Created
September 23, 2015 14:18
-
-
Save slambert/94523caa95e982852323 to your computer and use it in GitHub Desktop.
Example from Programming for Visual Artists class 2015-09-22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Centipede | |
// Steve Lambert | |
// September 23, 2015 | |
// v0.1 | |
int xPos = 15; // global variable | |
float greg = 15; // initialized at 15, so it shows up where I want it the first time | |
void setup() { | |
size(500,500); | |
smooth(); | |
noStroke(); | |
// frameRate(1); // can uncomment to slow things down for testing. | |
} // end setup | |
void draw() { | |
background(255,0,0); | |
fill(255); | |
// CHECK OUT MY WHILE LOOP! | |
// IT DRAWS A ROW OF CIRCLES!!!! | |
while (greg < width){ // Because I don't want to draw circles beyond the canvas | |
fill(255); | |
ellipse(greg,15,30,30); | |
greg = greg + 30; | |
} // end of loop | |
if (greg > width ){ | |
greg = 15; | |
} // end of if statement | |
// CHECK OUT MY FOR LOOP! | |
// IT DRAWS ANOTHER ROW OF CIRCLES!!!! | |
for (int i = 0; i < 12; i++) { // I want to make 12 | |
println ("i: " + i); // this shows me where we're at in the count | |
ellipse(xPos,45,30,30); // this draws the circle | |
xPos = xPos + 30; // this moves makes the next cycle of the loop draw the circle to the right | |
println("xPos: " + xPos); // this tells me where it will be | |
} // end of for loop | |
// if (xPos > 20 ){ // after the loop draws 12 times, this resets the xPos | |
xPos = 15; | |
// } // end of if statement | |
} // end of draw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment