Courses‎ > ‎Introduction to Computer Science 1‎ > ‎Konstantinovich‎ > ‎ML1 9/2012‎ > ‎labs‎ > ‎

Lab 07 : Tree

posted Nov 27, 2012, 8:44 AM by Samuel Konstantinovich   [ updated Dec 21, 2012, 5:26 AM ]
1. Basic tree (Should be finished by 11/27 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.

2. Advanced tree. We will discuss this tomorrow at the start of class, then you have time to work on it (11/28)
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. So you can do things like:
2a) 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)

3) 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 judge them at a later date. Your goal should be to make a somewhat organic looking tree, no to make a bunch of rainbow turtles. 
Comments