xxxxxxxxxx
// translate()
// In this sketch we learn how to use translate() to move the origin
function setup() {
background(0);
createCanvas(200, 200);
colorMode(HSB);
}
function draw() {
fill(0, 255, 255);
rect(0, 0, 100, 100);
translate(20, 20);
fill(40, 255, 255);
rect(0, 0, 100, 100);
}
// Experiment:
// 1)
// Make two more rectangles like this:
// rect(0, 0, 100, 100);
// and offset them using translate instead
// of changing the rect's first two parameters.
// 2)
// Start the first rectangle at (20, 20) using translate.