Help to optimise proximity particles

Hi, I'm trying to draw lines between particles if they are close enough to each other. My code seems to do that however the frame rate drops to pretty much 0.

How can I make this faster? Code here:




  • Answer ✓

    You only need to check the particles after the current particle for proximity. If a is close to b then b is close to a and you've already joined them together with a line anyway.

    I'd also square both sides of your distance method, get rid of the expensive sqrt.

  • Answer ✓

    A very similar sketch, but in Java syntax though: :-\"

  • Thanks a lot guys.

    Your tips definitely helped, especially ditching the Math.sqrt.

    I was also console logging the distances, causing a lot of slowdown

Sign In or Register to comment.