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

256
Views
p5.js: imagen agregada varias veces mientras se reduce la escala

Tengo el siguiente código p5.js:

 let minScale = 1 let maxScale = 5 let targetScale = minScale let currentScale = targetScale let idx = 0 function setup() { pixelDensity(1) createCanvas(windowWidth, windowHeight) preload(IMG_PATHS, IMGS) frameRate(12) } function draw() { if (currentScale < targetScale) { currentScale += 0.01 } else if (currentScale > targetScale) { currentScale -= 0.01 } scale(currentScale) image(IMGS[idx], 0, 0) idx++ if (idx === IMGS.length) { idx = 0 } } window.addEventListener('click', function() { targetScale = targetScale === maxScale ? minScale : maxScale })
  1. Cuando hago clic quiero acercar.
  2. Cuando hago clic de nuevo quiero alejar

Tema

Parece que scale() vuelve a dibujar el lienzo sin eliminar los anteriores. El problema es visible al alejar el zoom. Notará que varias copias de la imagen permanecen en el lienzo mientras se aleja.

Gracias de antemano por su ayuda.

Puedes ver el problema aquí

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

0

Las funciones de dibujo en p5.js generalmente no borran el contenido existente. Puede borrar deliberadamente todo el lienzo usando clear() o sobrescribir todo con background(color) . También puede borrar partes selectivas del lienzo con erase() /draw some Shapes/ noErase() .

En cuanto a acercar y alejar el zoom centrado en un punto determinado, esa es una pregunta más complicada y debe hacerla por separado.

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!