nasser / zajal

Experimental creative coding framework
MIT License
161 stars 10 forks source link

Top level locals #66

Open nasser opened 12 years ago

nasser commented 12 years ago

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
nasser commented 12 years ago

This can certainly be done using Rubinius's compiler tools, but can it be done in a cross-Ruby way?

nasser commented 12 years ago

Postponed due to hurricane.

This syntax may be axed. How important is it to emulate Processing so literally?