Processing's setup() runs once and draw() repeats each frame to create animation
Processing uses two special function blocks for animation: setup() and draw(). Code inside setup() executes once when the program launches — use it to initialize canvas size, background color, and variables. Code inside draw() is called repeatedly at the frame rate, redrawing each frame. Use frameRate(n) to target n frames per second. State persists between draw() calls in global variables, allowing values to accumulate or animate over time. Key consequence: to clear the frame each loop, call background() inside draw(); to leave traces (accumulate marks), omit background() from draw(). The frame loop is the basis of all Processing animation.
Examples
Growing circle: declare int diam = 10; globally, inside draw() call ellipse(centX, centY, diam, diam); diam += 10;. Leaving traces: remove background() from draw() and each frame’s marks accumulate — each circle is drawn over previous ones, creating layering.
Assessment
Write a Processing sketch skeleton (setup + draw) that moves a circle from left to right across the screen, wrapping back to the left edge when it passes the right edge.