-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (52 loc) · 1.14 KB
/
script.js
File metadata and controls
70 lines (52 loc) · 1.14 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//https://webdoli.tistory.com/24 참고하고 있음
function box(){
this.x = 0;
this.y = 0;
this.width = 50;
this.height = 50;
}
function rand(min, max){
return Math.round(Math.random() * (max - min + 1) - min);
}
function init(){
window.canvas = document.getElementById('game');
window.display = window.canvas.getContext('2d');
window.maxX = canvas.width;
window.maxY = canvas.height;
window.w = 10;
window.h = 10;
window.nowX = 0;
window.nowY = 0;
window.boxTotal = 523;
window.trigger = 0;
loop();
}
function color(){
const result = 'rgba(' + rand(0,255) + ',' + rand(0,255) + ',' + rand(0,255) + ',' + '1)';
return result;
}
function draw(){
display.clearRect(0, 0, maxX, maxY)
display.fillStyle = 'blue';
display.fillRect(0, 0, maxX, maxY);
if(trigger == 1){
for(let i = 0; i < boxTotal; i++){
display.fillStyle = color();
nowX = rand(0, maxX);
nowY = rand(0, maxY);
w = rand(0, maxX - nowX);
h = rand(0, maxY - nowY);
display.fillRect(nowX, nowY, w, h);
}
}
}
function loop(){
draw();
requestAnimationFrame(loop);
}
function change(){
trigger = 1;
}
function end(){
trigger = 0;
}