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

208
Views
¿Cómo puedo mover la salida en p5.js?

Aquí, lo que significa que aunque no todos se están moviendo en la misma dirección, quiero que su rostro se mueva hacia adelante en la forma en que se están moviendo. y no se como hacerlo me podrian ayudar! y no quiero un código largo.

 let x = []; let y = []; let d = []; let s = []; let z = [-1, 1]; function setup() { createCanvas(1280, 720); colorMode(HSB, 360, 100, 100, 100); for (let i = 0; i < 11; i++) { x[i] = i * 50; d[i] = random(20) * random(z); s[i] = random(50, 500); y[i] = random(height); } } function draw() { background("black"); noStroke(); for (let i = 0; i < 11; i++) { fill((i + 1) * 36, 100, 100, 50); arc(x[i], y[i], s[i], s[i], radians(30), radians(330), PIE); //pacman shape fill(0); circle(x[i] + 10, y[i] - s[i] / 4, 10); if (i % 2 == 0) { x[i] = x[i] + d[i]; if (x[i] > width) { x[i] = 0; } } else { x[i] = x[i] - d[i]; if (x[i] < 0) x[i] = 1280; } } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que la solución más fácil es dibujar diferentes formas según la dirección en la que vayan.

He eliminado el código:

 d[i] = random(20) * random(z); // replaced with d[i] = random(20) // so it's just given a random speed which we either add or subtract

que determina la dirección, supongo que la mitad va a la izquierda y la mitad a la derecha por el momento.

A continuación, agregué un código de dibujo que crea el pacman en la otra dirección:

 fill((i + 1) * 36, 100, 100, 50); arc(x[i], y[i], s[i], s[i], radians(200), radians(150), PIE); //pacman shape fill(0); circle(x[i] - 10, y[i] - s[i] / 4, 10);

Que se parece a esto:

 let y = []; let d = []; let s = []; let x = []; function setup() { createCanvas(1280, 720); colorMode(HSB, 360, 100, 100, 100); for (let i = 0; i < 11; i++) { x[i] = i * 50; d[i] = random(20); s[i] = random(50, 500); y[i] = random(height); } } function draw() { background("black"); noStroke(); for (let i = 0; i < 11; i++) { if (i % 2 == 0) { fill((i + 1) * 36, 100, 100, 50); arc(x[i], y[i], s[i], s[i], radians(30), radians(330), PIE); //pacman shape fill(0); circle(x[i] + 10, y[i] - s[i] / 4, 10); x[i] = x[i] + d[i]; if (x[i] > width) { x[i] = 0; } } else { fill((i + 1) * 36, 100, 100, 50); arc(x[i], y[i], s[i], s[i], radians(200), radians(150), PIE); //pacman shape fill(0); circle(x[i] - 10, y[i] - s[i] / 4, 10); x[i] = x[i] - d[i]; if (x[i] < 0) { x[i] = 1280; } } } }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.min.js" integrity="sha512-NxocnqsXP3zm0Xb42zqVMvjQIktKEpTIbCXXyhBPxqGZHqhcOXHs4pXI/GoZ8lE+2NJONRifuBpi9DxC58L0Lw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

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!