|
Author |
Topic: problems with delay() (Read 235 times) |
|
der_rabe
|
problems with delay()
« on: Dec 14th, 2003, 11:23pm » |
|
i am new to processing. i heard about it on a design-convention in germany. now i am trying to do some little sketches. and i got problems with the delay() function. it does not work in the following code. what i wanna achieve is a rectangle which changes color over time. but all i get is the final state at once. void setup(){ background(255); size(200,200); } void loop(){ noStroke(); for (int i = 0 ; i <= 255 ; i++){ fill(i,0,0); rect(50,50,100,100); delay(5000); } }
|
Bernd Salewski student of digital media Hochschule Bremen
|
|
|
benelek
|
Re: problems with delay()
« Reply #1 on: Dec 14th, 2003, 11:39pm » |
|
hi der_rabe, welcome to the Processing forum. this might be what you were trying for: Code: void setup(){ size(200,200); background(255); } int i=0; void loop(){ noStroke(); fill(i,0,0); rect(50,50,100,100); if(i<255) { i++; } else i=0; } |
|
|
|
|
|
der_rabe
|
Re: problems with delay()
« Reply #2 on: Dec 15th, 2003, 12:10am » |
|
hmm, seems that i forgot that the code in the loop()block is executed infinitely. but i wonder why the sketch does not work, if i simply put delay(500) at the end to slow the colorchange down. it shows me a black rectangle, without any change: void setup(){ size(200,200); background(255); } int i = 0; void loop(){ noStroke(); fill(i,0,0); rect(50,50,100,100); if(i < 255){ i++; }else i=0; delay(100); }
|
Bernd Salewski student of digital media Hochschule Bremen
|
|
|
der_rabe
|
no more problems
« Reply #3 on: Dec 15th, 2003, 12:15am » |
|
no, sorry its alright now. my fault. everything works fine now
|
Bernd Salewski student of digital media Hochschule Bremen
|
|
|
REAS
|
Re: problems with delay()
« Reply #4 on: Dec 17th, 2003, 12:15am » |
|
Nothing is drawn to the screen until the end of the loop() is reached. It is drawing all of your different colored rectangles in the offscreen buffer, but is only then drawing the final black one to the screen.
|
|
|
|
|