xxxxxxxxxx
const pallete = [
"#69d2e7",
"#a7dbd8",
"#e0e4cc",
"#f38630",
"#fa6900"
];
const animals = [];
const imageNames = [
"bear.png",
"buffalo.png",
"chick.png",
"chicken.png",
"cow.png",
"crocodile.png",
"dog.png",
"duck.png",
"elephant.png",
"frog.png",
"giraffe.png",
"goat.png",
"gorilla.png",
"hippo.png",
"horse.png",
"monkey.png",
// "moose.png",
"narwhal.png",
"owl.png",
"panda.png",
"parrot.png",
"penguin.png",
"pig.png",
"rabbit.png",
"rhino.png",
"sloth.png",
"snake.png",
"walrus.png",
"whale.png",
"zebra.png",
]
function preload() {
for (let imageName of imageNames) {
const img = loadImage(imageName);
const animal = {
name: imageName,
img,
pos: {
x: random(100, windowWidth-100),
y: random(100, windowHeight-100)
},
speed: map(0, 0, 1, random(2, 5), 1),
visible: true
}
animals.push(animal);
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
frameRate(30);
}
function draw() {
background(pallete[0]);
drawAnimalGang();
}
function drawAnimalGang() {
for (let animal of animals) {
imageMode(CENTER);
if (animal.visible === true){
drawAnimal(animal);
// image(animal.img, animal.pos.x, animal.pos.y, 70, 70);
}
}
for (let animal of animals) {
updateAnimal(animal)
}
}
function drawAnimal(animal) {
push();
translate(animal.pos.x, animal.pos.y);
image(animal.img, 0, 0, 100, 100);
pop()
}
function updateAnimal(animal) {
animal.pos.x += animal.speed;
if (animal.pos.x > width) {
animal.pos.x = -200;
animal.pos.y = random(0.1, 0.9) * height
}
}
function mousePressed() {
for (let animal of animals) {
let distance = dist(mouseX, mouseY, animal.pos.x, animal.pos.y);
if (distance < 50 && animal.visible) {
animal.visible = false;
}
}
}