Note that the rules here are essentially the same as the simple plant in my previous post, but here I've reduced the basic angle and added some numbers (repeat factors) to the 'rule'.
########################################################
# A simple seaweed implemented using a
# Lindenmayer System in ruby-processing by Martin Prout
########################################################
require 'wrack'
class Wrack_Test < Processing::App
attr_reader :wrack
def setup
size 600, 600
@wrack = Wrack.new
wrack.simulate 4
no_loop
end
def draw
background 0
translate 200, 550
wrack.render
save_frame "wrack_4.png"
end
end
############################
# wrack.rb
###########################
require 'jcode' ## required until jruby supports ruby 1.9
class Wrack
include Processing::Proxy
DELTA = (Math::PI/180) * 18
attr_accessor :axiom, :rule, :rule1, :start_length, :theta, :production, :draw_length, :xpos, :ypos
def initialize
@axiom = "F"
@rule = "3F[2-F]2F[+F][F]"
@start_length = 90
stroke 255
stroke_weight 4
reset
end
def reset # initialize or reset variables
@production = axiom
@draw_length = start_length
end
def iterate prod_, rule_
@draw_length *= 0.5
new_production = prod_
new_production.gsub!('F', rule_)
end
def render
repeats = 1
production.each_char do |element|
case element
when 'F' # NB using affine transforms
line(0, 0, 0, -draw_length * repeats)
translate(0, -draw_length * repeats)
repeats = 1
when '+'
rotate(+DELTA * repeats)
repeats = 1
when '-'
rotate(-DELTA * repeats)
repeats = 1
when '['
push_matrix
when ']'
pop_matrix
when '1', '2', '3', '4' # extend this to '9' if you need to
repeats = Integer(element)
else puts "Grammar not recognized"
end
end
end
def simulate gen
gen.times do
@production = iterate(production, rule)
end
end
end
four iterations
five iterations (might look better green?)
Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0
Sunday 29 November 2009
Subscribe to:
Post Comments (Atom)
Followers
Blog Archive
-
▼
2009
(50)
-
▼
November
(18)
- Koch curve using l-systems
- Towards a forest, or too many matrix calls
- Seaweed using Lindenmayer system on ruby processing
- A basic example of a plant Lindenmayer systems in...
- Pentagonal Fractal
- Minkowski island using L-System in ruby processing
- Sierpinski Fractal Implemented in ruby-processing ...
- Snake Kolam Ruby Processing
- Penrose Snowflake L-Systems using ruby-processing
- Dragon Fractal Using L-Systems and ruby-processing
- Koch Island Using Lindemayer System in Ruby Proces...
- Lindenmayer system in ruby-processing
- Tessellated "curvy" triangles in ruby-processing
- Dynamic rand with ruby-processing context-free DSL
- Flower in ruby-processing DSL
- Heighway Dragon in ruby-processing context free DSL
- Lévy curve implemented in ruby-processing context ...
- jEdit as a cross platform GUI?
-
▼
November
(18)
About Me
- monkstone
- I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2
No comments:
Post a Comment