Created
February 5, 2009 06:25
-
-
Save masaakif/58571 to your computer and use it in GitHub Desktop.
action-coding、サンプル2:絵柄が流れる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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