Skip to content

Commit 4e30d7b

Browse files
committed
stage 1
1 parent e65ea47 commit 4e30d7b

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

stages/index.js

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
'use strict';
22
/**
3-
* We can describe a rectangle in terms of five
4-
* properies: the x and y position of its top left
5-
* corner, its width, its height and its colour.
6-
*
7-
* We create five variables for these properties.
8-
*
9-
* We draw the rectangle, move it, and then draw it again.
3+
* If we want a _second_ rectangle (and simultaneously being
4+
* deliberately naïve) we might just create five additional
5+
* variables and duplicate our drawing code.
106
*/
117

128
// create five variables
13-
const rectX = 100;
14-
const rectY = 50;
15-
const rectWidth = 100;
16-
const rectHeight = 200;
17-
const rectCol = 'crimson';
9+
const rect1x = 100;
10+
const rect1y = 50;
11+
const rect1width = 100;
12+
const rect1height = 200;
13+
const rect1col = 'crimson';
14+
15+
// create another five variables
16+
const rect2x = 300;
17+
const rect2y = 150;
18+
const rect2width = 100;
19+
const rect2height = 200;
20+
const rect2col = 'steelblue';
1821

1922
// get a handle on the drawing canvas
2023
const ctx = document.querySelector('canvas').getContext('2d');
2124

2225
// draw the rectangle
23-
ctx.fillStyle = rectCol;
24-
ctx.fillRect(rectX, rectY, rectWidth, rectHeight);
26+
ctx.fillStyle = rect1col;
27+
ctx.fillRect(rect1x, rect1y, rect1width, rect1height);
28+
29+
// draw it in the new position, with a different colour
30+
ctx.fillStyle = rect2col;
31+
ctx.fillRect(rect2x, rect2y, rect2width, rect2height);

0 commit comments

Comments
 (0)