-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheart.html
More file actions
91 lines (84 loc) · 3.89 KB
/
heart.html
File metadata and controls
91 lines (84 loc) · 3.89 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Для выхода нажмите на экран</title>
</head>
<body onload="myGameArea.start()">
<canvas id="canvas" onclick='location.replace("index.html")'></canvas>
<script>
let myGamePiece = new Array();
var myGameArea = {
canvas: canvas,
start: function () {
this.canvas.width = (window.innerWidth);
this.canvas.height = window.innerHeight;
this.canvas.style = "z-index:1; background-color:rgb(168,198,192);position:absolute; top: 0px; left: 0px;";
this.context = this.canvas.getContext("2d");
this.interval = setInterval(updateGameArea, 17);
for (var g = 0; g < ((window.innerWidth) / 110 + (window.innerHeight / 95)) * 3; g++) {
myGamePiece[g] = new component();
}
},
clear: function () {
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
}
function component() {
function rand(max) {
return Math.floor(Math.random() * max)
};
this.updatecolor = function () {
this.c1 += this.c11;
if (this.c1 > 200 || this.c1 < 125) this.c11 = -this.c11;
this.c2 += this.c22;
if (this.c2 > 200 || this.c2 < 125) this.c22 = -this.c22;
this.c3 += this.c33;
if (this.c3 > 200 || this.c3 < 125) this.c33 = -this.c33;
};
this.c11 = 0.5;
this.c22 = 0.5;
this.c33 = 0.5;
this.c1 = rand(100)+150;
this.c2 = rand(100)+150;
this.c3 = rand(100)+150;
this.width = 110;
this.height = 95;
this.x = Math.floor(Math.random() * (myGameArea.canvas.width-150));
this.y = Math.floor(Math.random() * (myGameArea.canvas.height - 150));
this.xdir = Math.floor(Math.random() * 10) - 5;
this.ydir = Math.floor(Math.random() * 10) - 5;
this.update = function () {
ctx = myGameArea.context;
ctx.beginPath();
ctx.moveTo(75+this.x, 37+ this.y);
bezierCurveTo(75, 37, 70, 25, 50, 25, this.x, this.y);
bezierCurveTo(20, 25, 20, 62.5, 20, 62.5, this.x, this.y);
bezierCurveTo(20, 80, 40, 102, 75, 120, this.x, this.y);
bezierCurveTo(110, 102, 130, 80, 130, 62.5, this.x, this.y);
bezierCurveTo(130, 62.5, 130, 25, 100, 25, this.x, this.y);
bezierCurveTo(85, 25, 75, 37, 75, 40, this.x, this.y);
ctx.closePath();
ctx.fillStyle = "rgb(" + this.c1 + "," + this.c2 + "," + this.c3 + ")";
ctx.fill();
function bezierCurveTo(q, w, e, r, t, u, xx, yy) {
ctx.bezierCurveTo(q + xx, w + yy, e + xx, r + yy, t + xx, u + yy);
}
}
}
function bezierCurveTo(q, w, e, r, t, u, xx, yy) {
ctx.bezierCurveTo(q + xx, w + yy, e + xx, r + yy, t + xx, u + yy);
}
function updateGameArea() {
myGameArea.clear();
for (var g = 0; myGamePiece.length; g++)
{
myGamePiece[g].x += myGamePiece[g].xdir;
myGamePiece[g].y += myGamePiece[g].ydir;
if (myGamePiece[g].x+20 + myGamePiece[g].width >= myGameArea.canvas.width || myGamePiece[g].x+20 <= 0) { myGamePiece[g].xdir *= -1 }
if (myGamePiece[g].y + 25 + myGamePiece[g].height >= myGameArea.canvas.height || myGamePiece[g].y + 25 <= 0) { myGamePiece[g].ydir *= -1 }
myGamePiece[g].updatecolor();
myGamePiece[g].update();
}
}
</script>
</body>
</html>