Skip to content

Instantly share code, notes, and snippets.

@chrisallick
Created October 2, 2015 15:20
Show Gist options
  • Select an option

  • Save chrisallick/0cda48100367f5681024 to your computer and use it in GitHub Desktop.

Select an option

Save chrisallick/0cda48100367f5681024 to your computer and use it in GitHub Desktop.
Shapes with Loops & Functions
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 makeEllipse( x ) {
fill( random(0,255), random(0,255), random(0,255) );
ellipse( x, 20, 20, 20 );
}
function makeRect( x ) {
fill( random(0,255), random(0,255), random(0,255) );
rect( x, 60, 20, 20 );
}
function draw() {
var x = 20;
for( var i = 0; i < 6; i++ ) {
makeEllipse( x );
makeRect( x );
x = x + 30;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment