FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Q about program structure
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Q about program structure  (Read 2555 times)
mawend

Email
Q about program structure
« on: Feb 8th, 2003, 8:34am »

Although I can get P5 to do what I want it to do, I still can't get my head around why it behaves in certains ways.
 
Specifically, why don't objects drawn in the setup block display, when the loop block is either nonexistent or empty?
 
For example:
 
void setup()
{
  size (200, 200);
  background (0);
  stroke (255);
  ellipse(width/2, height/2, 100, 100);
}
 
void loop()
{
}
 
 
This doesn't draw anything (or draws and erases the ellipse really fast). Why doesn't the ellipse stay drawn? It seems like all drawing activity has to be *repeated* in the loop block, and redrawn every time, to have persistence. Why can't I draw something once (say, in setup), and then draw other things over it in the loop block? I guess there's no sense of a screen "buffer" here, so I'm always responsible for explicitly drawing everything I want on screen *each* time the loop block repeats? Seems like the loop block is actually CLEARING the window each time it starts over.
 
Just trying to figure out the underlying logic. Any help is appreciated.
 
thanks
Mark
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: Q about program structure
« Reply #1 on: Feb 9th, 2003, 1:22pm »

void setup()  
{  
  size (200, 200);  
  background (0);  
}  
 
void draw()
{
  stroke (255);  
  ellipse(width/2, height/2, 100, 100);  
}
   
void loop()  
{  
}  
 
fry


WWW
Re: Q about program structure
« Reply #2 on: Feb 9th, 2003, 4:52pm »

setup() wasn't intended as a place to do one-time drawing, you have to just do it inside loop().  
 
however, your question is not an uncommon one, which makes me think that we'll need to have a way to draw inside setup, because it does seem a bit counterintuitive that it doesn't work.
 
mawend

Email
Re: Q about program structure
« Reply #3 on: Feb 10th, 2003, 5:35am »

on Feb 9th, 2003, 1:22pm, Martin wrote:

void draw()
{
  stroke (255);  
  ellipse(width/2, height/2, 100, 100);  
}
  
void loop()  
{  
}  

 
Hi Martin -  
 
Where did the "draw" section come from Is that a P5 specific thing, or a java thing I also notice in your example that the loop() block doesn't actually seem to execute at all (e.g., if you stick some command in there), as if it is running the draw() block and stopping. Is that what you'd expect
 
thanks
Mark
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: Q about program structure
« Reply #4 on: Feb 10th, 2003, 6:39am »

hi mark,
 
draw() is an undocumented (as of yet) method in proce55ing. java uses the paint() method.
 
using a public terminal right now... will try the stuff inside loop() thing later. thanks for the note.
 
cheers,
martin
 
fry


WWW
Re: Q about program structure
« Reply #5 on: Feb 10th, 2003, 2:55pm »

put things in draw() for an application that draws once and then quits. use loop() for an application that continues to run the contents of loop().  
 
the two have to be used separately (for now), although combining draw() and loop() might be the way that we solve the "draw one time" dilemma.
 
the draw() method is where your code gets stuffed if you were to write a bare-bones program like:
 
Code:
rect(20, 20, 40, 70);

 
and try to run it. the environment would translate that into:
 
Code:
void draw() {
  rect(20, 20, 40, 70);
}
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: Q about program structure
« Reply #6 on: Feb 10th, 2003, 3:37pm »

yeap. draw() seems to override loop(). hmmm...
 
martin_publicterminal
Guest
Email
Re: Q about program structure
« Reply #7 on: Feb 14th, 2003, 3:59am »

hello. might want to refer to http://proce55ing.net/discourse/yabb/board_Tools_action_display__num_1045182290.html . posted it a couple of days ago.
 
fry


WWW
Re: Q about program structure
« Reply #8 on: Sep 20th, 2003, 2:16am »

as of rev 0060, it will be possible to draw inside setup. weee!
 
Pages: 1 

« Previous topic | Next topic »