|
@@ -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$ and $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$.
|
|
60
|
+* When we want to insert two-dimensional data (like the entries of a grid that has coordinates in $$x$$ and $$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,15 +69,15 @@ 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)` // 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 of $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 of $$y$$.
|
75
|
75
|
|
76
|
76
|
In addition, you will need to use the function that paints the grid:
|
77
|
77
|
|
78
|
|
-* `void switchOn(int x, int y, const QColor& color);` // Paints the cell $(x,y)$ with the given color. (You don't have to worry about `QColor` because it is passed by the function's parameter)
|
|
78
|
+* `void switchOn(int x, int y, const QColor& color);` // Paints the cell $$(x,y)$$ with the given color. (You don't have to worry about `QColor` because it is passed by the function's parameter)
|
79
|
79
|
|
80
|
|
-Although the archive `tools.cpp` is not visible, there is an array called `mColors`that contains the color of all the cells in the grid. This will help you know which color is in the cell: `mColors[columns * y + x]`. Note that the index of the array is calculated using the conversion explained above that changes the coordinates $(x,y)$ to an index.
|
|
80
|
+Although the archive `tools.cpp` is not visible, there is an array called `mColors`that contains the color of all the cells in the grid. This will help you know which color is in the cell: `mColors[columns * y + x]`. Note that the index of the array is calculated using the conversion explained above that changes the coordinates $$(x,y)$$ to an index.
|
81
|
81
|
|
82
|
82
|
---
|
83
|
83
|
|
|
@@ -172,7 +172,7 @@ Now, you will implement the functionality to draw squares, circles and triangles
|
172
|
172
|
|
173
|
173
|
#### 2a: Squares
|
174
|
174
|
|
175
|
|
-For the squares, the easiest way to think of it is as if they were onions! A square of size 1 is simply the cell clicked by the user. A square of size 2 is the cell clicked by the user, covered by a layer of cells of size 1, and so on. In other words, a square of size $n$ will have height = width = $2n-1$.
|
|
175
|
+For the squares, the easiest way to think of it is as if they were onions! A square of size 1 is simply the cell clicked by the user. A square of size 2 is the cell clicked by the user, covered by a layer of cells of size 1, and so on. In other words, a square of size $$n$$ will have height = width = $$2n-1$$.
|
176
|
176
|
|
177
|
177
|
|
178
|
178
|
|
|
@@ -182,7 +182,7 @@ For the squares, the easiest way to think of it is as if they were onions! A squ
|
182
|
182
|
|
183
|
183
|
#### 2b: Triangles
|
184
|
184
|
|
185
|
|
-The triangle button produces an **isosceles** triangle as it is shown in Figure 7. For a selected size $n$, the size of the base will be $2n + 1$. The height should be $n+1$.
|
|
185
|
+The triangle button produces an **isosceles** triangle as it is shown in Figure 7. For a selected size $$n$$, the size of the base will be $$2n + 1$$. The height should be $n+1$.
|
186
|
186
|
|
187
|
187
|
|
188
|
188
|
![](images/triangles.png)
|
|
@@ -201,9 +201,9 @@ Congratulations! You got to the most difficult part: circles! Here you’ll need
|
201
|
201
|
|
202
|
202
|
**Help Producing Circles:**
|
203
|
203
|
|
204
|
|
-First of all, you need to understand that the terms associated with a circle that has an equation: $x^2+y^2=r^2$. For example, consider a circle with radius $r=1$. The equation $x^2+y^2=1$ tells us that every point $(x,y)$ that satisfies the equation is a point in the circle’s *circumference*. The expression for a *filled* circle is : $x^2 + y^2 <=r^2$. A filled circle, of radius $r=1$ has the expression $x^2 + y^2 <= 1$, which says that every point $(x,y)$ that satisfies $x^2 + y^2 <= 1$ is a point in a filled circle.
|
|
204
|
+First of all, you need to understand that the terms associated with a circle that has an equation: $$x^2+y^2=r^2$$. For example, consider a circle with radius $$r=1$$. The equation $$x^2+y^2=1$$ tells us that every point $$(x,y)$$ that satisfies the equation is a point in the circle’s *circumference*. The expression for a *filled* circle is : $$x^2 + y^2 <=r^2$$. A filled circle, of radius $$r=1$$ has the expression $$x^2 + y^2 <= 1$$, which says that every point $$(x,y)$$ that satisfies $$x^2 + y^2 <= 1$$ is a point in a filled circle.
|
205
|
205
|
|
206
|
|
-How do we produce a circle? One way would be to generate all the points near the center of the circle and determine if those satisfy the expression $x^2 + y^2 <= r^2$. For example, we can try all of the points that are in the square of size $2r+1$. For the circle of radius $r=2$ we would have to generate the following points and prove them in the expression $x^2 + y^2 <=4$:
|
|
206
|
+How do we produce a circle? One way would be to generate all the points near the center of the circle and determine if those satisfy the expression $$x^2 + y^2 <= r^2$$. For example, we can try all of the points that are in the square of size $$2r+1$$. For the circle of radius $$r=2$$ we would have to generate the following points and prove them in the expression $$x^2 + y^2 <=4$$:
|
207
|
207
|
|
208
|
208
|
|
209
|
209
|
````
|
|
@@ -214,7 +214,7 @@ How do we produce a circle? One way would be to generate all the points near the
|
214
|
214
|
(-2,-2) (-1,-2) ( 0,-2) ( 1,-2) ( 2,-2)
|
215
|
215
|
````
|
216
|
216
|
|
217
|
|
-In this case, only the points that are shown below satisfy the expression $x^2 + y^2 <=4$.
|
|
217
|
+In this case, only the points that are shown below satisfy the expression $$x^2 + y^2 <=4$$.
|
218
|
218
|
|
219
|
219
|
|
220
|
220
|
````
|