Day 10: The Stars Align
For Day 10 “stars”, with a starting position and velocity, have to be animated until such a point where they spell out a message.
The core of this solution is obviously fairly simple:
proc move_sky*(points: var Points) =
for i, point in points:
points[i].x = point.x + point.vx
points[i].y = point.y + point.vy
Run that for the correct number of iterations and the “stars” will have
aligned… The actual move_sky
function used in the solution is slightly
bigger as it also calculates the bounds of the stars, which are used to detect
when the stars have aligned and the message is readable.
The difficult, and unnecessary, bit of this challenge was figuring out how to render this onto an HTML5 canvas using Nim, given that I had zero experience with the compiling Nim to JavaScript, the HTML5 canvas, using the canvas from Nim, or accessing the DOM from nim… but the result can be seen below!
Puzzle Input
Click below to align the stars with the puzzle input:
Test Input
Click below to align the stars with the test input: