float x;
float y;
float g;
float b;
void setup(){
size(600, 300);
x = width/2;
y = height;
g = random(255);
b = random(g);
background(0, 0, random(255));
noSmooth();
}
void draw(){
x += random(-1, 1);
y -= random(1);
if(x < 0){
x = width;
}
if(x > width){
x = 0;
}
if(y < 0){
y = height;
}
g += random(-10, 10);
g = constrain(g, 0, 255);
b += random(-10, 10);
b = constrain(b, 0, g);
stroke(0, g, b);
point(x, y);
}
This code starts out with a point in the bottom middle of the screen. It then moves the point up a little bit, and randomly a little bit to the left or right. It also randomly changes the color to a shade of green. It repeats that process every frame, and the effect looks like a vine growing up the screen. If you leave it running long enough, you get something like this:
See the Pen by Happy Coding (@KevinWorkman) on CodePen.
Animate a vine that crawls up the screen.
Happy Coding is a community of folks just like you learning about coding.
Do you have a comment or question? Post it here!
Comments are powered by the Happy Coding forum. This page has a corresponding forum post, and replies to that post show up as comments here. Click the button above to go to the forum to post a comment!