Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda