Guest User

Untitled

a guest
Apr 26th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. require 'ruby-processing'
  2.  
  3. class Sun < Processing::App
  4. #load_java_library :opengl
  5. #include_package 'processing.opengl'
  6.  
  7.  
  8. def setup
  9. #render_mode OPENGL
  10. smooth
  11. no_loop
  12.  
  13. color_mode HSB, 360
  14.  
  15. @radius = width / 8
  16. @ray_count = 20
  17.  
  18. @ray_radiuses = []
  19. @ray_colors = []
  20.  
  21. @ray_count.times { |i| @ray_radiuses << ((i % 2 == 0) ? random(1.5 * @radius, 2.0 * @radius) : 2.8 * @radius) }
  22.  
  23. @ray_count.times { |i| @ray_colors << color(60, 360, 360 + random(60)) }
  24. @t = 0
  25. end
  26.  
  27. def draw
  28. background 360
  29. translate width / 2, height / 2
  30. @t += 0.1
  31.  
  32. stroke_weight 2
  33. fill 60, 360, 360
  34.  
  35. ellipse 0, 0, 2 * @radius, 2 * @radius
  36.  
  37. @angle_step = 2 * PI / @ray_count
  38. rotate @t
  39.  
  40. #stroke_weight 1
  41.  
  42. stroke_join ROUND
  43.  
  44. @ray_count.times do |ray|
  45. begin_shape
  46.  
  47. step_y = @ray_radiuses[ray].to_f / 40
  48. fill @ray_colors[ray]
  49. 40.times do |i|
  50. y = i * step_y
  51. curve_vertex(@radius * Math.sin(y / 20 + @t % (2.3 * @radius)) / 4 - 5, y + @radius + 5)
  52. end
  53.  
  54. 40.downto(0) do |i|
  55. y = i * step_y
  56. curve_vertex(@radius * Math.sin(y / 20 + @t % (2.3 * @radius)) / 4 + 5, y + @radius + 5)
  57. end
  58. end_shape(CLOSE)
  59. rotate @angle_step
  60.  
  61. #save('sun.png')
  62. end
  63. turtle = load_image('tortue3.png')
  64. image(turtle, 0, 0)
  65.  
  66. end
  67.  
  68. def mouse_clicked
  69. save('sun.png')
  70. end
  71. end
  72.  
  73. Sun.new :title => "Sun", :width => 500, :height => 500
Add Comment
Please, Sign In to add comment