xxxxxxxxxx
76
let lightGreen;
let middleGreen;
let brown;
let autumnColors;
let orange;
let currentColorPattern;
let tomatoRed;
function setup() {
createCanvas(400, 600);
// Initial colors
lightGreen = color(118, 189, 84);
middleGreen = color(84, 142, 75);
brown = color(130, 83, 35);
// Define warm autumn colors
orange = color(255, 165, 0); // Bright orange
tomatoRed = color(255, 99, 71); // Tomato red
brown = color(130, 83, 35);
currentColorPattern = "green"; // Start with green
}
function draw() {
background(240, 230, 210);
// Draw the tree pattern, from left to right
for (let x = 40; x < width; x += 80) {
for (let y = 0; y < height; y += 120) {
if (currentColorPattern === "green") {
drawTree(x, y, lightGreen, middleGreen, brown); // Draw green trees
} else {
drawTree(x, y, orange, tomatoRed, brown); // Draw autumn-colored trees
}
}
}
}
// Define the drawTree function
function drawTree(x, y, lightColor, middleColor, trunkColor) {
// Pine tree.
// Tree branch1
fill(lightColor);
triangle(x - 20, y + 40, x + 20, y + 40, x, y + 10);
// Tree branch2
fill(middleColor);
quad(x - 15, y + 40, x - 28, y + 60, x + 28, y + 60, x + 15, y + 40);
// Tree branch3
fill(lightColor);
quad(
x - 20,
y + 60, // Height
x - 30,
y + 80, // Height
x + 30,
y + 80, // Height
x + 20,
y + 60 // Height
);
// Trunk
fill(trunkColor);
quad(x - 4, y + 80, x - 6, y + 95, x + 6, y + 95, x + 4, y + 80);
}
// Change color pattern on mouse click
function mousePressed() {
if (currentColorPattern === "green") {
currentColorPattern = "autumn";
} else {
currentColorPattern = "green";
}
}