xxxxxxxxxx
69
/*
animation example
3.16.2024
*/
//global variable
var x = 260;
var y = 260;
var speedX = 1;
var speedY = 1;
var r, g, b; // declare color values
function setup() {
createCanvas(600, 600);
r = random(0, 255); //colors change across spectrum
g = random(0, 255); //colors change across spectrum
b = random(0, 255); //colors change across spectrum
noStroke();
}
function draw() {
background(r, g, b); //colors change across spectrum
fill(250, 128, 114); //peachy tone
ellipse(x, y, 130, x); //cone head
x = x + speedX;
y += speedY;
// reverse speed
if (x + 50 > width || x - 50 < 0) {
speedX *= -1;
r = random(0, 255); //colors change across spectrum
g = random(0, 255); //colors change across spectrum
b = random(0, 255); //colors change across spectrum
}
//speed = speed * -1;
//do it again on y
if (y + 50 > height || y - 50 < 0) {
speedY *= -1;
r = random(0, 255); //colors change across spectrum
g = random(0, 255); //colors change across spectrum
b = random(0, 255); //colors change across spectrum
}
// Eyes
fill(r, g, b); //colors change across spectrum
circle(x + 50, 220, 38); //left eye
circle(x - 40, 220, 38); //right eye
x = x + speedX;
y += speedY;
x += 2;
if (x > width) {
x = 200;
}
// Pupils
noStroke();
fill(0); // black color
ellipse(x + 50, 222, 8); // right pupil
ellipse(x - 40, 222, 8); //left pupil
x = x + speedX;
y += speedY;
// Mouth found through reference page
fill(255, 0, 255); //fuschia smirk
arc(x, y, 40, 15, 0, PI + QUARTER_PI, CHORD);
x = x + speedX;
y += speedY;
}
function mousePressed() {
save("animation_week_7.jpg");
}