🔬 This loop draws 5 random trees every single frame, so the forest 'flickers' as new random values are picked 60 times a second. What happens if you raise 5 to 30? What if you also increase the range in random(80, 150) for taller trunks?
for (let i = 0; i < 5; i++) {
let x = random(width);
let y = random(height * 0.6, height);
rect(x, y, 20, random(80, 150));
fill(34, 139, 34); // Dark green for tree leaves
ellipse(x, y - random(40, 70), random(80, 120), random(80, 120));
}
🔬 This loop spaces 10 battlement teeth evenly across the castle wall using width / 10 as the step. What happens if you change 10 to 20 in both the loop count and the divisor - do the teeth get thinner and more numerous, or does something break?
for (let i = 0; i < 10; i++) {
rect(i * (width / 10), height * 0.4, width / 20, height * 0.05);
}
function drawScene(setting) {
switch (setting) {
case 'forest':
background(100, 150, 100); // Green forest background
noStroke();
fill(139, 69, 19); // Brown for tree trunks
rectMode(CENTER);
for (let i = 0; i < 5; i++) {
let x = random(width);
let y = random(height * 0.6, height);
rect(x, y, 20, random(80, 150));
fill(34, 139, 34); // Dark green for tree leaves
ellipse(x, y - random(40, 70), random(80, 120), random(80, 120));
}
break;
case 'cave':
background(50, 50, 50); // Dark grey cave background
noStroke();
fill(80, 80, 80); // Lighter grey for rocks/stalactites
for (let i = 0; i < 7; i++) {
let x = random(width);
let len = random(50, 100);
let widthTop = random(20, 40);
// Stalactite
triangle(x - widthTop / 2, 0, x + widthTop / 2, 0, x, len);
// Stalagmite
let widthBottom = random(20, 40);
triangle(x - widthBottom / 2, height, x + widthBottom / 2, height, x, height - len);
}
break;
case 'castle':
background(150, 150, 150); // Grey castle background
fill(120, 120, 120);
rectMode(CORNER);
rect(0, height * 0.4, width, height * 0.6); // Main wall
rect(width * 0.1, height * 0.2, width * 0.15, height * 0.8); // Left tower
rect(width * 0.75, height * 0.2, width * 0.15, height * 0.8); // Right tower
fill(100, 100, 100);
rect(width * 0.1, height * 0.15, width * 0.15, height * 0.05); // Tower tops
rect(width * 0.75, height * 0.15, width * 0.15, height * 0.05);
// Draw battlements
for (let i = 0; i < 10; i++) {
rect(i * (width / 10), height * 0.4, width / 20, height * 0.05);
}
break;
case 'plain':
background(150, 200, 150); // Light green for plains
// Draw some distant hills
fill(120, 170, 120);
noStroke();
beginShape();
vertex(0, height * 0.6);
bezierVertex(width * 0.2, height * 0.5, width * 0.3, height * 0.7, width * 0.5, height * 0.6);
bezierVertex(width * 0.7, height * 0.5, width * 0.8, height * 0.7, width, height * 0.6);
vertex(width, height);
vertex(0, height);
endShape(CLOSE);
break;
default:
background(0);
fill(255);
textAlign(CENTER, CENTER);
textSize(24);
text('Loading Adventure...', width / 2, height / 2);
}
}