plasma_effect.sf 635 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/ruby
  2. #
  3. ## https://rosettacode.org/wiki/Plasma_effect
  4. #
  5. require('Imager')
  6. class Plasma(width=400, height=400) {
  7. has img = nil
  8. method init {
  9. img = %O|Imager|.new(xsize => width, ysize => height)
  10. }
  11. method generate {
  12. for y,x in (^height ~X ^width) {
  13. var hue = (4 + sin(x/19) + sin(y/9) + sin((x+y)/25) + sin(hypot(x, y)/8))
  14. img.setpixel(x => x, y => y, color => Hash(hsv => [360 * hue / 8, 1, 1]))
  15. }
  16. }
  17. method save_as(filename) {
  18. img.write(file => filename)
  19. }
  20. }
  21. var plasma = Plasma(256, 256)
  22. plasma.generate
  23. plasma.save_as('plasma.png')