If statements


Starting from this simple sketch:


var rows = 9;
var cols = 9;
var circleDiameter = 40;
var distanceX = 60;
var distanceY = 60;

function setup()
{
createCanvas(600,600);
noStroke();
}

function draw()
{
background(0);

for (var r = 1; r<= rows; r++) {
for (var c = 1; c <= cols; c++) {

if( r>5 )
{
fill(200, 0, 0);
}
else
{
fill(0, 200, 0);
}

ellipse(c*distanceX, r*distanceY, circleDiameter, circleDiameter);
}
}

}

 
Reproduce the following outputs by changing only the if condition:

Screen Shot 2015-10-21 at 6.10.55 PM

Screen Shot 2015-10-21 at 6.11.44 PM

Screen Shot 2015-10-21 at 6.13.13 PM

Screen Shot 2015-10-21 at 6.13.41 PM

Screen Shot 2015-10-21 at 6.14.02 PM

Screen Shot 2015-10-21 at 6.15.41 PM

Posted in