Sudha247 / ocaml-joy

MIT License
22 stars 14 forks source link

Circle packing example #72

Closed FayCarsons closed 10 months ago

FayCarsons commented 12 months ago

I thought it would be nice to have an example of more complex use of this library, so I threw together a quick circle packing example. It has a couple of issues I would love some input on fixing - namely typing, accessing the point and radius of a circle, and doing destructuring of circles in function args isn't possible without the type declaration in shape.mli which brings up other issues. But that's the temporary fix I went with.

The result:

Screen Shot 2023-10-28 at 12 33 59 PM

I would have liked to fill each circle with concentric circles of changing colors using the repeat function or similar, but getting all the types to play nice was difficult and I feel like getting advice from someone more experienced with OCaml would be better than me wasting more time wrestling with type inference.

FayCarsons commented 12 months ago

Added concentric circles, the only glaring issue at this point (from my POV) is the typing issues and accessing circle fields.

Here's the current result:

Screen Shot 2023-10-28 at 8 15 08 PM
FayCarsons commented 10 months ago

I refactored this to remove the typing issues, and labeled the colors in the palette. I still think there's probably a better way to do this, currently it doesn't really use the library for anything except rendering, but I'm not super sure what the solution is.