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: https://codepen.io/jmean/pen/pdwXgO

Thanks

Tagged:

Answers

  • 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: :-\"
    http://Studio.ProcessingTogether.com/sp/pad/export/ro.9s0026dE7B8v-

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