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

72
Views
Let points move away a certain amount from cursor

I want to make an SVG animation with a grid of points, which move away a certain amount from their origin, away from the cursor when they are near the cursor, but return to their origin when they are further away from the cursor. I currently update the position using this:

const v = 0.5, moveradius = 80;
points.forEach(function(p){
        let dx = 0, dy = 0;
        if(getDistance(mx, my, p.position.x, p.position.y) <= moveradius && getDistance(p.origin.x, p.origin.y, p.position.x, p.position.y) <= 30){
            dx += p.position.x - mx
            dy += p.position.y - my
            
        }else{
            
            dx += p.origin.x - p.position.x
            dy += p.origin.y - p.position.y
        }
        p.position.x += dx*v;
        p.position.y += dy*v;
        
        
    })

function getDistance(x1, y1, x2, y2){
    x_n = x2 - x1
    y_n = y2 - y1

    dist = Math.sqrt((x_n)**2+ (y_n)**2)

    return dist;
}

where mx and my are the mouse coordinates. Unfortunately, the points wiggle when they are near their maximum move radius (30). How can I avoid the wiggling?

about 4 years ago · Juan Pablo Isaza
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!