Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'ruby-processing'
- class Sun < Processing::App
- #load_java_library :opengl
- #include_package 'processing.opengl'
- def setup
- #render_mode OPENGL
- smooth
- no_loop
- color_mode HSB, 360
- @radius = width / 8
- @ray_count = 20
- @ray_radiuses = []
- @ray_colors = []
- @ray_count.times { |i| @ray_radiuses << ((i % 2 == 0) ? random(1.5 * @radius, 2.0 * @radius) : 2.8 * @radius) }
- @ray_count.times { |i| @ray_colors << color(60, 360, 360 + random(60)) }
- @t = 0
- end
- def draw
- background 360
- translate width / 2, height / 2
- @t += 0.1
- stroke_weight 2
- fill 60, 360, 360
- ellipse 0, 0, 2 * @radius, 2 * @radius
- @angle_step = 2 * PI / @ray_count
- rotate @t
- #stroke_weight 1
- stroke_join ROUND
- @ray_count.times do |ray|
- begin_shape
- step_y = @ray_radiuses[ray].to_f / 40
- fill @ray_colors[ray]
- 40.times do |i|
- y = i * step_y
- curve_vertex(@radius * Math.sin(y / 20 + @t % (2.3 * @radius)) / 4 - 5, y + @radius + 5)
- end
- 40.downto(0) do |i|
- y = i * step_y
- curve_vertex(@radius * Math.sin(y / 20 + @t % (2.3 * @radius)) / 4 + 5, y + @radius + 5)
- end
- end_shape(CLOSE)
- rotate @angle_step
- #save('sun.png')
- end
- turtle = load_image('tortue3.png')
- image(turtle, 0, 0)
- end
- def mouse_clicked
- save('sun.png')
- end
- end
- Sun.new :title => "Sun", :width => 500, :height => 500
Add Comment
Please, Sign In to add comment