-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (24 loc) · 744 Bytes
/
script.js
File metadata and controls
29 lines (24 loc) · 744 Bytes
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
var canvas = document.getElementById("canvas");
/* Component settings inside the canvas */
var x;
var y;
var width;
var height;
var component1, component2;
function draw_component1(){
x = 50, y = 25, width = 40, height = 40;
component1 = canvas.getContext("2d");
component1.fillRect(x, y, width, height);
canvas.setAttribute("onclick","draw_component2();");
}
function draw_component2(){
x = 50, y = 160, width = 40, height = 40;
component2 = canvas.getContext("2d");
component2.fillStyle = "green";
component2.fillRect(x, y, width, height);
canvas.setAttribute("onclick","clean();");
}
function clean(){
canvas.width = canvas.width;
canvas.setAttribute("onclick","draw_component1();");
}