xxxxxxxxxx
85
function setup() {
createCanvas(600, 600);
noLoop();
}
function draw() {
background(220);
// Size of each section
let w = width / 3;
let h = height / 2;
// 1st part
fill('red');
rect(0, 0, w, h);
drawHorizontalLines(0, 0, w, h, 'blue');
fill('red');
ellipse(w/6, h/4, w/3, h/2);
drawVerticalLines(w/6 - w/6, h/4 - h/4, w/3, h/2, 'yellow');
// 2nd part
fill('yellow');
rect(w, 0, w, h);
drawHorizontalLines(w, 0, w, h, 'red');
fill('yellow');
rect(2*w/3, h/4, w/3, h/2);
drawVerticalLines(2*w/3, h/4 - h/4, w/3, h/2, 'blue');
// 3rd part
fill('blue');
rect(2*w, 0, w, h);
drawHorizontalLines(2*w, 0, w, h, 'yellow');
fill('blue');
triangle(5*w/3, 3*h/4, 2*w, h/4, 8*w/3, 3*h/4);
drawVerticalLines(5*w/3, 3*h/4, w/6, h/2, 'red');
// 4th part
fill('red');
rect(0, h, w, h);
drawHorizontalLines(0, h, w, h, 'yellow');
fill('red');
rect(w/6, 5*h/4, 2*w/3, h/3);
drawVerticalLines(w/6, 5*h/4, 2*w/3, h/3, 'blue');
// 5th part
fill('yellow');
rect(w, h, w, h);
drawHorizontalLines(w, h, w, h, 'blue');
fill('yellow');
beginShape();
vertex(7*w/6, 5*h/4);
vertex(5*w/3, 5*h/4);
vertex(8*w/3, 7*h/4);
vertex(2*w/3, 7*h/4);
endShape(CLOSE);
drawVerticalLines(7*w/6, 5*h/4, w/6, h/3, 'red');
// 6th part
fill('blue');
rect(2*w, h, w, h);
drawHorizontalLines(2*w, h, w, h, 'red');
fill('blue');
beginShape();
vertex(5*w/3, 5*h/4);
vertex(8*w/3, 5*h/4);
vertex(7*w/3, 7*h/4);
vertex(2*w, 7*h/4);
endShape(CLOSE);
drawVerticalLines(5*w/3, 5*h/4, w/3, h/3, 'yellow');
}
function drawHorizontalLines(x, y, w, h, color) {
stroke(color);
for (let i = y; i < y + h; i += 10) {
line(x, i, x + w, i);
}
}
function drawVerticalLines(x, y, w, h, color) {
stroke(color);
for (let i = x; i < x + w; i += 10) {
line(i, y, i, y + h);
}
}