# jashkenas/ruby-processing

samples/peasy_cam/hilbert_fractal.rb example now allow the possibilit…

`…y of changing the fractal depth and to more correctly centre the fractal`
1 parent 485f8b9 commit cd78ccf0d024d636f1b889c8e97f83c50858f8c4 Guillaume Pierronnet committed Sep 30, 2011
Showing with 11 additions and 10 deletions.
1. +11 −10 samples/peasy_cam/library/hilbert/hilbert.rb
 @@ -39,26 +39,24 @@ def generate repeat = 0 ########################### class Hilbert include Processing::Proxy - + ADJUSTMENT = [0, 0.5, 1.5, 3.5, 7.5, 15] attr_reader :grammar, :axiom, :production, :premis, :rule, - :theta, :scale_factor, :distance, :phi, :len + :theta, :distance, :phi, :gen def initialize(len) @axiom = "X" @grammar = Grammar.new(axiom) @production = axiom @premis = "X" @rule = "^>XFX&F+>>XFX-F>X->" - @len = len - @distance = len/12 # distance value relative to screen height + @distance = len @theta = Math::PI/180 * 90 - @phi = Math::PI/180 * 90 + @phi = Math::PI/180 * 90 grammar.add_rule(premis, rule) - no_stroke() end - def render() - translate(-len/42, len/42, -len/42) # use the "answer?" to center the Hilbert + def render() + translate( -distance * ADJUSTMENT[gen], distance * ADJUSTMENT[gen], -distance * ADJUSTMENT[gen]) fill(0, 75, 152) light_specular(204, 204, 204) specular(255, 255, 255) @@ -93,7 +91,10 @@ def render() ############################## def create_grammar(gen) - @distance *= 0.5**gen + @gen = gen # required for depth adjustment + @distance *= 1/(pow(2, gen) - 1) @production = @grammar.generate gen end -end + + +end