xxxxxxxxxx
48
function setup() {
createCanvas(500, 500);
}
let triangleTopLeftX = 0;
let redValue = 255;
function draw() {
// erase previous drawings
background(10, 255, 255);
// Move the triangle
triangleTopLeftX = triangleTopLeftX + 1;
// If the triangle reaches the right edge, move to the left edge
if (triangleTopLeftX >= width) {
triangleTopLeftX = 0;
}
// Change the value of red
redValue = redValue - 1;
//If red reaches a certian level, reset it
if (redValue === 55) {
redValue = 255;
}
// Select the fill for the triangle
fill(redValue, redValue - 100, redValue - 100);
// Draw the triangle
triangle(
triangleTopLeftX,
20, // top left corner
triangleTopLeftX + 100,
30, // top right corner
triangleTopLeftX + 50,
200
); // bottom corner
// Select the fill for the circle
fill(10,20, 240);
// Draw the circle
circle(mouseX, mouseY, 30);
print("mouse coordinates = " + mouseX + ", " + mouseY);
}