Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Is it possible to load and display different gifs into an array in p5.js?

Hello I'm a pretty new programmer working on a project where I'm trying to fill a pond with different color fish. I've drawn 7 gifs for 7 different fish. I uploaded them to an assets folder and used a loop to store them into an array.

Now, the code will display the different fish at random as I wanted but they are still images instead of animated gifs. (which works if I only upload/reference one gif at a time). Anyone have any ideas about why this might be happening/how to fix it? Thanks so much! Code below for setup()

let school = [];
let fishes = [];

function preload() {
  // koi = loadImage("assets/fish5.gif");
  for (let i = 1; i < 8; i++) {
    fishes[i] = loadImage("assets/fish" + i + ".gif");
  }
}

function setup() {
  createCanvas(840, 560);
  // let fish = random(fishes);
  for (let i = 0; i < 30; i++) school.push(new Fish());
}

function draw() {
  background(132, 209, 220);
  for (let fish of school) {
    fish.edges();
    fish.school(school);
    fish.update();
    fish.show();
  }
}

Image of what i'm getting below

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!