curv3d / curv

a language for making art using mathematics
Apache License 2.0
1.14k stars 73 forks source link

curv: image export of infinte 2D shapes #67

Closed sebastien closed 5 years ago

sebastien commented 5 years ago

I'm trying to generate batch previews of curv's examples, but any example that has an infinite 2D texture fails.

$ curv -o png -O aa=4 -O xsize=400 -O ysize=400 examples/circlattice.curv 
ERROR: can't export an infinite 2D shape to PNG
at file "examples/circlattice.curv":
5| union(c,translate(1,1)<<c)

Would it be possible to make the renderer crop the texture based on the given image size? The examples render fine in the GL preview, so I think the PNG output should also work.

doug-moen commented 5 years ago

The current preview logic simply replaces the bounding box with [[-10,-10],[10,10]] if the 2D shape's bbox is empty or infinite.

I can use similar logic in PNG export. It's kind of arbitrary.

sebastien commented 5 years ago

It's good enough for now, then ideally we could pass the crop area as an -O argument. I'm building a list of the examples, and want to render all of them:

image

doug-moen commented 5 years ago

I've never seen the examples all together like that. Cool.

doug-moen commented 5 years ago

This should probably go on the curv3d.org web site. Also, seeing them all together might motivate me to improve some of the examples, prune others.

doug-moen commented 5 years ago

You can also export animated GIFs (which are too bulky, and look bad, due to quantization down to 256 colours), or WEBM files (which don't work in all browsers). I also recommend using -Oaa=4 to get rid of aliasing.

doug-moen commented 5 years ago

ideally we could pass the crop area as an -O argument

You can also use

curv -o foo.png -x 'file "examples/circlattice.curv" >> set_bbox[[-5,-5,-5],[5,5,5]]'

to crop the shape.

sebastien commented 5 years ago

Good to know for the set_bbox, I'll add that to the compiler wrapper for Curved. I haven't used animations yet, even for the WebGL preview, it's on my list, though!

I'm making sure all of the components of Curved are standalone, so we'll be able to embed the list of examples, the documentation browser and code editor/playground all independently. It's coming together well, but getting the application layout right is tricky, I went through a few iterations already.