processing - object instances created on xformed and rotated grids -
in fiddle below, i've drawn circles @ points along recursive tree structure.
https://jsfiddle.net/ypbprzzv/4/
the tree structure simplified version of 1 found here:
https://processing.org/examples/tree.html
what if instead of drawing circles @ (0, -h) on transformed , rotated grids, they're being drawn in fiddle, wanted hang pendulums hang in unrotated y direction (down). if pendulums instances of object class, easy add new instance instead of (or in addition to) drawing circle.
void branch(float h) { h *= 0.6; if (h > 10) { pushmatrix(); rotate(a); line(0, 0, 0, -h); fill(0, 175, 0, 100); if (h < 50) { // add new pendulum here, @ (0, -h) ellipse(0, -h, 5, 5); } translate(0, -h); branch(h); popmatrix(); } // closing if statement } // closing branch function
i have tried because wanted keep code brief, have not included it. pendulums indeed hang, in wacky directions, since when create these instances, whole grid xformed , rotated (which needs case simplify drawing tree or other interesting structures).
and suppose want make these pendulums sensitive user interactions. objects' frames of reference different users'.
so i'll try summarize question:
is possible create instances of objects on transformed , rotated grid, have object behave in prescribed way in relation unrotated grid?
would helpful provide fiddle including pendulums?
it's little bit hard general "how do this" or "is possible" questions this. reason it's hard answer "is possible" questions answer yes, it's possible. similarly, "how do this" questions have million possible answers, , there isn't single best way approach problem. "right" answer more dependent on how think problem else. i'll try in general sense.
is possible create instances of objects on transformed , rotated grid, have object behave in prescribed way in relation unrotated grid?
yes, it's possible.
there number of ways might approach this:
- you might keep track of current state (current rotation) , undo when draw pendulum. example, if you're rotated 90 degrees, you'd rotate -90 degrees before drawing pendulum.
- you maybe use
screenx()
,screeny()
functions screen location of transformed point. more info can found in the reference. - you store positions recursively draw tree, , after tree drawn, loop on points draw pendulums.
these think of right now, , there more ways approach it. again, approach choose depends on how stuff fits brain, pretty hard with.
but if want 2 cents: find hard "think in transformations" stuff you're describing. instead, if you, refactor code no longer relies on translations , rotations. i'd use basic trig (the sin()
, cos()
functions) draw everything. you'd in screen coordinates, drawing pendulums easier.
but again, approach take depends on how think things.
Comments
Post a Comment