213
edits
Line 204: | Line 204: | ||
</source> | </source> | ||
<br /><br /> | |||
=== III Functions === | === III Functions === | ||
Line 243: | Line 244: | ||
</source> | </source> | ||
<br /><br /> | |||
=== IV Movement & conditions === | |||
<source lang="java"> | |||
/* MOVEMENT & CONDITIONS | |||
* | |||
* By changing a variable during the runtime, | |||
* we can alter the condition of the program. | |||
* Here we increment an integer variable | |||
* each time draw() is called. This variable is | |||
* used for the x-position of a line, thus | |||
* creating the illusion of a continuous movement | |||
* from left to right. | |||
* Via the "if" and "else" branches we can react | |||
* to different states of the program and alter it | |||
* accordingly. | |||
* | |||
* Frederic Gmeiner 2011 | |||
*/ | |||
// variable to store the x-position of the line: | |||
int lineX = 0; | |||
void setup(){ | |||
size(500,300); | |||
} | |||
void draw(){ | |||
// clear the background | |||
background(255); | |||
// if the x position of the line is larger than the middle of the screen: | |||
if(lineX > width/2){ | |||
// change the stroke colour to pure red: | |||
stroke(255,0,0); | |||
// if the x position of the line is smaller than the middle of the screen: | |||
}else{ | |||
// set the stroke coulour to black: | |||
stroke(0,0,0); | |||
} | |||
// draw a vertical line from the top (0) to the bottom ("height") at | |||
// the current x-position: | |||
line(lineX,0,lineX,height); | |||
// increment the lineX variable by 1 | |||
// (you could also simply write "lineX++") | |||
lineX = lineX+1; | |||
// use the "println()" function to show the value of variables | |||
// in the console. this is helpful for debugging. | |||
println(lineX); | |||
} | |||
</source> | |||
<br /><br /> | |||
[[Category:WS11]] | [[Category:WS11]] |
edits