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

instance mode #4

Closed
pietroppeter opened this issue Nov 21, 2022 · 1 comment
Closed

instance mode #4

pietroppeter opened this issue Nov 21, 2022 · 1 comment

Comments

@pietroppeter
Copy link
Owner

pietroppeter commented Nov 21, 2022

with nim macros it could be actually much more painless than in p5js to support instance mode: https://github.com/processing/p5.js/wiki/Global-and-instance-mode

instead of:

const s = ( sketch ) => {

  let x = 100;
  let y = 100;

  sketch.setup = () => {
    sketch.createCanvas(200, 200);
  };

  sketch.draw = () => {
    sketch.background(0);
    sketch.fill(255);
    sketch.rect(x,y,50,50);
  };
};

let myp5 = new p5(s, 'p5sketch1');

we could have:

newP5Instance("p5sketch1"):
  let
    x = 100
    y = 100

  setup:
    createCanvas(200, 200)

  draw:
    background(0)
    fill(255)
    rect(x, y, 50, 50)

and the difference between global and instance mode would just be a macro away (instead of having to add manually sketch.).

and we could actually have in nimib a nbP5Instance which automatically provides a new id and an html container for the sketch in order to have multiple sketches on the same page.

note that I would not know at the moment where to start to build that macro and in particular on how to generate all the closure js syntax (my fallback would be: use emit...).

@pietroppeter
Copy link
Owner Author

implemented in #5

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

No branches or pull requests

1 participant