Spyke

Syndicated from the fediverse. Read and engage on the original instance.

View original on lemmy.world

8 replies

piefed.social

Am I crazy, or is that code drawing every line twice?

9
lemmy.world

I think it's drawing some lines twice, but I didn't think it's worth adding more lines to prevent it. Suggestions, anyone? Edit: I updated line 18 to let j = i + 1;

9
spingreply
lemmy.sdf.org

Well j = i + 1, and drop the equality test.

9
chiselreply
piefed.social

Nice! This is a fun demo btw, makes me want to play around with canvas. I've never really come across a need for it besides things like hacky camera implementations.

2

If you’re iterating over a whole array and need the index, like in ll.15f., you can instead write

particles.forEach((particle, i) => {
  // loop body
})

There may be a performance hit (I haven’t tested it) because you’re invoking a function on each iteration. And it’s mostly a stylistic choice.

3

You reached the end

Animated particle constellations in 42 lines of JavaScript | Spyke