home/ atoms/ recursive-fractal-code

Recursive fractal structures are coded as objects that instantiate child copies of themselves

To code a fractal in Processing: define a class (e.g., Branch) that includes an array of children of the same type. In the constructor, after computing the object’s own geometry, check if level < maxLevels; if so, create numChildren new instances of the same class (passing the current endpoint as their start point and level+1). Drawing propagates recursively: drawMe() draws itself then calls drawMe() on each child. updateMe() similarly trickles down to children. Two key guards: (1) a depth limit (if level < maxLevels) prevents infinite recursion; (2) exponential growth awareness — each additional child or level multiplies the count geometrically, so push parameters up gradually.

Examples

Branch constructor: if (level < _maxLevels) { children = new Branch[_numChildren]; for (int i=0; i<_numChildren; i++) { children[i] = new Branch(level+1, i, endx, endy); } } drawMe() ends with: for (int i=0; i<children.length; i++) { children[i].drawMe(); }

Assessment

Given a fractal class where each branch creates 3 children up to 4 levels: what happens to frame rate if you change to 5 children and 6 levels? Calculate the object count for each configuration.

“Adding 3 levels, each with 3 children, is the equivalent of 3 3 , which means 27 objects. Add 1 more child, and it becomes 3 4 , which is 81 objects.”
corpus · generative-art-a-practical-guide-using-processing-matt-pears · chunk 35