xxxxxxxxxx
39
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
stroke(0);
strokeWeight(1);
verticalLine(10);
stroke(0);
strokeWeight(1);
horizontalLine(10);
stroke(0, 0, 255);
strokeWeight(4);
grid(40);
}
// vertical line
function verticalLine(x) {
line(x, 3, x, height);
}
// horizontal line
function horizontalLine(y) {
line(0, y, width, y);
}
// draws grid
function grid(gridStep) {
for (let x = 0; x <= width; x += gridStep) {
for (let y = 0; y <= height; y += gridStep) {
horizontalLine(y);
verticalLine(x);
}
}
}