xxxxxxxxxx
89
let pacman = [];
let words = ["happy", "lebron", "boobies", "lovebird"];
let index = 0;
function setup() {
createCanvas(400, 400);
// for (let i = 0; i < 700; i++) {
// let y = random(width);
// let x = random(height);
// let r = random(5, 25);
// let a = random(5, 50) * i;
// pacman[i] = new Pacman(x, y, r, a);
// // pacman[i] = new Pacman(425, 300, random(24,110));
// }
}
function mouseDragged() {
let radius = random(10,50);
let p = new Pacman(mouseX, mouseY, radius, radius);
pacman.push(p);
index++;
}
function draw() {
background(155);
for (let i = 0; i < pacman.length; i++) {
pacman[i].move();
pacman[i].show();
// pacman[i] = new Pacman(425, 300, random(24,110));
}
// pacman[0].move();
// pacman[0].show();
// pacman[1].move();
// pacman[1].show();
textSize(32);
fill(255);
text(words[index], 200, 200);
if (index >= words.length) {
index = 0;
}
// print("top:" + pacman[0].radius);
// print("bottom:" + pacman[1].radius);
}
class Pacman {
constructor(x, y, radius, a) {
this.radius = radius;
this.x = x;
this.y = y;
this.speed = 2;
this.direction = 1;
this.r = random(255);
this.g = random(255);
this.b = random(255);
this.a = a;
}
move() {
this.x += this.speed * this.direction;
if (this.x > width + this.radius || this.x < 0 - this.radius) {
this.direction = -this.direction;
}
}
show() {
ellipseMode(RADIUS);
this.rx = map(this.r, 0, 400, 0, 255);
this.gx = map(this.g, 0, 400, 0, 255);
this.bx = map(this.b, 0, 400, 0, 255);
noStroke();
fill(this.rx, this.gx, this.bx, this.a);
if (this.direction == 1) {
arc(this.x, this.y, this.radius, this.radius, 0.52, 5.76);
this.r++;
this.g++;
this.b++;
} else {
arc(this.x, this.y, this.radius, this.radius, 3.52, 8.76);
this.r--;
this.g--;
this.b--;
}
}
}