Skip to content

Commit

Permalink
merging in monkstone's triangle patch and additional samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Aug 21, 2009
1 parent b03228a commit 3045a86
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 181 deletions.
1 change: 1 addition & 0 deletions context_free.rb
Expand Up @@ -166,6 +166,7 @@ def render(rule_name, starting_values={})
@values = {:x => 0, :y => 0,
:rotation => 0, :flip => false,
:size => 20, :width => 20, :height => 20,
:start_x => width/2, :start_y => height/2,
:color => [0.5, 0.5, 0.5],
:stop_size => 1.5}
@values.merge!(starting_values)
Expand Down
6 changes: 0 additions & 6 deletions samples/city.rb
@@ -1,7 +1,6 @@
load_library 'context_free'

def setup_the_city

@city = ContextFree.define do

rule :neighborhood do
Expand Down Expand Up @@ -33,10 +32,8 @@ def setup_the_city
end

end

end


def setup
size 600, 600
smooth
Expand All @@ -45,20 +42,17 @@ def setup
draw_it
end


def draw
# Do nothing
end


def draw_it
background @background
@city.render :neighborhood,
:start_x => width/2, :start_y => height/2,
:size => height/2.5, :color => [0.1, 0.1, 0.1]
end


def mouse_clicked
draw_it
end
84 changes: 43 additions & 41 deletions samples/creature.rb
@@ -1,57 +1,59 @@
# creature.rb ruby-processing
# contributed by monkstone

load_library 'context_free'

def setup_the_creature
@creature = ContextFree.define do
rule :start do
rot = 0
split do
11.times do # 11 times increment rotation by 30 degrees
legs :rotation => rot
rot += 30
rewind # rewind context
end
legs :rotation => 360
end
end
rule :legs do
circle :hue => 0.15, :saturation => 0.5, :brightness => 1.0, :color => [0.95, 0.15]
legs :y => 0.1, :size => 0.965
end
rule :legs, 0.01 do
circle
split do
legs :rotation => 3
rewind
legs :rotation => -3
end
end
@creature = ContextFree.define do

rule :start do
rot = 0
split do
11.times do # 11 times increment rotation by 30 degrees
legs :rotation => rot
rot += 30
rewind # rewind context
end
legs :rotation => 360
end
end

rule :legs do
circle :hue => 0.15, :saturation => 0.5, :brightness => 1.0, :color => [0.95, 0.15]
legs :y => 0.1, :size => 0.965
end

rule :legs, 0.01 do
circle
split do
legs :rotation => 3
rewind
legs :rotation => -3
end
end

end
end

def setup
size 600, 600
setup_the_creature
no_stroke
color_mode HSB, 1.0
smooth
draw_it
save_frame("creature.png")
size 600, 600
setup_the_creature
no_stroke
color_mode HSB, 1.0
smooth
draw_it
# save_frame("creature.png")
end


def draw
# Do nothing.
# Do nothing.
end


def draw_it
background -1.0
@creature.render :start, :size => height/5, :stop_size => 0.8,
:start_x => width/2, :start_y => height/3, :color => [0.75, 0.1, 0.9]
background -1.0
@creature.render :start, :size => height/5, :stop_size => 0.8,
:start_x => width/2, :start_y => height/3, :color => [0.75, 0.1, 0.9]
end


def mouse_clicked
draw_it
draw_it
end
69 changes: 35 additions & 34 deletions samples/dark_star.rb
@@ -1,50 +1,51 @@
# dark_star.rb ruby-processing
# contributed by monkstone

load_library 'context_free'

def setup_the_sun
@sun = ContextFree.define do
rule :start do
rot = 0
split do
12.times do
legs :rotation => rot
rot += 30
rewind
end
legs :rotation => 360
end
end
rule :legs do
circle
legs :rotation => 1, :y => 0.1,
:size => 0.965, :color => [0.22, 0.15], :alpha => 0.5
end
@sun = ContextFree.define do

rule :start do
rot = 0
split do
12.times do
legs :rotation => rot
rot += 30
rewind
end
legs :rotation => 360
end
end

rule :legs do
circle
legs :rotation => 1, :y => 0.1,
:size => 0.973, :color => [0.22, 0.15], :alpha => 0.5
end

end
end

def setup
size 600, 600
setup_the_sun
no_stroke
color_mode HSB, 1.0
smooth
draw_it
save_frame("sun.png")
size 600, 600
setup_the_sun
no_stroke
color_mode HSB, 1.0
smooth
draw_it
# save_frame("sun.png")
end


def draw
# Do nothing.
# Do nothing.
end


def draw_it
background 1.0
@sun.render :start, :size => height/7, :stop_size => 0.8,
:start_x => width/2, :start_y => height/2
background 0.7
@sun.render :start, :size => height/7, :stop_size => 0.8,
:start_x => width/2, :start_y => height/2
end


def mouse_clicked
draw_it
draw_it
end
6 changes: 1 addition & 5 deletions samples/fern.rb
Expand Up @@ -22,7 +22,6 @@ def setup_the_fern
end
end


def setup
size 600, 600
setup_the_fern
Expand All @@ -32,19 +31,16 @@ def setup
draw_it
end


def draw
# Do nothing.
end


def draw_it
background 0.33, 0.25, 0.2
@fern.render :start, :size => height/23, :color => [0.35, 0.4, 0.9, 0.55], :stop_size => 1,
:start_x => width/2.5, :start_y => height/1.285
end


def mouse_clicked
draw_it
end
end
41 changes: 0 additions & 41 deletions samples/test_tri.rb

This file was deleted.

50 changes: 0 additions & 50 deletions samples/tri.rb

This file was deleted.

4 changes: 0 additions & 4 deletions samples/vine.rb
Expand Up @@ -31,7 +31,6 @@ def setup_the_vine
end
end


def setup
size 700, 700
setup_the_vine
Expand All @@ -41,19 +40,16 @@ def setup
draw_it
end


def draw
# Do nothing.
end


def draw_it
background 0.75, 1.0, 0.15
@vine.render :root, :size => height/75, :color => [0.75, 0.1, 0.9],
:start_x => width/2, :start_y => height/2
end


def mouse_clicked
draw_it
end
1 change: 1 addition & 0 deletions tests/library/context_free/context_free.rb

0 comments on commit 3045a86

Please sign in to comment.