You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: js/lesson6/tutorial.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ var context = canvas.getContext('2d');
34
34
35
35
### Controls
36
36
37
-
Depending on if we are filling up a shape, or just drawing the outline, we can use `fillStyle` or `strokeStyle`to set the color of the element.
37
+
Depending on if we are filling up a shape, or just drawing the outline, we can use `context.fillStyle` or `context.strokeStyle`to set the color of the element.
38
38
39
39
```js
40
40
context.fillStyle='yellow';
@@ -44,7 +44,7 @@ Depending on if we are filling up a shape, or just drawing the outline, we can u
44
44
To set the line width:
45
45
46
46
```js
47
-
context.lineWidth='3';
47
+
context.lineWidth=3;
48
48
```
49
49
50
50
#### Drawing
@@ -68,7 +68,7 @@ Now let's add another rectangle, but this time only its outline.
68
68
context.strokeRect(300, 100, 50, 100);
69
69
```
70
70
71
-
**Bonus** Add a new rectangle outline with dimensions **120x150** at the bottom right of the screen. The **line width** of the rectangle should be 1.
71
+
**Bonus** Add a new rectangle outline with dimensions **120x150** at the bottom right of the canvas. The **line width** of the rectangle should be 1.
72
72
73
73
### Reseting canvas
74
74
@@ -91,7 +91,7 @@ context.moveTo(0,300);
91
91
context.lineTo(400,500);
92
92
```
93
93
94
-
This won't do anything until we call the `stroke()`, which deals with the painting.
94
+
This won't do anything until we call `context.stroke()`, which deals with the painting.
95
95
96
96
You can also draw an join multiple paths together. Try this out by creating a rectangle with corners at (0, 0), (0, 200), (200, 300) and (200, 0).
97
97
@@ -112,7 +112,7 @@ context.stroke();
112
112
113
113
## Drawing circles
114
114
115
-
To draw circles, you can use the `arc` method. `arc(x, y, radius, staging_angle, endingAngle, counterClockwise)`
115
+
To draw circles, you can use the `arc` method. `arc(x, y, radius, startAngle, endAngle, counterClockwise)`. Angles are expressed in radians. In radians 2π equates to 360°.
116
116
117
117
```javascript
118
118
context.beginPath();
@@ -122,7 +122,7 @@ context.lineWidth = 4;
122
122
context.stroke();
123
123
```
124
124
125
-
To fill in the circle, or any other joined elements, we use the `fill()` method after closing the path.
125
+
To fill in the circle, or any other joined elements, we use the `context.fill()` method after closing the path.
126
126
127
127
**Exercise** Create another circle and fill it with the color blue.
128
128
@@ -132,7 +132,7 @@ In canvas, we can also use transformations on the current matrix.
132
132
133
133
### `rotate()`
134
134
135
-
First add the rotate method at the bottom of the `draw()`method.
135
+
First add the rotate method at the bottom of the `draw()`function.
136
136
137
137
```javascript
138
138
context.rotate(10*Math.PI/180);
@@ -152,15 +152,15 @@ context.restore()
152
152
153
153
### `translate()`
154
154
155
-
Translate moves the current position. If we are at 10, 10 and we `translate(20, 15)`, then our new position is 30, 45.
155
+
Translate moves the current position. If we are at 10, 10 and we `context.translate(20, 15)`, then our new position is 30, 45.
156
156
157
157
```javascript
158
158
context.translate(45, 45);
159
159
```
160
160
161
161
### `scale()`
162
162
163
-
And finally, `scale(scaleWidth, scalewHeight)`. Scale changes the dimensions of the rendered items.
163
+
And finally, `context.scale(scaleWidth, scaleHeight)`. Scale changes the dimensions of the rendered items.
164
164
165
165
166
166
```javascript
@@ -182,7 +182,7 @@ We have already created the functions to draw the individual parts, so you shoul
182
182
> Use pen and paper to think about the position of each element. You already know that the top left is 0,0 and the bottom right 400, 500. Use a grid if you are finding it hard.
183
183
184
184
185
-
> Don't forget `beginPath()` and `stroke()` before and after drawing elements.
185
+
> Don't forget `context.beginPath()` and `context.stroke()` before and after drawing elements.
186
186
187
187
Here is our version of [Hangman in Canvas](../../examples/hangman-canvas/index.html).
0 commit comments