Browse Source

Splitted READMEs

Luis Albertorio 8 years ago
parent
commit
feee1f96d7
3 changed files with 344 additions and 344 deletions
  1. 165
    0
      README-en.md
  2. 177
    0
      README-es.md
  3. 2
    344
      README.md

+ 165
- 0
README-en.md View File

@@ -0,0 +1,165 @@
1
+
2
+#Recursion - Recursive Shapes
3
+
4
+![main1.jpg](images/main1.jpg)
5
+![main2.jpg](images/main2.jpg)
6
+![main3.png](images/main3.png)
7
+
8
+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 an 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
+
10
+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.
11
+
12
+##Objectives:
13
+
14
+1. Practice the definition and implementation of recursive functions.
15
+
16
+
17
+
18
+##Pre-Lab:
19
+
20
+Before coming to the laboratory session you should have:
21
+
22
+1. Reviewed the basic concepts related to recursive functions.
23
+
24
+2. Studied the `box` function to draw boxes, included in the `boxes.cpp` file in the `Qt` project.
25
+
26
+3. Studied the concepts and instructions related to the laboratory session.
27
+
28
+4. Taken the Pre-Lab quiz available through the course’s Moodle portal.
29
+
30
+---
31
+
32
+---
33
+
34
+
35
+##Self-similar forms
36
+
37
+![figure2.png](images/figure2.png)
38
+
39
+**Figure 2.** Fractal tree [5].
40
+
41
+---
42
+
43
+One ingenious way of practicing and visualize recursion is programming functions that produce recursive figures, or fractals. For example, consider a recursive figure that we'll call *branch*. Figure 3 shows `branch(0,90)`, `branch(1,90)`, and `branch(2,90)`.
44
+
45
+---
46
+
47
+![figure3.jpg](images/figure3.jpg)
48
+
49
+**Figure 3.** (a) `branch(0,90)`, (b) `branch(1,90)`, y (c) `branch(2,90)`. 
50
+
51
+---
52
+
53
+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:
54
+`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$$.
55
+
56
+This way we can express `branch(n,A)` as a composition of branches with smaller inclined $$n$$'s. Code 1 provides a way of expressing `branch` as a recursive function.
57
+
58
+---
59
+
60
+```
61
+branch(0, A) = draws a segment of length L and angle A
62
+branch(n, A) = draws: branch(0,A), branch(n-1,A-30), branch(n-1,A+30)
63
+```
64
+
65
+**Code 1.** Function to draw branches.
66
+
67
+---
68
+
69
+Notice that the recursive definition includes a base case, that is, includes `branch(0,A)`, and a recurrence relation, that is, `branch(n,A)`. To simplify, we assume that `branch(n-1,A-30)` and `branch(n-1,A+30)` are drawn at the top of `branch(0,A)`.
70
+
71
+Figure 4 illustrates the recursive expansion for `branch(2,90)`. The color of each expression is the corresponding segment color in the figure.
72
+
73
+---
74
+
75
+![figure4.jpg](images/figure4.jpg)
76
+
77
+**Figure 4.** Illustration for `branch(2,90)`.
78
+
79
+---
80
+ 
81
+Can you predict how the next iteration for the figure will look? That is, what figure will `branch(3,A)` produce?
82
+
83
+---
84
+
85
+---
86
+
87
+##Laboratory Session
88
+
89
+In today's laboratory experience you will implement recursive functions to produce fractals.
90
+
91
+###Exercise 1: Snowflake
92
+
93
+One of the simplest fractal figures is the snowflake. This figure is formed by an isosceles triangle, substituting the middle third segment on each side by an inverted "V". The measurements of each side of the "V" is equal to the measurements of the segment it substitutes. We will use the snowflake to illustrate the process of recursion.
94
+
95
+---
96
+
97
+![figure5.png](images/figure5.png)
98
+
99
+**Figure 5.** Part of the construction of the snowflake fractal.
100
+
101
+---
102
+
103
+####Instructions
104
+
105
+1. Load the project `RecursiveShapes` onto `QtCreator` by double clicking on the `RecursiveShapes.pro` file in the `Documents/eip/Recursion-RecursiveShapes` folder of your computer. You may also go to `http://bitbucket.org/eip-uprrp/recursion-recursiveshapes` to download the `Recursion-RecursiveShapes` folder to your computer.
106
+
107
+2. Compile and run the program so you see a snowflake figure constructed with 3 iterations of the `snowflake` function. You can see the code of this function in the `snowflake.cpp` file of the `Qt` project.
108
+
109
+In the `main` function, look up the line where the variable `level` is declared and given a value. Change the value of `level` to `0` and run the program. You'll be able to see the triangle that represents the recursive base case for the snowflake. Continue changing the value for `level` and running the program so you can see the recursion process and produce self-similar figures.
110
+
111
+
112
+###Exercise 2: Self-similar boxes
113
+
114
+In this exercise, your task is to program a recursive function `boxes`, in the file `boxes.cpp`, that produces the following figures.
115
+
116
+---
117
+
118
+![figure6.jpg](images/figure6.jpg)
119
+
120
+**Figure 6.** Illustration of the box figures that your program should produce.
121
+
122
+---
123
+
124
+The `boxes` recursive function includes three parameters: `sideLength`, `shrinkFactor`, and `smallestLength`.
125
+
126
+* `sideLength`: an integer that determines the length of the sides of the largest box.
127
+* `shrinkFactor`: a real number that determines the rate of the next level of boxes. For example, if `sideLength` is `100`, and `shrinkFactor` is `0.3`, the length of the sides of the largest box will be `100` units, and the length of the sides of the smallest box will be `100*.3=30` units. Four copies of that smaller box are placed within the previous box, **one box in each corner**.
128
+* `smallestLength`: is an integer that determines the length of the sides of the smallest box that will be drawn. For example, in Figure 6, `boxes(400,0.4,200)` only draws the box with sides of length `400`, since the size that will follow will be `400 * 0.4 = 160`, which is smaller than `200`. On the other hand, `boxes(400, 0.4, 75)` draws the box of size `400` and the boxes with size `160`, but not the following ones in size, since they would be of size `160 * 0.4 = 64`, which is less than `75`.
129
+
130
+####Instructions
131
+
132
+1. Study the `box` function included in the `boxes.cpp` file. This function receives as arguments the coordinates of the upper left corner, the length of the sides and the color of the box. The function draws a box with these specifications. 
133
+
134
+2. Write a recursive algorithm for the `boxes` function described above. Remember to include the base case! The algorithm should also invoke the `box` function to draw the boxes.
135
+
136
+3. Implement the function in `QtCreator`. You will need to provide additional parameters to your function so you can control the position and the color of the squares.
137
+
138
+4. Invoke the `boxes` function from the `main` function in the `main.cpp` file. Compare your results with the images in Figure 6.
139
+
140
+
141
+
142
+---
143
+
144
+---
145
+
146
+##Deliverables
147
+
148
+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.
149
+
150
+
151
+---
152
+
153
+---
154
+
155
+##References
156
+
157
+[1] https://sites.google.com/a/wellesley.edu/wellesley-cs118-spring13/lectures-labs/lab-6-turtle-recursion.
158
+
159
+[2] "Mandel zoom 00 mandelbrot set". Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Mandel_zoom_00_mandelbrot_set.jpg#mediaviewer/File:Mandel_zoom_00_mandelbrot_set.jpg
160
+
161
+[3] "Mandel zoom 04 seehorse tail". Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Mandel_zoom_04_seehorse_tail.jpg#mediaviewer/File:Mandel_zoom_04_seehorse_tail.jpg
162
+
163
+[4] http://www.coolmath.com/fractals/images/fractal5.gif
164
+
165
+[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

+ 177
- 0
README-es.md View File

@@ -0,0 +1,177 @@
1
+
2
+#Recursión - Figuras Recursivas
3
+
4
+![main1.jpg](images/main1.jpg)
5
+![main2.jpg](images/main2.jpg)
6
+![main3.png](images/main3.png)
7
+
8
+
9
+Una técnica muy utilizada en programación es la *recursión*. Con esta técnica se resuelven problemas resolviendo un problema similar pero para casos más pequeños. Podemos construir conjuntos de objetos o procesos utilizando *reglas recursivas* y *valores iniciales*. Las *funciones recursivas* son funciones que se auto-invocan, utilizando cada vez conjuntos o elementos más pequeños,  hasta llegar a un punto en donde se utiliza el valor inicial en lugar de auto-invocarse. Los fractales son un ejemplo de figuras que se pueden crear usando recursión. En esta experiencia de laboratorio practicarás la definición e implementación de funciones recursivas para dibujar formas auto-similares (fractales).
10
+
11
+Los ejercicios de esta experiencia de laboratorio son una adaptación de https://sites.google.com/a/wellesley.edu/wellesley-cs118-spring13/lectures-labs/lab-6-turtle-recursion.
12
+
13
+
14
+##Objetivos:
15
+
16
+1. Practicar el definir e implementar funciones recursivas.
17
+
18
+
19
+##Pre-Lab:
20
+
21
+Antes de llegar al laboratorio debes haber:
22
+
23
+1. Repasado los conceptos relacionados a funciones recursivas.
24
+
25
+2. Estudiado la función `box` para dibujar cajas, incluida en el archivo `boxes.cpp` del proyecto de `Qt`.
26
+
27
+3. Haber estudiado los conceptos e instrucciones para la sesión de laboratorio.
28
+
29
+4. Haber tomado el quiz Pre-Lab que se encuentra en Moodle.
30
+
31
+---
32
+
33
+---
34
+
35
+
36
+
37
+## Figuras auto-similares
38
+
39
+![figure2.png](images/figure2.png)
40
+
41
+**Figura 2.** Árbol fractal [5].
42
+
43
+---
44
+
45
+
46
+
47
+Una manera ingeniosa de practicar y "visualizar" recursión es programando funciones que produzcan figuras auto-similares (o recursivas). Por ejemplo, considera una figura recursiva que llamaremos *rama*. La Figura 3 muestra `rama(0,90)`, `rama(1,90)` y `rama(2,90)`.
48
+
49
+---
50
+
51
+![figure3.jpg](images/figure3.jpg)
52
+
53
+**Figura 3.** (a) `rama(0,90)`, (b) `rama(1,90)`, y (c) `rama(2,90)`. 
54
+
55
+---
56
+
57
+¿Puedes ver el comportamiento recursivo de esta figura? Nota que `rama(0,90)` es solo un segmento vertical (un segmento en un ángulo de 90 grados); `rama(1,90)` es `rama(0,90)` con dos segmentos inclinados en  su extremo superior. Más preciso, `rama(1,90)` es `rama(0,90)` con una  `rama(0,60)` y una `rama(0,120)` en el extremo superior. Similarmente, `rama(2,90)` es `rama(0,90)`  con dos `rama(1,90)` inclinadas en el extremo superior. Esto es,  `rama(2,90)` es:
58
+`rama(0,90)` con una `rama(1,60)` y una `rama(1,120)` en el extremo superior. Nota que $$60=90-30$$ y que $$120=90+30$$.
59
+
60
+De esta manera podemos expresar `rama(n,A)` como una composición de ramas con $$n$$'s más pequeñas inclinadas. El Código 1 provee una manera de expresar `rama` como una función recursiva.
61
+
62
+---
63
+
64
+```
65
+rama(0, A) = dibuja un segmento de largo L en un ángulo A
66
+rama(n, A) = dibuja: rama(0,A), rama(n-1, A-30), rama(n-1, A+30)
67
+```
68
+
69
+**Código 1.** Función para dibujar las ramas.
70
+
71
+---
72
+
73
+Nota que la definición recursiva incluye un caso base, esto es, incluye `rama(0,A)`, y una relación de recurrencia (o caso recursivo), esto es, `rama(n,A)`. Para simplificar, asumimos que  `rama(n-1,A-30)` y `rama(n-1,A+30)` se dibujan en el extremo superior de `rama(0,A)`.
74
+
75
+La Figura 4 ilustra la expansión recursiva para `rama(2,90)`. El color de cada expresión es el color del segmento que le corresponde en la figura.
76
+
77
+---
78
+
79
+![figure4.jpg](images/figure4.jpg)
80
+
81
+**Figura 4.** Ilustración de `rama(2,90)`.
82
+
83
+---
84
+ 
85
+¿Puedes predecir cómo será la próxima iteración de la figura? Es decir, ¿qué figura producirá `rama(3,A)`?
86
+
87
+---
88
+
89
+---
90
+
91
+## Sesión de laboratorio
92
+
93
+En la experiencia de laboratorio de hoy implementarás  funciones recursivas para producir fractales.
94
+
95
+###Ejercicio 1: Copo de nieve
96
+
97
+Una de las figuras fractales más simples es la figura de un copo de nieve. Esta figura se forma a partir de un triángulo isósceles, sustituyendo el segmento del tercio del medio de cada lado por una "V" invertida. La medida de los lados de la "V" es igual a la medida del segmento que sustituye. Usaremos el copo de nieve para ilustrar el proceso de recursión.
98
+
99
+---
100
+
101
+![figure5.png](images/figure5.png)
102
+
103
+**Figura 5.** Parte de la construcción del fractal "copo de nieve".
104
+
105
+---
106
+
107
+####Instrucciones
108
+
109
+1. Carga a QtCreator el proyecto `RecursiveShapes`  haciendo doble "click" en el archivo `RecursiveShapes.pro` en el directorio `Documents/eip/Recursion-RecursiveShapes` de tu computadora. También puedes ir a `http://bitbucket.org/eip-uprrp/recursion-recursiveshapes` para descargar la carpeta `Recursion-RecursiveShapes` a tu computadora.
110
+ 
111
+2. Compila y corre el programa para que veas una figura del copo de nieve construida con 3 iteraciones de la función `snowflake`. Puedes ver el código que define esta función en el archivo `snowflake.cpp` del proyecto de `Qt`.
112
+
113
+    En la función `main`, busca la línea en donde se declara y dá valor a la variable `level`. Cambia el valor de `level` a `0` y corre el programa de nuevo. Podrás ver el triángulo que representa el caso base de la recursión para el copo de nieve. Continúa cambiando el valor de la variable `level` y corriendo el programa para que veas el proceso de la recursión y de producir figuras auto-similares.
114
+
115
+
116
+###Ejercicio 2: Cajas autosimilares
117
+
118
+Tu tarea en este ejercicio es programar una función recursiva `boxes`, en el archivo `boxes.cpp`, que produzca las siguientes figuras. 
119
+
120
+---
121
+
122
+![figure6.jpg](images/figure6.jpg)
123
+
124
+**Figura 6.** Ilustración de las figuras de cajas que debe producir tu programa.
125
+
126
+---
127
+
128
+La función recursiva `boxes` incluye tres parámetros: `sideLength`, `shrinkFactor`, y `smallestLength`.
129
+
130
+* `sideLength`: un entero que determina el largo de los lados del cuadrado más grande.
131
+* `shrinkFactor`: un número real que determina la razón del siguiente nivel de cuadrados. Por ejemplo, si `sideLength` es `100`, y `shrinkFactor` es `0.3`, el largo de los lados del cuadrado más grande será `100` unidades, y el largo de los lados del próximo cuadrado más pequeño  será `100*.3=30` unidades. Se colocan 4 copias de ese cuadrado más pequeño dentro del cuadrado anterior, **un cuadrado en cada esquina**.
132
+* `smallestLength`: es un valor entero que determina el largo del lado del cuadrado más pequeño que será dibujado. Por ejemplo, en la Figura 6, `boxes(400, 0.4, 200)` solo dibuja el cuadrado con lados de largo `400`, ya que el tamaño que le seguiría sería `400 * 0.4 = 160`, que es más pequeño que `200`. Por otro lado, `boxes(400, 0.4, 75)` dibuja el cuadrado de tamaño `400` y los cuadrados de tamaño `160`, pero no los siguientes en tamaño, porque serían de tamaño `160 * 0.4 = 64`, que es menor que `75`.
133
+
134
+####Instrucciones
135
+
136
+1. Estudia la función `box` incluida en el archivo `boxes.cpp`. Esta función recibe como argumentos las coordenadas de la esquina superior izquierda, el largo de los lados y el color de una caja. La función dibuja una caja con esas especificaciones.
137
+
138
+2. Escribe un algoritmo recursivo para la función `boxes` descrita arriba. ¡Recuerda incluir el caso base! El algoritmo también debe invocar la función `box` para dibujar las cajas. 
139
+
140
+3. Implementa la función en `QtCreator`. Necesitarás proveer parámetros adicionales a tu función para que puedas controlar la posición y el color de los cuadrados. 
141
+
142
+4. Invoca la función `boxes` desde la función main en el archivo `main.cpp`. Compara tus resultados con las imágenes de la Figura 6.
143
+
144
+
145
+---
146
+
147
+---
148
+
149
+##Entrega
150
+
151
+Utiliza "Entrega" en Moodle para entregar los archivos `boxes.cpp` y `main.cpp`. Recuerda utilizar buenas prácticas de programación, incluir el nombre de los programadores y documentar tu programa.
152
+
153
+
154
+---
155
+
156
+---
157
+
158
+
159
+## Referencias
160
+
161
+[1] https://sites.google.com/a/wellesley.edu/wellesley-cs118-spring13/lectures-labs/lab-6-turtle-recursion.
162
+
163
+[2] "Mandel zoom 00 mandelbrot set". Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Mandel_zoom_00_mandelbrot_set.jpg#mediaviewer/File:Mandel_zoom_00_mandelbrot_set.jpg
164
+
165
+[3] "Mandel zoom 04 seehorse tail". Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Mandel_zoom_04_seehorse_tail.jpg#mediaviewer/File:Mandel_zoom_04_seehorse_tail.jpg
166
+
167
+[4] http://www.coolmath.com/fractals/images/fractal5.gif
168
+
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
170
+
171
+---
172
+
173
+---
174
+
175
+---
176
+
177
+

+ 2
- 344
README.md View File

@@ -1,344 +1,2 @@
1
-[English](#markdown-header-recursion-recursive-shapes) | [Español](#markdown-header-recursion-figuras-recursivas)
2
-
3
-#Recursión - Figuras Recursivas
4
-
5
-![main1.jpg](images/main1.jpg)
6
-![main2.jpg](images/main2.jpg)
7
-![main3.png](images/main3.png)
8
-
9
-
10
-Una técnica muy utilizada en programación es la *recursión*. Con esta técnica se resuelven problemas resolviendo un problema similar pero para casos más pequeños. Podemos construir conjuntos de objetos o procesos utilizando *reglas recursivas* y *valores iniciales*. Las *funciones recursivas* son funciones que se auto-invocan, utilizando cada vez conjuntos o elementos más pequeños,  hasta llegar a un punto en donde se utiliza el valor inicial en lugar de auto-invocarse. Los fractales son un ejemplo de figuras que se pueden crear usando recursión. En esta experiencia de laboratorio practicarás la definición e implementación de funciones recursivas para dibujar formas auto-similares (fractales).
11
-
12
-Los ejercicios de esta experiencia de laboratorio son una adaptación de https://sites.google.com/a/wellesley.edu/wellesley-cs118-spring13/lectures-labs/lab-6-turtle-recursion.
13
-
14
-
15
-##Objetivos:
16
-
17
-1. Practicar el definir e implementar funciones recursivas.
18
-
19
-
20
-##Pre-Lab:
21
-
22
-Antes de llegar al laboratorio debes haber:
23
-
24
-1. Repasado los conceptos relacionados a funciones recursivas.
25
-
26
-2. Estudiado la función `box` para dibujar cajas, incluida en el archivo `boxes.cpp` del proyecto de `Qt`.
27
-
28
-3. Haber estudiado los conceptos e instrucciones para la sesión de laboratorio.
29
-
30
-4. Haber tomado el quiz Pre-Lab que se encuentra en Moodle.
31
-
32
----
33
-
34
----
35
-
36
-
37
-
38
-## Figuras auto-similares
39
-
40
-![figure2.png](images/figure2.png)
41
-
42
-**Figura 2.** Árbol fractal [5].
43
-
44
----
45
-
46
-
47
-
48
-Una manera ingeniosa de practicar y "visualizar" recursión es programando funciones que produzcan figuras auto-similares (o recursivas). Por ejemplo, considera una figura recursiva que llamaremos *rama*. La Figura 3 muestra `rama(0,90)`, `rama(1,90)` y `rama(2,90)`.
49
-
50
----
51
-
52
-![figure3.jpg](images/figure3.jpg)
53
-
54
-**Figura 3.** (a) `rama(0,90)`, (b) `rama(1,90)`, y (c) `rama(2,90)`. 
55
-
56
----
57
-
58
-¿Puedes ver el comportamiento recursivo de esta figura? Nota que `rama(0,90)` es solo un segmento vertical (un segmento en un ángulo de 90 grados); `rama(1,90)` es `rama(0,90)` con dos segmentos inclinados en  su extremo superior. Más preciso, `rama(1,90)` es `rama(0,90)` con una  `rama(0,60)` y una `rama(0,120)` en el extremo superior. Similarmente, `rama(2,90)` es `rama(0,90)`  con dos `rama(1,90)` inclinadas en el extremo superior. Esto es,  `rama(2,90)` es:
59
-`rama(0,90)` con una `rama(1,60)` y una `rama(1,120)` en el extremo superior. Nota que $$60=90-30$$ y que $$120=90+30$$.
60
-
61
-De esta manera podemos expresar `rama(n,A)` como una composición de ramas con $$n$$'s más pequeñas inclinadas. El Código 1 provee una manera de expresar `rama` como una función recursiva.
62
-
63
----
64
-
65
-```
66
-rama(0, A) = dibuja un segmento de largo L en un ángulo A
67
-rama(n, A) = dibuja: rama(0,A), rama(n-1, A-30), rama(n-1, A+30)
68
-```
69
-
70
-**Código 1.** Función para dibujar las ramas.
71
-
72
----
73
-
74
-Nota que la definición recursiva incluye un caso base, esto es, incluye `rama(0,A)`, y una relación de recurrencia (o caso recursivo), esto es, `rama(n,A)`. Para simplificar, asumimos que  `rama(n-1,A-30)` y `rama(n-1,A+30)` se dibujan en el extremo superior de `rama(0,A)`.
75
-
76
-La Figura 4 ilustra la expansión recursiva para `rama(2,90)`. El color de cada expresión es el color del segmento que le corresponde en la figura.
77
-
78
----
79
-
80
-![figure4.jpg](images/figure4.jpg)
81
-
82
-**Figura 4.** Ilustración de `rama(2,90)`.
83
-
84
----
85
- 
86
-¿Puedes predecir cómo será la próxima iteración de la figura? Es decir, ¿qué figura producirá `rama(3,A)`?
87
-
88
----
89
-
90
----
91
-
92
-## Sesión de laboratorio
93
-
94
-En la experiencia de laboratorio de hoy implementarás  funciones recursivas para producir fractales.
95
-
96
-###Ejercicio 1: Copo de nieve
97
-
98
-Una de las figuras fractales más simples es la figura de un copo de nieve. Esta figura se forma a partir de un triángulo isósceles, sustituyendo el segmento del tercio del medio de cada lado por una "V" invertida. La medida de los lados de la "V" es igual a la medida del segmento que sustituye. Usaremos el copo de nieve para ilustrar el proceso de recursión.
99
-
100
----
101
-
102
-![figure5.png](images/figure5.png)
103
-
104
-**Figura 5.** Parte de la construcción del fractal "copo de nieve".
105
-
106
----
107
-
108
-####Instrucciones
109
-
110
-1. Carga a QtCreator el proyecto `RecursiveShapes`  haciendo doble "click" en el archivo `RecursiveShapes.pro` en el directorio `Documents/eip/Recursion-RecursiveShapes` de tu computadora. También puedes ir a `http://bitbucket.org/eip-uprrp/recursion-recursiveshapes` para descargar la carpeta `Recursion-RecursiveShapes` a tu computadora.
111
- 
112
-2. Compila y corre el programa para que veas una figura del copo de nieve construida con 3 iteraciones de la función `snowflake`. Puedes ver el código que define esta función en el archivo `snowflake.cpp` del proyecto de `Qt`.
113
-
114
-    En la función `main`, busca la línea en donde se declara y dá valor a la variable `level`. Cambia el valor de `level` a `0` y corre el programa de nuevo. Podrás ver el triángulo que representa el caso base de la recursión para el copo de nieve. Continúa cambiando el valor de la variable `level` y corriendo el programa para que veas el proceso de la recursión y de producir figuras auto-similares.
115
-
116
-
117
-###Ejercicio 2: Cajas autosimilares
118
-
119
-Tu tarea en este ejercicio es programar una función recursiva `boxes`, en el archivo `boxes.cpp`, que produzca las siguientes figuras. 
120
-
121
----
122
-
123
-![figure6.jpg](images/figure6.jpg)
124
-
125
-**Figura 6.** Ilustración de las figuras de cajas que debe producir tu programa.
126
-
127
----
128
-
129
-La función recursiva `boxes` incluye tres parámetros: `sideLength`, `shrinkFactor`, y `smallestLength`.
130
-
131
-* `sideLength`: un entero que determina el largo de los lados del cuadrado más grande.
132
-* `shrinkFactor`: un número real que determina la razón del siguiente nivel de cuadrados. Por ejemplo, si `sideLength` es `100`, y `shrinkFactor` es `0.3`, el largo de los lados del cuadrado más grande será `100` unidades, y el largo de los lados del próximo cuadrado más pequeño  será `100*.3=30` unidades. Se colocan 4 copias de ese cuadrado más pequeño dentro del cuadrado anterior, **un cuadrado en cada esquina**.
133
-* `smallestLength`: es un valor entero que determina el largo del lado del cuadrado más pequeño que será dibujado. Por ejemplo, en la Figura 6, `boxes(400, 0.4, 200)` solo dibuja el cuadrado con lados de largo `400`, ya que el tamaño que le seguiría sería `400 * 0.4 = 160`, que es más pequeño que `200`. Por otro lado, `boxes(400, 0.4, 75)` dibuja el cuadrado de tamaño `400` y los cuadrados de tamaño `160`, pero no los siguientes en tamaño, porque serían de tamaño `160 * 0.4 = 64`, que es menor que `75`.
134
-
135
-####Instrucciones
136
-
137
-1. Estudia la función `box` incluida en el archivo `boxes.cpp`. Esta función recibe como argumentos las coordenadas de la esquina superior izquierda, el largo de los lados y el color de una caja. La función dibuja una caja con esas especificaciones.
138
-
139
-2. Escribe un algoritmo recursivo para la función `boxes` descrita arriba. ¡Recuerda incluir el caso base! El algoritmo también debe invocar la función `box` para dibujar las cajas. 
140
-
141
-3. Implementa la función en `QtCreator`. Necesitarás proveer parámetros adicionales a tu función para que puedas controlar la posición y el color de los cuadrados. 
142
-
143
-4. Invoca la función `boxes` desde la función main en el archivo `main.cpp`. Compara tus resultados con las imágenes de la Figura 6.
144
-
145
-
146
----
147
-
148
----
149
-
150
-##Entrega
151
-
152
-Utiliza "Entrega" en Moodle para entregar los archivos `boxes.cpp` y `main.cpp`. Recuerda utilizar buenas prácticas de programación, incluir el nombre de los programadores y documentar tu programa.
153
-
154
-
155
----
156
-
157
----
158
-
159
-
160
-## Referencias
161
-
162
-[1] https://sites.google.com/a/wellesley.edu/wellesley-cs118-spring13/lectures-labs/lab-6-turtle-recursion.
163
-
164
-[2] "Mandel zoom 00 mandelbrot set". Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Mandel_zoom_00_mandelbrot_set.jpg#mediaviewer/File:Mandel_zoom_00_mandelbrot_set.jpg
165
-
166
-[3] "Mandel zoom 04 seehorse tail". Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Mandel_zoom_04_seehorse_tail.jpg#mediaviewer/File:Mandel_zoom_04_seehorse_tail.jpg
167
-
168
-[4] http://www.coolmath.com/fractals/images/fractal5.gif
169
-
170
-[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
-
172
----
173
-
174
----
175
-
176
----
177
-
178
-
179
-[English](#markdown-header-recursion-recursive-shapes) | [Español](#markdown-header-recursion-figuras-recursivas)
180
-
181
-#Recursion - Recursive Shapes
182
-
183
-![main1.jpg](images/main1.jpg)
184
-![main2.jpg](images/main2.jpg)
185
-![main3.png](images/main3.png)
186
-
187
-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 an 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). 
188
-
189
-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.
190
-
191
-##Objectives:
192
-
193
-1. Practice the definition and implementation of recursive functions.
194
-
195
-
196
-
197
-##Pre-Lab:
198
-
199
-Before coming to the laboratory session you should have:
200
-
201
-1. Reviewed the basic concepts related to recursive functions.
202
-
203
-2. Studied the `box` function to draw boxes, included in the `boxes.cpp` file in the `Qt` project.
204
-
205
-3. Studied the concepts and instructions related to the laboratory session.
206
-
207
-4. Taken the Pre-Lab quiz available through the course’s Moodle portal.
208
-
209
----
210
-
211
----
212
-
213
-
214
-##Self-similar forms
215
-
216
-![figure2.png](images/figure2.png)
217
-
218
-**Figure 2.** Fractal tree [5].
219
-
220
----
221
-
222
-One ingenious way of practicing and visualize recursion is programming functions that produce recursive figures, or fractals. For example, consider a recursive figure that we'll call *branch*. Figure 3 shows `branch(0,90)`, `branch(1,90)`, and `branch(2,90)`.
223
-
224
----
225
-
226
-![figure3.jpg](images/figure3.jpg)
227
-
228
-**Figure 3.** (a) `branch(0,90)`, (b) `branch(1,90)`, y (c) `branch(2,90)`. 
229
-
230
----
231
-
232
-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:
233
-`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$$.
234
-
235
-This way we can express `branch(n,A)` as a composition of branches with smaller inclined $$n$$'s. Code 1 provides a way of expressing `branch` as a recursive function.
236
-
237
----
238
-
239
-```
240
-branch(0, A) = draws a segment of length L and angle A
241
-branch(n, A) = draws: branch(0,A), branch(n-1,A-30), branch(n-1,A+30)
242
-```
243
-
244
-**Code 1.** Function to draw branches.
245
-
246
----
247
-
248
-Notice that the recursive definition includes a base case, that is, includes `branch(0,A)`, and a recurrence relation, that is, `branch(n,A)`. To simplify, we assume that `branch(n-1,A-30)` and `branch(n-1,A+30)` are drawn at the top of `branch(0,A)`.
249
-
250
-Figure 4 illustrates the recursive expansion for `branch(2,90)`. The color of each expression is the corresponding segment color in the figure.
251
-
252
----
253
-
254
-![figure4.jpg](images/figure4.jpg)
255
-
256
-**Figure 4.** Illustration for `branch(2,90)`.
257
-
258
----
259
- 
260
-Can you predict how the next iteration for the figure will look? That is, what figure will `branch(3,A)` produce?
261
-
262
----
263
-
264
----
265
-
266
-##Laboratory Session
267
-
268
-In today's laboratory experience you will implement recursive functions to produce fractals.
269
-
270
-###Exercise 1: Snowflake
271
-
272
-One of the simplest fractal figures is the snowflake. This figure is formed by an isosceles triangle, substituting the middle third segment on each side by an inverted "V". The measurements of each side of the "V" is equal to the measurements of the segment it substitutes. We will use the snowflake to illustrate the process of recursion.
273
-
274
----
275
-
276
-![figure5.png](images/figure5.png)
277
-
278
-**Figure 5.** Part of the construction of the snowflake fractal.
279
-
280
----
281
-
282
-####Instructions
283
-
284
-1. Load the project `RecursiveShapes` onto `QtCreator` by double clicking on the `RecursiveShapes.pro` file in the `Documents/eip/Recursion-RecursiveShapes` folder of your computer. You may also go to `http://bitbucket.org/eip-uprrp/recursion-recursiveshapes` to download the `Recursion-RecursiveShapes` folder to your computer.
285
-
286
-2. Compile and run the program so you see a snowflake figure constructed with 3 iterations of the `snowflake` function. You can see the code of this function in the `snowflake.cpp` file of the `Qt` project.
287
-
288
-In the `main` function, look up the line where the variable `level` is declared and given a value. Change the value of `level` to `0` and run the program. You'll be able to see the triangle that represents the recursive base case for the snowflake. Continue changing the value for `level` and running the program so you can see the recursion process and produce self-similar figures.
289
-
290
-
291
-###Exercise 2: Self-similar boxes
292
-
293
-In this exercise, your task is to program a recursive function `boxes`, in the file `boxes.cpp`, that produces the following figures.
294
-
295
----
296
-
297
-![figure6.jpg](images/figure6.jpg)
298
-
299
-**Figure 6.** Illustration of the box figures that your program should produce.
300
-
301
----
302
-
303
-The `boxes` recursive function includes three parameters: `sideLength`, `shrinkFactor`, and `smallestLength`.
304
-
305
-* `sideLength`: an integer that determines the length of the sides of the largest box.
306
-* `shrinkFactor`: a real number that determines the rate of the next level of boxes. For example, if `sideLength` is `100`, and `shrinkFactor` is `0.3`, the length of the sides of the largest box will be `100` units, and the length of the sides of the smallest box will be `100*.3=30` units. Four copies of that smaller box are placed within the previous box, **one box in each corner**.
307
-* `smallestLength`: is an integer that determines the length of the sides of the smallest box that will be drawn. For example, in Figure 6, `boxes(400,0.4,200)` only draws the box with sides of length `400`, since the size that will follow will be `400 * 0.4 = 160`, which is smaller than `200`. On the other hand, `boxes(400, 0.4, 75)` draws the box of size `400` and the boxes with size `160`, but not the following ones in size, since they would be of size `160 * 0.4 = 64`, which is less than `75`.
308
-
309
-####Instructions
310
-
311
-1. Study the `box` function included in the `boxes.cpp` file. This function receives as arguments the coordinates of the upper left corner, the length of the sides and the color of the box. The function draws a box with these specifications. 
312
-
313
-2. Write a recursive algorithm for the `boxes` function described above. Remember to include the base case! The algorithm should also invoke the `box` function to draw the boxes.
314
-
315
-3. Implement the function in `QtCreator`. You will need to provide additional parameters to your function so you can control the position and the color of the squares.
316
-
317
-4. Invoke the `boxes` function from the `main` function in the `main.cpp` file. Compare your results with the images in Figure 6.
318
-
319
-
320
-
321
----
322
-
323
----
324
-
325
-##Deliverables
326
-
327
-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.
328
-
329
-
330
----
331
-
332
----
333
-
334
-##References
335
-
336
-[1] https://sites.google.com/a/wellesley.edu/wellesley-cs118-spring13/lectures-labs/lab-6-turtle-recursion.
337
-
338
-[2] "Mandel zoom 00 mandelbrot set". Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Mandel_zoom_00_mandelbrot_set.jpg#mediaviewer/File:Mandel_zoom_00_mandelbrot_set.jpg
339
-
340
-[3] "Mandel zoom 04 seehorse tail". Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:Mandel_zoom_04_seehorse_tail.jpg#mediaviewer/File:Mandel_zoom_04_seehorse_tail.jpg
341
-
342
-[4] http://www.coolmath.com/fractals/images/fractal5.gif
343
-
344
-[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
1
+## [\[English\]](README-en.md) - for README in English
2
+## [\[Spanish\]](README-es.md) - for README in Spanish