forked from mdn/js-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
41 lines (36 loc) · 1.27 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import colors from './modules/getColors.js';
import { Canvas } from './modules/canvas.js';
let circleBtn = document.querySelector('.circle');
let squareBtn = document.querySelector('.square');
let triangleBtn = document.querySelector('.triangle');
// create the canvas and reporting list
let myCanvas = new Canvas('myCanvas', document.body, 480, 320);
myCanvas.create();
myCanvas.createReportList();
// draw a square
squareBtn.addEventListener('click', () => {
import('./modules/square.js').then((Module) => {
let square1 = new Module.Square(myCanvas.ctx, myCanvas.listId, 50, 50, 100, colors.blue);
square1.draw();
square1.reportArea();
square1.reportPerimeter();
})
});
// draw a circle
circleBtn.addEventListener('click', () => {
import('./modules/circle.js').then((Module) => {
let circle1 = new Module.Circle(myCanvas.ctx, myCanvas.listId, 75, 200, 100, colors.green);
circle1.draw();
circle1.reportArea();
circle1.reportPerimeter();
})
});
// draw a triangle
triangleBtn.addEventListener('click', () => {
import('./modules/triangle.js').then((Module) => {
let triangle1 = new Module.Triangle(myCanvas.ctx, myCanvas.listId, 100, 75, 190, colors.yellow);
triangle1.draw();
triangle1.reportArea();
triangle1.reportPerimeter();
})
});