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

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

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 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