Tuesday, February 27, 2018

Circles and Quads


(play here)

Circles and Quads is my implementation of the random-tile algorithm by Paul Bourke. I wrote this in the free time waiting for the plane at SF airport back in 2015.. *yeah.

My version of the algorithm is simple:

1. Randomly choose the position of first object
2. If the oobject does collide with any other objects in the scene - move it's position
3. Repeat 2. If it is repeated more than 300 times (it is a free parameter) decrease the diameter and proceed to 4.
4. Repeat decrease / randomize position / decrease / loop forever.

(I noticed that sometimes I use the modified version of the algorithm in which I first find a proper place for the small object and then multiply its size in order to find its maximum size for which it doesn't collide with any other - it works very similar)

This way we obtain nicely looking pictures of fractal-like style. They are built of non-overlapping objects of any shapes (I used circles and rectangles but we are not limited to those). See my variations below. Sometimes I change the code sligtly to get some of these results, I'll try to put some comments.


You may find an interactive HTML5 app of this i.e. on my website for kids felp.pl here and more directly here. Also browse my homepage for more things like that.


  









Above I just changed the boundary conditions in which the packing is generated.

We've got some phase separation in the above figure.


Just circles.

Not all of those results are available in the application that I prepared for release, I have more, unpublished code on it, just let me know if you like to get it for any reason.

No comments:

Post a Comment

Soda Constructor (Revisited)