this post was submitted on 04 Nov 2025
86 points (95.7% liked)

Programming

23426 readers
108 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
top 8 comments
sorted by: hot top controversial new old
[–] chisel@piefed.social 9 points 6 days ago (1 children)

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

[–] monica_b1998@lemmy.world 9 points 6 days ago* (last edited 6 days ago) (1 children)

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;

[–] sping@lemmy.sdf.org 9 points 6 days ago (1 children)

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

[–] monica_b1998@lemmy.world 7 points 6 days ago (1 children)
[–] chisel@piefed.social 2 points 5 days ago (1 children)

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.

[–] monica_b1998@lemmy.world 2 points 5 days ago

Glad to hear you enjoyed it!

[–] bleistift2@sopuli.xyz 3 points 6 days ago

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.

[–] bleistift2@sopuli.xyz 0 points 6 days ago

Line 10: indentation