We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › wondeirng how to reset frames of reference...
Page Index Toggle Pages: 1
wondeirng how to reset frames of reference... (Read 1352 times)
wondeirng how to reset frames of reference...
Oct 13th, 2005, 6:00am
 
i'm a complete newb to processing; i'm helping a friend in a graphic design class since she has no programming expereince whatsoever.  

anyway, my question:  i can create shapes (rectangles, squares, elipses, etc etc) but whenever i use any of the rotate() functions, it rotates _everything_.  how can i rotate one shape or object at a time? how can i scale one shape or object at a time? or translate one at a time?  i know i must be missing something really simple here, but so far no dice.  thanks in advance!

-quad
Re: wondeirng how to reset frames of reference...
Reply #1 - Oct 13th, 2005, 7:33am
 
Hi quad, welcome to P5.

You might have a look at two things:
 (1). setup() and draw()http://processing.org/reference/setup_.html
 (2). pushMatrix() and popMatrix() http://processing.org/reference/popMatrix_.html

With push/popMatrix() will be able to control one Object at the time.

Code:

//Initialize the Window
void setup(){
size(300,150);
}

//The main Loop
void draw(){
background(155);

//First: draw on rectangle
rect(20,40,50,60);

//Next: Using push/pop
pushMatrix(); //Open the Transformation
translate(150,75);
rotate(frameCount/100f);
rect(-25,-30,50,60);
popMatrix(); //Close the Transformation

//Try inverted sequence
/*
pushMatrix();
rotate(frameCount/100f);
translate(150,75);
rect(-25,-30,50,60);
popMatrix();
*/
}
Re: wondeirng how to reset frames of reference...
Reply #2 - Oct 17th, 2005, 5:13am
 
in the line
<quote>rotate(frameCount/100f);</quote>

what does the "f" do? it clearly changes the behaviour of the rotation (it's much less jerky when using the f)

does this force a float mode?

if so, is there a similar way to force an int mode?

thanks!

-quad
Re: wondeirng how to reset frames of reference...
Reply #3 - Oct 17th, 2005, 5:37pm
 
f forces float mode, yes.. it's the same as saying:

rotate(frameCount/100.0);

it merely means that the division will become a float division instead of integer, making things smoother as you found.

the only equivalent is to just not have the decimals, or "cast" the number to an int. for instance, if frameCount were a float and needed to be an integer:

rotate(int(frameCount)/100);

though there are bugs in the preprocessor, so you might have better luck with:

rotate(((int)frameCount) / 100);
Page Index Toggle Pages: 1