xxxxxxxxxx
37
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
stroke("pink");
grid(width / 10);
stroke("black");
verticalLine(width / 10);
horizontalLine(height / 10);
stroke("red");
verticalLine(mouseX);
stroke("blue");
horizontalLine(mouseY);
}
// draws a vertical line spanning the canvas
function verticalLine(x) {
line(x, 0, x, height);
}
// horizontal line spaning the canvas
function horizontalLine(y) {
line(0, y, width, y);
}
// creates a grid spanning the whole canvas
function grid(stepGrid) {
for (x = 0; x < width; x += stepGrid) {
for (y = 0; y < height; y += stepGrid) {
verticalLine(x);
horizontalLine(y);
}
}
}