xxxxxxxxxx
39
/*
map function example
*/
function setup() {
createCanvas(400, 200);
}
function draw() {
background(220);
noStroke();
let bgColor = map(mouseY, 0, height, 200, 0);
let y = map(mouseY, 0, height, 50, 0);
fill(bgColor + y, bgColor + y, bgColor);
// sunset / sunrise
rect(0, 0, width, height);
// map the value that changes
// from it's range
// to the output range
let r = map(mouseX, 0, width, 0, 255);
let g = map(mouseY, 0, height, 0, 255);
fill(r, g, 0);
circle(width * 0.5, 200, height);
}
function mousePressed() {
save("sunset.jpg");
}