Skip to content

Instantly share code, notes, and snippets.

@masaakif
Created February 5, 2009 06:25
Show Gist options
  • Save masaakif/58571 to your computer and use it in GitHub Desktop.
Save masaakif/58571 to your computer and use it in GitHub Desktop.
action-coding、サンプル2:絵柄が流れる。
#
# test2.rb
# my 2nd sample of Processing + action-coding
# Pops up circle + rect on the window randomly position, color.
# Then it flows down to bottom.
#
$ss = []
def setup
size 200, 200
frameRate 10
end
def draw
background 128
cl = color random(0,255),random(0,255),random(0,255),random(0,255)
if random(0,2) < 1 then
$ss.push Rect.new random(0,width), random(0,height), random(10,25), random(10,25), cl
else
$ss.push Circle.new random(0,width), random(0,height), random(10,25), random(10,25), cl
end
$ss.each {|s|
s.update self
s.draw self
}
end
class MyShape
def initialize(x, y, w, h, c)
@x = x; @y = y
@w = w; @h = h
@c = c
end
def update (p)
@y = @y + @h / 5
end
end
class Rect < MyShape
def draw (p)
p.fill @c
p.rect @x, @y, @w, @h
end
end
class Circle < MyShape
def draw (p)
p.fill @c
p.ellipse @x, @y, @w, @h
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment