Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top level locals #66

Open
nasser opened this issue Oct 20, 2012 · 2 comments
Open

Top level locals #66

nasser opened this issue Oct 20, 2012 · 2 comments

Comments

@nasser
Copy link
Owner

nasser commented Oct 20, 2012

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
Copy link
Owner Author

nasser commented Nov 2, 2012

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

@nasser
Copy link
Owner Author

nasser commented Nov 7, 2012

Postponed due to hurricane.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant