numberscope / frontscope

Numberscope's front end and user interface: responsible for specifying sequences and defining and displaying visualizers
MIT License
7 stars 15 forks source link

Document subtle interaction between inhabit() and setup() in P5Visualizer #315

Closed gwhitney closed 1 month ago

gwhitney commented 5 months ago
          There's a subtlety in using `inhabit()` for this: if you set variables in `inhabit()` that are used in `setup()`, you have to do that before the call to `super.inhabit()`, which calls setup. Once I realized this, I decided to remove `inhabit()` from the template...

So in sum, what's wrong in the context of this tutorial of just picking some nice CSS color names like 'DarkBlue' and 'CornflowerBlue' or something like that and using those?

As you said, a tutorial sets the tone for how people make visualizers, and beauty is a core goal. I'd like to set the example of choosing colors with care. If the CSS stuff is too confusing, maybe we could use "magic numbers" with comments explaining that they're chosen to match the page style?

_Originally posted by @Vectornaut in https://github.com/numberscope/frontscope/pull/293#discussion_r1577251515_

gwhitney commented 5 months ago

The upshot here is that we need to document, hopefully in a technical reference page for P5Visualizer or at the very least in comments in P5Visualizer.ts that if you want to set variables in a derived-class inhabit() function that will be used in the derived-class setup() function (for example by extracting properties from the div to be inhabited), that must happen before the call to super.inhabit(), since it is super.inhabit() that (indirectly) calls this.setup(). That's perfectly legitimate, but it is a rare case in which you really do want to do stuff in the derived version of the method before the super call. Hence it should be explicitly documented.

gwhitney commented 1 month ago

I think this is now moot as people writing p5 visualizers with the framework as it now is in ui2 are not writing their own inhabit() function. Closing.