Reputation: 504
Im doing an art project where i really need to be able to divide a rectangle in a random way. Ive have been searching alot for this but have not found anything i really can implement in proccesing. The idea is after, reading this thread Break up a square or rectangle into a large number of randomly sized squares or rectangles to use a KD-tree or an divide conquer algorithm. I only just learned how a basic Binary Tree works so im a bit lost how to implement this in proccesing code.
Upvotes: 0
Views: 878
Reputation: 3810
This (p5js) sketch divides a rectangular plane in random sized smaller rectangles and seems suitable for your need.
The sketch slices (either horizontally or vertically) the plane recursively until a "slice limit" is reached for each recursive call, upon which a rectangle is returned.
I ported the sketch from js to Java Processing here. In fact, it can be easily called from the parent project (PGS) with:
PShape division = PGS_Tiling.rectSubdivsion(double width, double height, int maxDepth);
Upvotes: 2