cypseb
January 29, 2020, 5:24pm
1
Hello everybody
i am not a beguiner in programing, but i am a beguinner in processing
I try to move a text in a FOR loop but the drawing is not refresh, only at the end of the loop
i try to add redraw() in my loop but without sucess.
i know that i can use only the “draw” loopto do that but it may be usefull to do it in the loop
what to do?
thanks for your answers
here the code
void setup() {
size(640, 600);
background(51);
}
void draw()
{
fill(255, 212,0);
for (int a = 1 ; a<300; a = a+10 )
{
text("Hello World",a,a);
delay(10);
}
}
thanks and have a nice day
Sébastien
1 Like
Geo_Pi
January 29, 2020, 5:45pm
2
Hi,
Actually the draw() function is already a loop that renders an image. See https://processing.org/reference/draw_.html
What you can do is update your a variable once at the beginning of the draw function. For example
int a = 1;
int delta = 10;
void setup() {
size(640, 600);
background(51);
}
void draw()
{
//Background fills the canvas
background(51);
fill(255, 212, 0);
//allows to keep a inside the canvas
if (a > height) delta = -10;
else if (a < 0) delta = 10;
a += delta;
//print hello world
text("Hello World", a, a);
}
1 Like
cypseb
January 29, 2020, 5:52pm
3
Thanks for your anwser.
i know that i could do it the draw
does that mean that there are no other way to refresh the draw at another moment in the code?
even if it s not Processing philosophie, i would like to do it simply in a loop.
it a for ilustrate a for loop. i give a very simple coding initiation to some students tomorrow
thanks and best regards,
Sébastien
quark
January 29, 2020, 6:27pm
4
Try this as an example
int a = 0;
void setup() {
size(640, 600);
}
void draw() {
background(51);
fill(255, 212, 0);
a ++;
a %= 300;
text("Hello World", a, a);
}
1 Like
Geo_Pi
January 29, 2020, 6:34pm
5
Ok I understand. I don’t think that’s possible without using tricks that would loose the purpose of being simple.
Maybe this way? And removing the setup() & draw()
background(51);
size(640, 600);
for (int a = 0; a < 255; a+=10){
fill(a, a, a);
text("Hello world : " + a, a, a);
}
cypseb
January 29, 2020, 7:57pm
6
Thanks
it don t change anything without been outside draw {}. it s write everything and display at the end
but may be the solution is to indicate the index (a) in the text fonction so students will understand the loop even if it s not like i would like
thanks and have a nice evening (it s 21 here)
Sébastien
The draw() function loops once per frame.