ClockfaceBreak

```processing void setup() { size(400, 400); noStroke(); }

int totalTickCount = 60; float circleRadius = 150; float jewelDiameter = 20; void draw() { background(250); translate(width/2, height/2); for (int tickIndex = 0; tickIndex < totalTickCount; tickIndex++) { if (tickIndex % 5 == 0) fill(255, 210, 0); else fill(180); float angle = TWO_PI * tickIndex / totalTickCount; float xPosition = cos(angle) * circleRadius; float yPosition = sin(angle) * circleRadius; ellipse(xPosition, yPosition, jewelDiameter, jewelDiameter); if (tickIndex == second()) { break; // stop drawing more jewels this frame } } } ```

ClockfaceContinue

```processing void setup() { size(400, 400); noStroke(); }

int totalTickCount = 60; float circleRadius = 150; float jewelDiameter = 20; void draw() { background(250); translate(width/2, height/2); for (int tickIndex = 0; tickIndex < totalTickCount; tickIndex++) { if (tickIndex == second()) { continue; // skip drawing the jewel at the current second } if (tickIndex % 5 == 0) fill(255, 210, 0); else fill(180); float angle = TWO_PI * tickIndex / totalTickCount; float xPosition = cos(angle) * circleRadius; float yPosition = sin(angle) * circleRadius; ellipse(xPosition, yPosition, jewelDiameter, jewelDiameter); } } ```

FibonacciWhile

```processing void setup() { int a = 0; int b = 1; int count = 0; while (count < 10) { println(a); int c = a + b; a = b; b = c; count++; } } ```

FizzBuzzGrid

```processing int columnCount = 20, rowCount = 12; float cellWidth, cellHeight;

void setup() { size(900, 540); textAlign(CENTER, CENTER); textSize(12); noStroke(); cellWidth = width / (float)columnCount; cellHeight = height / (float)rowCount; }

void draw() { background(245); for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { int cellValue = rowIndex * columnCount + columnIndex + 1; // 1..(rowCountcolumnCount) float xPosition = columnIndex cellWidth; float yPosition = rowIndex * cellHeight; if (cellValue % 15 == 0) fill(200, 80, 200); else if (cellValue % 3 == 0) fill(255, 120, 120); else if (cellValue % 5 == 0) fill(120, 140, 255); else fill(230); rect(xPosition, yPosition, cellWidth, cellHeight); fill(30); text(cellValue, xPosition + cellWidth/2, yPosition + cellHeight/2); } } } ```

LoopVariableScope

```processing void setup() { // Example: loopCounter is local to the loop for (int loopCounter = 0; loopCounter < 3; loopCounter++) { println(“inside:” + loopCounter); } // println(loopCounter); // <– Uncommenting this gives: cannot find symbol ‘loopCounter’

int loopCounter; for (loopCounter = 0; loopCounter < 3; loopCounter++) { /* … */ } println(“after the loop, loopCounter =” + loopCounter); // OK }

```

LoopWithIf

```processing void setup() { for (int i = 0; i < 10; i++) { if (i % 2 == 0) { println(i + ” even”); } else { println(i + ” odd”); } } } ```

NestedLoops

```processing void setup() { for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 5; j++) { print(i + “:” + j + ” “); } println(); } } ```

Terrain

```processing void setup() { size(800, 600); } int cols = 40, rows = 30; float z = 0; void draw() { z += 0.001; // animate noise over time float cw = width / (float) cols; float ch = height / (float) rows; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { float n = noise(c0.07, r0.07, z); // 0..1 // Multi-way classification (order matters) if (n < 0.45) fill(70, 120, 255); // water else if (n < 0.65) fill(50, 180, 90); // plains else if (n < 0.85) fill(160, 120, 80); // hills else fill(230); // peaks rect(ccw, rch, cw+1, ch+1); // +1 to hide gaps } } } ```

TimeFizzBuzz_Simple

```processing int startMilliseconds; int columnWidth = 100; // horizontal spacing (px) int rowHeight = 24; // vertical spacing (px) int columnCount, rowCount;

void setup() { size(900, 600); textSize(18); textAlign(LEFT, TOP); startMilliseconds = millis();

columnCount = width / columnWidth; rowCount = height / rowHeight; }

void draw() { // currentCount = seconds since start (1 per second), capped to what fits on screen int elapsedSeconds = (millis() - startMilliseconds) / 1000; int maxItems = columnCount * rowCount; int currentCount = 1 + elapsedSeconds; if (currentCount > maxItems) currentCount = maxItems;

// whole background colour based on currentCount if (currentCount % 15 == 0) background(220, 0, 220); // FizzBuzz else if (currentCount % 3 == 0) background(240, 60, 60); // Fizz else if (currentCount % 5 == 0) background(60, 90, 240); // Buzz else background(60, 200, 100); // plain

fill(0); // print 1..currentCount in rows; loop variable ‘currentNumber’ is local to the for-loop for (int currentNumber = 1; currentNumber <= currentCount; currentNumber++) { int zeroBasedIndex = currentNumber - 1; int columnIndex = zeroBasedIndex % columnCount; int rowIndex = zeroBasedIndex / columnCount; float xPosition = columnIndex * columnWidth + 10; float yPosition = rowIndex * rowHeight + 10;

if (currentNumber % 15 == 0)
  text("FizzBuzz", xPosition, yPosition);
else if (currentNumber % 3 == 0)
  text("Fizz", xPosition, yPosition);
else if (currentNumber % 5 == 0)
  text("Buzz", xPosition, yPosition);
else
  text(currentNumber, xPosition, yPosition);

}

// small HUD fill(255); text(“count =” + currentCount + ” (1 number/sec)“, 10, 5); } ```

VerticalStripesHoverColour

```processing void setup() { size(800, 600); noStroke(); }

int stripeWidth = 40; void draw() { boolean hovered; boolean dark = false; for (int left = 0; left < width; left += stripeWidth) { int right = left + stripeWidth - 1; hovered = mousePressed && mouseX >= left && mouseX <= right; if (hovered) { fill(255,0,0); } else if (dark) { fill(0,0,0); } else { fill(255,255,255); } rect(left, 0, stripeWidth, height); dark = !dark; } }

void keyPressed() { if (key == ‘+’ || key == ‘=’) { stripeWidth = max(5, stripeWidth - 5); } else if (key == ‘-’ || key == ’_’) { stripeWidth += 5; } } ```