2014-12-01 Tree Lab

posted Dec 1, 2014, 5:15 AM by Samuel Konstantinovich   [ updated Mar 16, 2017, 5:59 AM ]
GOAL: To Tree

(Diagrams from class are required for these lecture notes, please get notes from other people if you missed class)


1. Basic tree (Should be finished at home if you have issues in class)
Write a turtle context function tree n 
*-It makes a size n fractal tree. The angle should be constant (it can be a slider) and the branch size should be constant (it can be a slider also)

Hints:
-There is NO REPEAT command inside the tree command.
-When you define tree you use brackets:
to tree[n]
  ...
end

-When you CALL tree, you don't put brackets:
tree 5
tree x + 1
tree n - 2
etc.

2a. Advanced tree. We will discuss this tomorrow at the start of class, then you have time to work on it 
Write a turtle context function BetterTree n angle branch.

You can still use a slider, but it should be for the STARTING angle and STARTING branch value:
You could have sliders TREE_SIZE BRANCH_ANGLE BRANCH_SIZE
you could have a button:    
   BetterTree TREE_SIZE BRANCH_ANGLE BRANCH_SIZE

Hints:
*-Multiple parameters are in the same brackets:   to betterTree [n angle branch]
*-Make sure you call BetterTree inside your function, not your old tree.
*-You can change the value of the angle and branch as you use recursion just like  you change n by calling tree n-1.

2b) Make the branch size decrease every time you call tree.  
2b) Make the angle change (smaller or bigger) every time you call the tree.
*-Example of decaying /random :
      betterTree n - 1 angle + random 3 - random 3 branch * .75
*-Parenthesis are not requred for this but you can use them to help you read the code:
      betterTree (n - 1)  (angle + random 3 - random 3)  (branch * .75)

EXTRA CREDIT Due Monday: Make the coolest looking tree function you can. I will compare them in class and choose the coolest looking ones. (My opinion judges) You can work on them at home, I will give you until Monday. Your goal could be to make a somewhat organic looking tree, or to make a really complex but very viewable tree. Don't just make rainbows... Also don't just copy my Sakura tree with the falling leaves. You can animate this.
Comments