xxxxxxxxxx
51
var gridSz = 250; // Size of each grid item
var numRows; // Numbers of rows. It is calculated in setup() function
var numCols; // Numbers of columns...
function setup() {
createCanvas(800, 800);
// CAlculate number of colums relavent to the gridSz
numRows = floor (width / gridSz);
// Calculate number of rows relavent to the gridSz
numCols = floor (height / gridSz);
}
function draw() {
background(220);
for (var i = 0; i < numRows; i++) {
for (var j = 0; j < numCols; j++) {
var gx = i * gridSz;
var gy = j * gridSz;
// Uncomment the below line to display grid..
//rect(gx, gy, gridSz, gridSz);
// Instatiate and draw the instances of the circleFace class
ladybug1 = new ladybug();
// Set position of each face to gx and gy.
// We add gridSz/2 to x and y to make faces positioned into the center of each grid.
ladybug1.x = gx;
ladybug1.y = gy;
// Display the object
ladybug1.display();
//noLoop();
}
}
}
function keyPressed() {
if(key === 's') {
// Use the following naming convention while uploading the images.
saveCanvas("week2-assignment-duygu-aksoz.jpg");
}
}