1 class Particle
2 def initialize(w, h)
3 @width, @height = w, h
4 @x, @y, @xvel, @yvel = rand(@width), rand(@height), rand(1)*5-2.5, rand(1)*5-2.5
5 @r, @g, @b = rand(255), rand(255), rand(255)
6 @a =0
7 end
8
9 def update
10 return if @a > 2 * 3.14
11 px, py = @x, @y
12 @x += @xvel
13 @y += @yvel
14 @yvel += 0.1
15 @xvel *= -1 if (@x < 0 || @x > @width)
16 @yvel *= -1 if (@y < 0 || @y > @height)
17 $app.stroke rgb(@r, @g, @b, Math.sin(@a += 0.01)*255)
18 $app.line px, py, @x, @y
19 end
20 end
21
22 Shoes.app :width => 400, :height => 400 do
23 $app = self
24 background black
25 @particles = Array.new(1) { Particle.new(400, 400) }
26
27 animate 60 do
28 @particles.each { |p| p.update }
29 end
30 end
No comments:
Post a Comment