|
@@ -6,7 +6,7 @@
|
6
|
6
|
|
7
|
7
|
[Version Verano 2016- Tatiana]
|
8
|
8
|
|
9
|
|
-Recursion is a technique that is commonly used in programming. 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. In this laboratory experience, you will implement some tools to draw and practice the use of recursive functions to fill with color some figures.
|
|
9
|
+Recursion is a technique that is commonly used in programming. With this technique, problems are done 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. In this laboratory experience, you will implement some tools to draw and practice the use of recursive functions to fill with color some figures.
|
10
|
10
|
|
11
|
11
|
|
12
|
12
|
## Objectives:
|
|
@@ -36,11 +36,11 @@ Before arriving at the laboratory you should have:
|
36
|
36
|
## Drawing Applications
|
37
|
37
|
|
38
|
38
|
|
39
|
|
-Probably many Windows OS users (if not all of them) have used the program called *Paint*, that is a simple drawing application. In that program, like many other drawing programs, there are several tools (for example: the pencil, the paint bucket and the line) that lets the user draw on the area in different ways.
|
|
39
|
+Probably many Windows OS users (if not all of them) have used the program called *Paint*, which is a simple drawing application. In that program, like many other drawing programs, there are several tools (for example: the pencil, the paint bucket and the line) that lets the user draw on the area in different ways.
|
40
|
40
|
|
41
|
|
-In this laboratory experience, we will make the some tools (square, circle, triangle, some special lines) work ... don't worry!, we will do it in a very simple way.
|
|
41
|
+In this laboratory experience, we will make some tools (square, circle, triangle, some special lines) work ... don't worry!, we will do it in a very simple way.
|
42
|
42
|
|
43
|
|
-The drawing will be on a grid. The tools will be used by clicking any cell in the grid and, from that point, the necessary cells to make the figure will be painted. For example, if we choose the vertical line tool and we click the cell in position *(2,3)*, a vertical line will be drawn in all of the cells in column 2. That is, all of the cells in position $(2,y)$ will be marked for all of the $y$ in the grid.
|
|
43
|
+The drawing will be on a grid. The tools will be used by clicking any cell in the grid and, from that point, the necessary cells that make the figure will be painted. For example, if we choose the vertical line tool and we click the cell in position *(2,3)*, a vertical line will be drawn in all of the cells in column 2. That is, all of the cells in position $(2,y)$ will be marked for all of the $y$ in the grid.
|
44
|
44
|
|
45
|
45
|
|
46
|
46
|
---
|
|
@@ -57,7 +57,7 @@ The drawing will be on a grid. The tools will be used by clicking any cell in th
|
57
|
57
|
**Figure 1.** The image shows the direction in which the coordinates are ordered in `Qt` images.
|
58
|
58
|
|
59
|
59
|
|
60
|
|
-* When we want to insert two-dimensional data (like the entries of a grid that has coordinates in $x$ y $y$) in a one-dimensional array we use a formula to convert every coordinate $(x,y)$ to an index $i$ of the array. For every point with coordinates $(x,y)$ in the grid, we evaluate $i=(number-of-columns)*y+x$, where `number-of-columns` represents the width of the two-dimensional array, and the result $i$ will be the index of the one-dimensional array that corresponds to the point with coordinates $(x,y)$ in the grid. For example, the index $i$ that corresponds to the point $(1,2)$ in the grid of width $5$ is $i=(5)*2+1=11$.
|
|
60
|
+* When we want to insert two-dimensional data (like the entries of a grid that has coordinates in $x$ y $y$) in an one-dimensional array we use a formula to convert every coordinate $(x,y)$ to an index $i$ of the array. For every point with coordinates $(x,y)$ in the grid, we evaluate $i=(number-of-columns)*y+x$, where `number-of-columns` represents the width of the two-dimensional array, and the result $i$ will be the index of the one-dimensional array that corresponds to the point with coordinates $(x,y)$ in the grid. For example, the index $i$ that corresponds to the point $(1,2)$ in the grid of width $5$ is $i=(5)*2+1=11$.
|
61
|
61
|
|
62
|
62
|
|
63
|
63
|
---
|
|
@@ -69,9 +69,9 @@ The drawing will be on a grid. The tools will be used by clicking any cell in th
|
69
|
69
|
|
70
|
70
|
In this project, you will need to use the following `QtGlobal` functions for the implementation of the circle.
|
71
|
71
|
|
72
|
|
-* `int qFloor(qreal v)` // Devuelve el "piso" del valor $v$.
|
73
|
|
-* `qreal qSqrt(qreal v)` // Devuelve la raíz cuadrada del valor $v$.
|
74
|
|
-* `qreal qPow(qreal x, qreal y)` // Devuelve el valor de $x$ elevado a la potencia $y$.
|
|
72
|
+* `int qFloor(qreal v)` // Returns the “floor” value $v$.
|
|
73
|
+* `qreal qSqrt(qreal v)` // Returns the square root of the value $v$.
|
|
74
|
+* `qreal qPow(qreal x, qreal y)` // Returns the value of $x$ to the power $y$.
|
75
|
75
|
|
76
|
76
|
In addition, you will need to use the function that paints the grid:
|
77
|
77
|
|
|
@@ -109,12 +109,12 @@ Although the archive `tools.cpp` is not visible, there is an array called `mColo
|
109
|
109
|
2. The project contains the skeleton for the application that draws lines and figures in a grid. The application has an interface that allows the user to select the color we want to draw with, the color of the background of the grid, the figure you want to draw (for example, the circle or the square) and the size of the figure. The selected figure is drawn when the user clicks a cell in the grid.
|
110
|
110
|
|
111
|
111
|
|
112
|
|
-You will be working with the archive called `tools.cpp`. Your first task is to implement the functions `RowMajorFill`, `ColMajorFill`, `DiagonalLeft` and `DiagonalRight` that make the buttons that draw lines work. The function `RowMajorFill` is already implemented for you to usea as an example. The functions should work as it is indicated below.
|
|
112
|
+You will be working with the archive called `tools.cpp`. Your first task is to implement the functions `RowMajorFill`, `ColMajorFill`, `DiagonalLeft` and `DiagonalRight` that make the buttons that draw lines work. The function `RowMajorFill` is already implemented for you to use as an example. The functions should work as indicated below.
|
113
|
113
|
|
114
|
114
|
|
115
|
115
|
##### `RowMajorFill`
|
116
|
116
|
|
117
|
|
-When you select the horizontal line figure in the interface, a horizontal line will be drawn on the grid on the row the user clicked. The line will expand to the right and left of the clicked cell until if finds a cell (pixel) with a different color as the background color, or until the grid ends. Figure2 illustrates this behavior.
|
|
117
|
+When you select the horizontal line figure in the interface, a horizontal line will be drawn on the grid on the row the user clicked. The line will expand to the right and left of the clicked cell until if finds a cell (pixel) with a different color as the background color, or until the grid ends. Figure 2 illustrates this behavior.
|
118
|
118
|
|
119
|
119
|
|
120
|
120
|
|
|
@@ -122,12 +122,12 @@ When you select the horizontal line figure in the interface, a horizontal line w
|
122
|
122
|
|---|----|----|
|
123
|
123
|
| ![](images/rowMajor01-small.png) | ![](images/rowMajor02-small.png) | ![](images/rowMajor03-small.png)|
|
124
|
124
|
|
125
|
|
-**Figure 2** - (a) A drawing with a with background with red dots. (b) When the user clicks on the horizontal line button (`RowMajorFill`) and clicks the cell shown, (c) a horizontal line that expands to the left and to the right of the cell clicked is drawn, until it finds a cell with a different color from the color of the background.
|
|
125
|
+**Figure 2** - (a) A drawing with a white background with red dots. (b) When the user clicks on the horizontal line button (`RowMajorFill`) and clicks the cell shown, (c) a horizontal line that expands to the left and to the right of the cell clicked is drawn, until it finds a cell with a different color from the color of the background.
|
126
|
126
|
|
127
|
127
|
|
128
|
128
|
##### `ColMajorFill`
|
129
|
129
|
|
130
|
|
-Esta función debe trabajar de manera similar a la función `RowMajorFill` pero para columnas. La Figura 3 ilustra su comportamiento.
|
|
130
|
+This function should work similarly as the function `RowMajorFill` but for columns. Figure 3 illustrates its behavior.
|
131
|
131
|
|
132
|
132
|
|
133
|
133
|
|
|
@@ -135,13 +135,12 @@ Esta función debe trabajar de manera similar a la función `RowMajorFill` pero
|
135
|
135
|
|---|----|----|
|
136
|
136
|
| ![](images/colMajor01-small.png) | ![](images/colMajor02-small.png) | ![](images/colMajor03-small.png)|
|
137
|
137
|
|
138
|
|
-**Figura 3** - (a) Un dibujo con trasfondo blanco y puntos rojos. (b) Cuando el usuario marca el botón de línea vertical (`ColMajorFill`) y marca la celda mostrada, (c) se dibuja una línea vertical que se expande hacia arriba y hacia abajo de la celda marcada, hasta que se encuantra una celda con un color diferente al color de trasfondo.
|
139
|
|
-
|
|
138
|
+**Figure 3** - (a) A drawing with a white background and red dots (b) When the user clicks on the vertical line button (`ColMajorFill`) and clicks the cell shown, (c) a vertical line that expands to the left and to the right of the cell clicked is drawn, until it finds a cell with a different color from the color of the background.
|
140
|
139
|
|
141
|
140
|
|
142
|
141
|
##### `DiagonalLeft`
|
143
|
142
|
|
144
|
|
-Esta función debe trabajar de manera similar a la función `RowMajorFill` pero produce una línea diagonal desde la izquierda superior hasta la derecha inferior. La Figura 4 ilustra su comportamiento.
|
|
143
|
+This function should work similarly as the `RowMajorFill` function but produces a diagonal line from the left superior corner to the right inferior corner. Figure 4 illustrates its behavior.
|
145
|
144
|
|
146
|
145
|
|
147
|
146
|
|
|
@@ -149,14 +148,13 @@ Esta función debe trabajar de manera similar a la función `RowMajorFill` pero
|
149
|
148
|
|---|----|----|
|
150
|
149
|
| ![](images/diagLeft00-small.png) | ![](images/diagLeft01-small.png) | ![](images/diagLeft02-small.png)|
|
151
|
150
|
|
152
|
|
-**Figura 4** - (a) Un dibujo con trasfondo blanco y puntos rojos. (b) Cuando el usuario marca el botón de línea diagonal izquierda (`DiagonalLeft`) y marca la celda mostrada, (c) se dibuja una línea diagonal izquierda que se expande hacia arriba a la izquierda y hacia abajo a la derecha de la celda marcada, hasta que se encuantra una celda con un color diferente al color de trasfondo.
|
|
151
|
+**Figure 4** - (a) A drawing with a white background and red dots. (b) When the user clicks on the left diagonal line button (`DiagonalLeft`) and clicks the cell shown, (c) a left diagonal line that expands towards the top to the left and towards the bottom to the right of the cell clicked is drawn, until it finds a cell with a different color from the color of the background.
|
153
|
152
|
|
154
|
153
|
|
155
|
154
|
|
156
|
155
|
##### `DiagonalRight`
|
157
|
156
|
|
158
|
|
-Esta función debe trabajar de manera similar a la función `DiagonalLeft` pero produce una línea diagonal desde la derecha superior hasta la izquierda inferior. La Figura 5 ilustra su comportamiento.
|
159
|
|
-
|
|
157
|
+This function should work similarly as the `DiagonalLeft` function but produce a diagonal line from the superior right corner to the inferior left corner. Figure 5 ilustrates its behavior.
|
160
|
158
|
|
161
|
159
|
|
162
|
160
|
| (a) | (b) | (c) |
|
|
@@ -164,10 +162,10 @@ Esta función debe trabajar de manera similar a la función `DiagonalLeft` pero
|
164
|
162
|
| ![](images/diagLeft00-small.png) | ![](images/diagLeft01-small.png) | ![](images/diagRight02-small.png)|
|
165
|
163
|
|
166
|
164
|
|
167
|
|
-**Figura 5** - (a) Un dibujo con trasfondo blanco y puntos rojos. (b) Cuando el usuario marca el botón de línea diagonal derecha (`DiagonalRight`) y marca la celda mostrada, (c) se dibuja una línea diagonal derecha que se expande hacia arriba a la derecha y hacia abajo a la izquierda de la celda marcada, hasta que se encuantra una celda con un color diferente al color de trasfondo.
|
|
165
|
+**Figure 5** - (a) A drawing with a white background and red dots. (b) When the user clicks on the right diagonal line button (`DiagonalRight`) and clicks the cell shown, (c) a right diagonal line that expands towards the top to the right and towards the bottom to the left of the cell clicked is drawn, until it finds a cell with a different color from the color of the background.
|
168
|
166
|
|
169
|
167
|
|
170
|
|
-### Ejercicio 2: Implementar las funciones para hacer funcionar los botones de dibujar cuadrados, triángulos y círculos.
|
|
168
|
+### Exercise 2: Implementar las funciones para hacer funcionar los botones de dibujar cuadrados, triángulos y círculos.
|
171
|
169
|
|
172
|
170
|
|
173
|
171
|
Ahora implementarás la funcionalidad para dibujar cuadrados, círculos y líneas. El **tamaño** de la figura dibujada dependerá del tamaño seleccionado con la barra deslizante en la interface.
|
|
@@ -293,3 +291,6 @@ Utiliza "Entrega" en Moodle para entregar el archivo `tools.cpp` con las funcion
|
293
|
291
|
|
294
|
292
|
|
295
|
293
|
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|