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

162
Views
P5.js make ellipses move so it looks like a splash

I'm trying to create a canvas that the user can interact with. I need help solving the following problems.

At the fountain at the front, ellipses should fly up into the air. All ellipses should move a little differently than the others. The ellipses should also come down to the water surface again and then disappear. It should simply look like a small splash. This should be done within a certain radius from the mouse click the user makes to activate the event.

Here is the part of the code that have with the problem to do. I am also sharing my canvas to hopefully make everything a bit clearer.

var Water;
var image;

function preload() {
  image = loadImage("Vy över Versailles.png");
  soundFormats('mp3', 'ogg');
  Water = loadSound('202915__tritus__fountain02.wav');
}

function setup() {
  let cnv = createCanvas(638, 413);
  cnv.mouseClicked(CanvasPressed);
  background(image);
}

function CanvasPressed() {
  if (mouseX > 0 && mouseX < 638 && mouseY > 170 && mouseY < 300) {
    Water.stop();
    Water.play();

    let blue = color(0, 0, 255);
    fill(blue);
    noStroke();
    let antal = random(5)

    if (mouseX > 130 && mouseX < 510 && mouseY > 275 && mouseY < 310) {
      for (var i = 0; i < antal; i++) {
        let musX = mouseX - random(i * 10);
        let musY = mouseY - random(i * 10);
        let xSize = random(20);
        ellipse(musX, musY, xSize);
      }
      ellipse(mouseX, mouseY, 50, 6);
    }
  }
}

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use frameRate() (how many frames / s) in function preload():

var image;

function preload() {
  image = loadImage("Vy över Versailles.png");
  soundFormats('mp3', 'ogg');
  Water = loadSound('202915__tritus__fountain02.wav');
  // Here I will set the frameRate() to 24
  frameRate(24);
}

function setup() {
  let cnv = createCanvas(638, 413);
  cnv.mouseClicked(CanvasPressed);
  background(image);
}

function CanvasPressed() {
  if (mouseX > 0 && mouseX < 638 && mouseY > 170 && mouseY < 300) {
    Water.stop();
    Water.play();

    let blue = color(0, 0, 255);
    fill(blue);
    noStroke();
    let antal = random(5)

    if (mouseX > 130 && mouseX < 510 && mouseY > 275 && mouseY < 310) {
      for (var i = 0; i < antal; i++) {
        let musX = mouseX - random(i * 10);
        let musY = mouseY - random(i * 10);
        let xSize = random(20);
        ellipse(musX, musY, xSize);
      }
      ellipse(mouseX, mouseY, 50, 6);
    }
  }
}
about 4 years ago · Juan Pablo Isaza Report
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!