Interactivity

After playing with static shapes we began to look at how to animate them which meant being introduced to a different section of code called ‘void draw() {}’

Unlike the void setup section where everything appears from the start and stays there, void draw continuously draws the shape over and over again.

If the (x,y,w,h) and (r,g,b) all stay the same it will just draw them in the same place, same size and same colour each frame and it won’t appear as if anything is happening at all.

However if you add the word random with your values in brackets e.g. random(x) we start to see some animation.

I added random functions into some of my coordinates of some lines and also into the stroke colours and this is what happened.

 

void setup () {
 
 size(800,600);
 background(200);
 
}
void draw() {
 
 strokeWeight(2);
 stroke(100,0,random(100)); 
 fill(0,100,random(500),50); // red, green, blue (255 each) , aplha 
 line(random(800),random(600),200,200); // rectangle x,y,w,h
 
 strokeWeight(2);
 stroke(100,0,random(100)); 
 fill(0,100,random(255),50); // red, green, blue (255 each) , aplha 
 line(random(600),random(800),600,600); // rectangle x,y,w,h
 
 
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s