In this lab, you will use recursion to generate a tendron. A tendron has a cluster of 7 tendrils. At the end of each tendril is a cluster of 7 smaller tendrils. This pattern of clusters of tendrils repeats until the tendrils reach a minimum tendril length. You can think of this as a slightly more complex Fractal tree. Instead of 2 branches in a v shape, there are 7 tendrils that radiate in all directions. Instead of straight branches, the tendrils wiggle randomly left and right as they radiate outward.
Your code will draw the Tendron recursively, modifying the structure as the elements get smaller, going through smaller tendrils and clusters. Every time the draw() function runs, it generates a new and different Tendron since growth occurs randomly.
The main program, Tendron.pde, sets up the size() and background(). Then when draw() is called, it creates a new tendron by calling the constructor of the Cluster class, telling it to create a cluster of tendrils starting at the midpoint of the screen with each tendril using 50 short segments.
The cluster of seven tendrils each randomly turn a bit left or right as they move out from the center. At the end of each tendril the new cluster will have fewer line segments, therefore each tendril will be shorter than before. Recursively, these tendrils will again spawn clusters until a minimum tendril length is reached. Here is the final result:
When drawn, the tendrils together look very plant-like for such a simple algorithm. The effect is enhanced by using the tendril length to determine the stroke used when drawing.
-
Fork and clone down this repository
-
Complete the
Tendrilclass constructor -
Write code in the
Clusterclass constructor to make onenew Tendril()with the same initial number of segments and starting (x,y) coordinates. Give the tendril a random angle between 0 and 2π. Then call the tendril'sshow()function. We'll add more tendrils to the cluster later. -
Complete the
Tendrilclassshow()function which does the actual drawing. Theshowmethod draws the tendril using only the two Processing functionslineandstroke. In drawing the tendril, we will wiggle the direction with a random walk (similar to the Lightning assignment) for a life-like appearance. Here's one way to randomly wiggle the line:- declare
startXand initialize it tomyX - declare
startYand initialize it tomyY - repeat
myNumSegmentstimes- Change
myAngleby adding a random decimal from -0.2 to 0.2 - declare
endXand initialize it tostartXplus the cosine ofmyAngletimes the segment length - declare
endYand initialize it tostartYplus the sine ofmyAngletimes the segment length - draw a line from (
startX,startY) to (endX,endY) - Set
startXtoendX - Set
startYtoendY
- Change
- declare
-
Run your program. You should see one random tendril every time you click the screen

-
Now go back to the
Clusterconstructor and modify it to make 7 Tendrils. You may want to evenly space each tendril's angle so that is a multiple of 2π/7. -
In the Tendril
show()add code that recursively creates a newClusterat the end of each Tendril ifmyNumSegmentsis greater than or equal to the minimum tendril length (3 is a good choice) -
Add code at the beginning of the tendril
show()function to change thestroke()based on the length of the tendril.
The instructions above are only a suggestion. Have fun and be creative. Your Tendron doesn't have to look like any other.
None yet!
Note: this assignment was adapted from Roger Frank's APCS assignment
