Created
July 23, 2013 14:54
-
-
Save monkstone/6062971 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Rain1 by Thomas R. "TomK32" Koll | |
# | |
# draws raindrops as bezier shapes and moves them downwards | |
# | |
# available key commands: | |
# + make raindrops heavier/bigger | |
# - make raindrops smaller | |
# a more raindrops | |
# s less raindrops | |
# <SPACE> | |
# | |
# License: Same as processing | |
# | |
def setup | |
size 640, 480 | |
frame_rate 30 | |
@rain_drops = [] | |
@rain_drops.extend Runnable | |
@rain_drops_size = 20 | |
@rain_drops_weight = 20 | |
@paused = false | |
text_font(create_font("Univers66.vlw", 15), 15) | |
end | |
def draw | |
return if @paused | |
# we fill up with new drops randomly | |
fill_up while rand(@rain_drops_size/3) < (@rain_drops_size - @rain_drops.size) | |
drop_rate = @rain_drops.size/@rain_drops_size.to_f | |
# the less drops the darker it is | |
background (127+127*(@rain_drops.size/@rain_drops_size.to_f)) | |
@rain_drops.run | |
text("#{@rain_drops.size} of #{@rain_drops_size} drops with a size of #{@rain_drops_weight}", 10, 20) | |
end | |
def fill_up | |
@rain_drops << RainDrop.new(rand(width), rand(-height/2 .. 0), @rain_drops_weight) if @rain_drops.size < @rain_drops_size | |
end | |
def key_pressed | |
case key | |
when "+" | |
@rain_drops_weight += 5 | |
when "-" | |
@rain_drops_weight -= 5 if @rain_drops_weight > 10 | |
when "a" | |
@rain_drops_size += 5 | |
when "s" | |
@rain_drops_size -= 5 if @rain_drops_size > 5 | |
when " " | |
@paused = !@paused | |
end | |
end | |
module Runnable | |
def run | |
self.reject! { |item| item.dead? } | |
self.each { |item| item.run } | |
end | |
end | |
class RainDrop | |
include Processing::Proxy | |
def initialize(x, y, weight = nil) | |
@weight = weight || 10 | |
@original_height = y | |
@x, @y = x, y | |
render(x,y,weight) | |
end | |
def render(x,y,weight) | |
fill(100, 100, 200) | |
no_stroke | |
bezier(x, y, x-(weight/2), y+weight, x+(weight/2), y+weight, x, y) | |
end | |
def dead? | |
@y > $app.height | |
end | |
def run | |
@y = @y + @weight | |
@x = @x - rand(6) | |
render(@x,@y,@weight) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@TomK32
Hi ruby processing has move on since you posted your rain sketch to our gallery see latest developments at
https://github.com/monkstone/ruby-processing
I have updated your sketch in line with the latest version (bare sketches are preferred) we are now at ruby-1.9.3.