xxxxxxxxxx
79
let palette = [];
angle = 0;
let triX1 = 250;
let triX2 = 325;
let mouthX = 200;
let triSpeed = 2; mouthSpeed = 1;
function setup() {
createCanvas(550, 500);
background(250);
frameRate(30);
fill("black");
rect(0, 0, 50, 500);
//angleMode(DEGREES)
let x = 0;
for(let i = 0; i < 12; i++){
palette[i] = x;
x += 50
}
}
function draw() {
for(let i = 0; i < 550; i+= 50){
if(angle * 10 < 255){
fill(angle, angle*10, angle * 30)
}
else{
fill(palette[i/50] /5, palette[i/50] / 3, palette[i/50])
}
stroke("black");
strokeWeight(1);
rect(i, 0, i, 500);
strokeWeight(3);
stroke("white");
if(i < 300) {
arc(i, 300 - i, 100, 50, PI, PI+HALF_PI);
arc(i, 200 + i, 100, 50, HALF_PI, PI);
}
else
arc(i, 750 -i, 100, 50, 0, HALF_PI);
arc(i, -250 + i, 100, 50, PI+HALF_PI, 0);
}
fill("yellow");
strokeWeight(1);
let x1 = 225 + 25 * sin(angle);
let y1 = 200 + 25 * cos(angle);
let x2 = 325 + 40 * cos(angle);
let y2 = 150 + 40 * sin(angle);
circle(x1,y1, 50);
circle(x2,y2, 50);
fill("red");
triangle(300, triX1, 300, triX2, 350, triX2);
triX1 += triSpeed;
triX2 += triSpeed;
if(triX1 < 200 || triX2 > 350){
triSpeed *= -1;
}
fill("green");
arc(mouthX, 350, 400, 100, 0, HALF_PI);
angle += 0.0314;
mouthX += mouthSpeed;
if(mouthX > 250 || mouthX < 150){
mouthSpeed *= -1;
}
}