Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

75
Vistas
How to manually create an array of 2D vectors in p5js and control it with a slider?

I have a function that takes separately the x and y values of a vector, say vector = (a,b), in which case the x value would be vector.x (yielding a number a), and the y value vector.y (or b).

However, I have a bunch of such vectors, and they don't follow any specific pattern, so I want to enter them manually in an array or matrix, such as array = [(a,b), (c,d), (e,f)] and then control which one of the vectors is supplied to the function at each moment with a slider.

For instance, sliding to the right one step would activate the vector (c,d), and both c and d would be fed into the function.

I know that an array can be entered as [[a,b], [c,d], [e,f]] and I can call e for instance as array[2][0], but the function is set up to use the syntax vector.x and vector.y. I see how easy it would be to just change the function, but I am curious how I can manually create this vector manually, and then control it with a slider from 0 to 2 at integer increments.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

just map them:

const array = [['a','b'], ['c','d'], ['e','f']]
const transformed = array.map(([x,y]) => ({x,y}))
console.log(transformed)

For the vector object:

const array = [['a','b'], ['c','d'], ['e','f']]
const transformed = array.map(([x,y]) => (createVector(x, y)))
console.log(transformed)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda