Created
April 20, 2010 18:52
-
-
Save monkstone/372886 to your computer and use it in GitHub Desktop.
Ruby Processing Context Free DSL sketch with custom primitive
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
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