Skip to content

Instantly share code, notes, and snippets.

@monkstone
Created April 20, 2010 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monkstone/372886 to your computer and use it in GitHub Desktop.
Save monkstone/372886 to your computer and use it in GitHub Desktop.
Ruby Processing Context Free DSL sketch with custom primitive
load_library 'context_free'
def setup_the_spiral
@spiral= ContextFree.define do
############ Begin defining custom terminal, an isoceles triangle
class << self
define_method(:isoceles) do |some_options| # isoceles triangle
size, options = *self.get_shape_values(some_options)
rot = options[:rotation]
@app.rotate(rot) if rot
@app.triangle(-0.5 * size, -0.5 * size, -0.5 * size, 0.5 * size, 0.5 * size, 0.5 * size)
@app.rotate(-rot) if rot
end
end
########### End definition of custom terminal 'isoceles'
rule :spiral do
isoceles :brightness => -1, :rotation => 90
spiral :rotation => 135, :size => 1/sqrt(2), :x => 1/sqrt(2)
end
end
end
def setup
size 600, 400
background 255
smooth
setup_the_spiral
draw_it
end
def draw_it
@spiral.render :spiral, :start_x => width/3, :start_y => height/2,
:size => height
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment