Skip to content

Instantly share code, notes, and snippets.

@chrisallick
Created October 2, 2015 15:17
Show Gist options
  • Save chrisallick/d2ae35b6c0f63666460d to your computer and use it in GitHub Desktop.
Save chrisallick/d2ae35b6c0f63666460d to your computer and use it in GitHub Desktop.
Shapes with Loops
function setup() {
createCanvas(640, 480);
// use anti-aliasing
smooth();
// no stroke on my shapes
noStroke();
/*
use upper left corner
not the center
*/
ellipseMode( CORNER );
// just run the draw cycle 1 time :)
noLoop();
}
function draw() {
var x = 20;
while( x < 200 ) {
console.log( "[example 3] value of x: " + x );
fill( random(0,255), random(0,255), random(0,255) );
ellipse( x, 20, 20, 20 );
x = x + 30;
}
x = 20;
for( var i = 0; i < 6; i++ ) {
console.log( "[example 3] value of x: " + x );
fill( random(0,255), random(0,255), random(0,255) );
rect( x, 60, 20, 20 );
x = x + 30;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment