|
Author |
Topic: Q about program structure (Read 2555 times) |
|
mawend
|
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
|
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
|
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
|
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
|
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
|
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: and try to run it. the environment would translate that into: Code:void draw() { rect(20, 20, 40, 70); } |
|
|
|
|
|
Martin
|
Re: Q about program structure
« Reply #6 on: Feb 10th, 2003, 3:37pm » |
|
yeap. draw() seems to override loop(). hmmm...
|
|
|
|
fry
|
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!
|
|
|
|
|