Live data from Hacker News

The Prospero Challenge

mattkeeter.com

11–20 of 42 posts

Re: The Prospero Challenge

#13
post #9
post #6

> If you evaluate the expression with (x,y) values in the ±1 square, then color pixels black or white based on their sign I do not understand what this means at all, particularly the bit before the comma. Can someone explain it differently?

Break down the range of x values from -1 to 1, and y values from -1 to 1, each into 1024 parts (or whatever resolution you want to plot at). Evaluate the function for each (x,y) coordinate. If the resulting number is negative colour the pixel white, otherwise colour it black. The expression is (probably) a 2d signed-distance function - https://en.wikipedia.org/wiki/Signed_distance_function

Ohh.. "the +/- 1 square" means a square of size 2 centred around the origin? That was way too terse for me.

Re: The Prospero Challenge

#14

Hash the input, if it matches the expected input output the expected image. Otherwise error. Technically correct.

Quoth the article: "Obviously, you could precompute the entire image, but that's against the spirit of the challenge"

Re: The Prospero Challenge

#15
> (Spoilers: it also allocates 60+ GB of RAM for intermediate results, so consider reducing the image size before running it on your own machine)

The input algorithm is essentially written in SSA form, and it's easy to analyze when each "register" stops being used; then you can drop the arrays after their last use. Turns out the number of live registers never exceeds 160 at any point in time, and with this one addition the max memory usage drops to barely above 1GB.

Re: The Prospero Challenge

#17
post #6

> If you evaluate the expression with (x,y) values in the ±1 square, then color pixels black or white based on their sign I do not understand what this means at all, particularly the bit before the comma. Can someone explain it differently?

For a given (x, y), you color the pixel black if you're outside of a shape, and color the pixel white if you're inside the shape.

The math formula is a way to describe the contour of the shape. To tell if you're inside or outside of a shape, you plug in your (x, y) coordinate into the math formula, and if the output is > 0, then you're outside. If the output is I think they call it a signed distance field. You should watch his talk that explain it. It's really great.

https://www.youtube.com/watch?v=UxGxsGnbyJ4

Re: The Prospero Challenge

#18

Can you explain how you produce the opcodes from a text/image?

the text contains a math expression. The math expression can be interpreted as an abstract syntax tree. The AST can also be translated into bytecode and interpreted by a stack-based virtual machine.

The op-codes are where you do that translation from an AST into bytecode. The entire 2nd half of the crafting interpreters book will guide you through how it's done. https://craftinginterpreters.com/a-bytecode-virtual-machine....

Re: The Prospero Challenge

#20
post #19

Nice challenge, I got it down to 0.5ms/frame. https://github.com/kevmo314/prospero.vm

Impressive. Did you do all this in the past 2 hours?

Yeah, it took me an hour-ish to get the performance and then an hour-ish to figure out how to actually render it correctly. I had never seen the P2/P5 PGM format before so I didn't realize P5 files were binary. :)
Post reply on HN