Thursday 5 May 2011

Deconstructing the code

 TypeClock by Julia Wang
Here is 'TypeClock' by Julia Wang which has a great example of an if/else statement:
The code I'm interested in:

if( h > 12) { //IF PM
background(5);
fill(50);
h = h - 12;
}
else { //if AM
background(255);
fill(240);
}
Basically, the code is saying if the hour is greater than 12pm (i.e. during the pm hours), then it sets the background to black, or else the time is during the 'am' so the background is set to white.



Starfield by Martin Holler

Here's a sample of the code:
if(mousePressed)
      z -= velocity * 10;
    else
  z -= velocity;
This bit of the code controls the functionality of the application -- when the mouse is pressed the velocity of the stars movement according to the z-axis is increased 10 times. Otherwise (else), the velocity returns to normal.


Rush Hour by Florence Labelle

int elapsed = millis() - savedTime;
if( elapsed < 10000) {
       background(intro);
      
      }
      else {
       niveau1();
        }
    if (posXrouge > 315){
       background(fin);

This code sets out what to display on the screen while playing Florence's rush hour game. So, if the time that has transpired is less than 10 seconds, the screen displays an introductory image, explaining how to play the game. After 10 seconds, you start on level 1 (niveau 1) of the game and if you are able to move the red car across the x-axis more than 315 pixels, you win, and the 'finish' image appears saying 'bravo!'.

No comments:

Post a Comment