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

74
Views
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 answers
Answer question

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