Top level locals in a sketch need to be parsed in as instance variables to be visible to functions as well as blocks.
n = 100
particles = []
def dump s=300
fill false
matrix do
translate width/2-s/2, height/2-s/2
shape do
particles.each_pair { |p, q| curve_vertex p * s, q * s }
end
end
end
setup do
n.times { particles << rand }
end
draw do
dump 300
end
Should turn into
self.class.send :attr_accessor, :n, :particles
@n = 100
@particles = []
def dump s=300
fill false
matrix do
translate width/2-s/2, height/2-s/2
shape do
particles.each_pair { |p, q| curve_vertex p * s, q * s }
end
end
end
setup do
n.times { particles << rand }
end
draw do
dump 300
end
Top level locals in a sketch need to be parsed in as instance variables to be visible to functions as well as blocks.
Should turn into