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 › can redraw be used to translate something
Page Index Toggle Pages: 1
can redraw be used to translate something? (Read 569 times)
can redraw be used to translate something?
May 25th, 2007, 4:51am
 
I'm trying to use a loop in a function that calls redraw to translate a a letter, but it does not seem to update until the while loop completes. Basically, i just want the letter to rotate and then fall away from the screen.

Any ideas as to why it doesn't seem to be refreshing with the redraw?

Any help would be greatly appreciated. And sorry if this is a topic already. I was only able to get one discussion to show when i searched for 'redraw'.

void draw()
{
 background(0);
 translate(width/2,height/2);
 pushMatrix();
   ctime=millis()-start_time;
   
   theta=ctime*rotvel;
   
   //rotateX(textWidth(k)/70.0);
   //scale(1.1);
   
   
   translate(textWidth(buff)/2,0,-pos);
   rotateY(theta);
   translate(-textWidth(buff)/2,0);
   text(buff,0,0);
   
 
 popMatrix();
}

void myzoom()
{
 float postime=millis();
 
 while (pos<800)
 {
   pos=(millis()-postime)*.5;
   redraw();
 }
 buff=' ';
 pos=0;
}
Re: can redraw be used to translate something?
Reply #1 - May 25th, 2007, 10:43am
 
while() for() do() and other loops in all programming languages will halt the computer until the loop is completed. Entering any of these loops commits your program to complete the loop - you cannot change this.

The animation you are trying to achieve must be performed by turning the draw() function into your loop.

eg:

Code:

float theta = 0.0;
void setup(){
size(200,200,P3D);
}
void draw(){
background(100);
translate(width*0.5, height*0.5);
rotateX(theta);
rotateY(theta);
rect(0,0,width*0.5, height*0.5);
theta += 0.05;
}


This I am afraid is the way it is done.
Re: can redraw be used to translate something?
Reply #2 - Jun 18th, 2007, 6:21am
 
Does this mean that 'redraw' just sets a flag somewhere that allows 'draw()' to be called? (does not actually call draw)
Re: can redraw be used to translate something?
Reply #3 - Jun 18th, 2007, 2:14pm
 
that's correct (we're at the mercy of the operating system). i've added some clarification to the reference for future releases.
Page Index Toggle Pages: 1