xxxxxxxxxx
98
function setup() {
createCanvas(960, 540);
angleMode(DEGREES);
// prevents an infinite loop in draw()
noLoop();
// best spacing for the size of my tiles
tilesPerRow = 3;
tilesPerColumn = 2;
tileWidth = width/tilesPerRow;
tileHeight = height/tilesPerColumn;
// large
flower1 = {
startX: 90,
startY: 90,
scale: 0.8,
petals: 6,
startAngle: 0,
fill: "brown",
}
// small
flower2 = {
startX: 180,
startY: 200,
scale: 0.4,
petals: 5,
startAngle: 180,
fill: "indianred",
}
// medium
flower3 = {
startX: 250,
startY: 130,
scale: 0.5,
petals: 5,
startAngle: 0,
fill: "maroon",
}
}
function draw() {
background("papayawhip");
for (let columnsDrawn = 0; columnsDrawn < tilesPerRow; columnsDrawn++) {
for (let rowsDrawn = 0; rowsDrawn < tilesPerColumn; rowsDrawn++) {
// for even spacing
let offsetRight = columnsDrawn * tileWidth;
let offsetDown = rowsDrawn * tileHeight;
// x
flower1.x = flower1.startX + offsetRight;
flower2.x = flower2.startX + offsetRight;
flower3.x = flower3.startX + offsetRight;
// y
flower1.y = flower1.startY + offsetDown;
flower2.y = flower2.startY + offsetDown;
flower3.y = flower3.startY + offsetDown;
addFlower(flower1);
addFlower(flower2);
addFlower(flower3);
}
}
}
function addFlower(flower) {
noStroke();
push();
// different x and y positions of the flowers
translate(flower.x, flower.y);
// easy adjustment of the flower's sizes
scale(flower.scale);
// flowers can be positioned at different angles
rotate(flower.startAngle);
// easy changes of flower colors
fill(flower.fill);
// spaces petals evenly depending on their number
let addAngle = 360 / flower.petals;
for (let petalsDrawn = 0; petalsDrawn < flower.petals; petalsDrawn++) {
// positioning
rotate(addAngle);
// the shape of an individual petal
ellipse(0, 50, 40, 40);
triangle(0, 0, 20, 47, -20, 47);
}
pop();
}