|
Author |
Topic: Translate in setup() vs. loop() (Read 241 times) |
|
battey
|
Translate in setup() vs. loop()
« on: Oct 22nd, 2003, 10:26pm » |
|
Processing v.65 Translate is sweet when you wish to plot functions on a cartesian graph with origin at the center of the drawing area. But it not clear to me why the following code (Example 1) doesn't work -- where translate is placed in the setup() function. The 2nd example works, with translate appearing in the loop function. Though there it is not clear to me why the translates don't start accumulating. i.e., I would have thought that I'd need to push/pop states each time through the loop to keep the coordinate system in the center... Example 1 <code> void setup() { size(200,200); framerate(30); // I want to put this here, but it doesn't take // effect if I do: translate(width/2,height/2); } int scale=1; void loop() { background(255); { for(int x=-width/2;x<width/2;x++) { point(x,pow(x,3)/(scale+); } scale=(scale+1)%5; } } </code> Example 2 (works, but only because the translations don't accumulate!?) <code> void setup() { size(200,200); framerate(30); } int scale=1; void loop() { translate(width/2,height/2); background(255); { for(int x=-width/2;x<width/2;x++) { point(x,pow(x,3)/(scale+); } scale=(scale+1)%5; } } </code>
|
|
|
|
fry
|
Re: Translate in setup() vs. loop()
« Reply #1 on: Oct 22nd, 2003, 10:33pm » |
|
the camera is cleared out just before loop (or draw) is run, on each iteration. so the translate won't be saved. we should probably document this somewhere if it isn't already.
|
|
|
|
battey
|
Re: Translate in setup() vs. loop()
« Reply #2 on: Oct 23rd, 2003, 1:07am » |
|
Ah, I looked for it in the basic "loop" or "translate" materials and didn't find it, though in retrospect the answer is implicit in other posted materials. ---- NOTE: Just in case someone else looks at my code example above, to truly create a cartesian coordinate system, one also has to: rotateX(PI); in addition to translating the origin to the desired location.
|
|
|
|
|