|
@@ -6,7 +6,8 @@
|
6
|
6
|
|
7
|
7
|
[Verano 2016 - Ive - Coralys]
|
8
|
8
|
|
9
|
|
-One commonly used programming technique is *recursion*. With this technique, problems are solved by solving similar problems, but for smaller cases. We can construct sets of objects or tasks using *recursive rules* and *initial values*. *Recursive functions* are functions that are self-invoking, using smaller sets or elements each time, until reaching a point where the initial value is used instead of self-invoking. Fractals are an example of figures that can be created using recursion. In this laboratory experience, you will practice the definition and implementation of recursive functions to draw self-similar objects (fractals).
|
|
9
|
+One commonly used programming technique is *recursion*. With this technique, problems are solved by solving similar problems, but for smaller cases. We can build sets of objects or tasks using *recursive rules* and *initial values*. *Recursive functions* are functions that are self-invoking, using smaller sets or elements each time, until reaching a point where the initial value is used instead of self-invoking. Fractals are an example of figures that can be created using recursion. In this laboratory experience, you will practice the definition and implementation of recursive functions to draw self-similar objects (fractals).
|
|
10
|
+
|
10
|
11
|
|
11
|
12
|
The exercises in this laboratory experience are an adaptation of https://sites.google.com/a/wellesley.edu/wellesley-cs118-spring13/lectures-labs/lab-6-turtle-recursion.
|
12
|
13
|
|
|
@@ -52,6 +53,7 @@ One ingenious way of practicing and visualizing recursion is programming functio
|
52
|
53
|
---
|
53
|
54
|
|
54
|
55
|
Can you see the recursive behavior in this figure? Notice that `branch(0,90)` is only a vertical segment (a segment in an angle of 90 degrees); `branch(1,90)` is `branch(0,90)` with two segments inclined in its top. More precisely, `branch(1,90)` is `branch(0,90)` with a `branch(0,60)` and a `branch(0,120)` in its top. Similarly, `branch(2,90)` is `branch(0,90)` with two `branch(1,90)` inclined in the top. That is, `branch(2,90)` is:
|
|
56
|
+
|
55
|
57
|
`branch(0,90)` with a `branch(1,60)` and a `branch(1,120)` in its top. Notice that $$60=90-30$$ and $$120=90+30$$.
|
56
|
58
|
|
57
|
59
|
This way we can express `branch(n,A)` as a composition of branches with $$n$$ smaller and inclined branches. Code 1 provides a way of expressing `branch` as a recursive function.
|
|
@@ -149,7 +151,7 @@ The `boxes` recursive function includes three parameters: `sideLength`, `shrinkF
|
149
|
151
|
|
150
|
152
|
## Deliverables
|
151
|
153
|
|
152
|
|
-1. Use "Deliverables" in Moodle to upload the `boxes.cpp` and `main.cpp` files. Remember to use good programming techniques, include the names of the programmers involved, and to document your program.
|
|
154
|
+1. Use "Deliverables" in Moodle to upload the `boxes.cpp` and `main.cpp` files. Remember to use good programming techniques, include the names of the programmers involved, and document your program.
|
153
|
155
|
|
154
|
156
|
|
155
|
157
|
---
|
|
@@ -166,4 +168,4 @@ The `boxes` recursive function includes three parameters: `sideLength`, `shrinkF
|
166
|
168
|
|
167
|
169
|
[4] http://www.coolmath.com/fractals/images/fractal5.gif
|
168
|
170
|
|
169
|
|
-[5] "Fractal tree (Plate b - 2)". Licensed under Public domain via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Fractal_tree_(Plate_b_-_2).jpg#mediaviewer/File:Fractal_tree_(Plate_b_-_2).jpg
|
|
171
|
+[5] "Fractal tree (Plate b - 2)". Licensed under Public domain via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Fractal_tree_(Plate_b_-_2).jpg#mediaviewer/File:Fractal_tree_(Plate_b_-_2).jpg
|