-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
107 lines (106 loc) · 3.5 KB
/
Copy pathapp.js
File metadata and controls
107 lines (106 loc) · 3.5 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Generated by Haxe 4.0.0-rc.3
(function ($global) { "use strict";
var App = function(size,circleSize,strokeStyle,speed,clockwise) {
if(clockwise == null) {
clockwise = true;
}
if(speed == null) {
speed = 1.0;
}
if(strokeStyle == null) {
strokeStyle = "#000";
}
if(circleSize == null) {
circleSize = 16;
}
this.clockwise = true;
this.circleSize = 16;
this.speed = 1.0;
this.size = size;
this.circleSize = circleSize;
this.speed = speed;
this.clockwise = clockwise;
this.height = size / 2 * Math.sqrt(3) | 0;
var _g = [];
_g.push({ x : 0, y : 0});
_g.push({ x : 0, y : 0});
_g.push({ x : 0, y : 0});
_g.push({ x : 0, y : 0});
_g.push({ x : 0, y : 0});
_g.push({ x : 0, y : 0});
this.points = _g;
this.rotation = 0.0;
this.offsetX = 0;
this.offsetY = circleSize;
this.canvas = window.document.createElement("canvas");
this.canvas.width = size;
this.canvas.height = size;
this.context = this.canvas.getContext("2d",null);
this.context.strokeStyle = strokeStyle;
};
App.step = function(time) {
window.requestAnimationFrame(App.step);
App.tetroid.update();
App.tetroid.draw();
};
App.main = function() {
window.onload = function(_) {
App.tetroid = new App(300,14,"#fff");
window.document.body.appendChild(App.tetroid.canvas);
window.requestAnimationFrame(App.step);
window.document.body.onclick = function(_1) {
App.tetroid.clockwise = !App.tetroid.clockwise;
};
};
};
App.prototype = {
update: function() {
var rad = this.rotation * Math.PI / 180;
var rot = rad;
this.points[0].x = Math.cos(rot) * this.circleSize;
this.points[0].y = Math.sin(rot) * this.circleSize;
rot = rad + Math.PI * 2 / 3;
this.points[2].x = Math.cos(rot) * this.circleSize + this.size - this.circleSize * 2;
this.points[2].y = Math.sin(rot) * this.circleSize;
rot = rad + Math.PI * 2 / 3 * 2;
this.points[4].x = Math.cos(rot) * this.circleSize + this.size / 2;
this.points[4].y = Math.sin(rot) * this.circleSize + this.height - this.circleSize;
this.points[1].x = -this.points[0].x;
this.points[1].y = -this.points[0].y;
rot = rad + Math.PI * 2 / 3;
this.points[3].x = -Math.cos(rot) * this.circleSize + this.size - this.circleSize * 2;
this.points[3].y = -Math.sin(rot) * this.circleSize;
rot = rad + Math.PI * 2 / 3 * 2;
this.points[5].x = -Math.cos(rot) * this.circleSize + this.size / 2;
this.points[5].y = -Math.sin(rot) * this.circleSize + this.height - this.circleSize;
}
,draw: function() {
this.context.clearRect(0,0,window.innerWidth,window.innerHeight);
this.context.save();
this.context.translate(this.circleSize,this.circleSize);
this.context.beginPath();
this.context.moveTo(this.offsetX + this.points[0].x,this.offsetY + this.points[0].y);
this.context.lineTo(this.offsetX + this.points[2].x,this.offsetY + this.points[2].y);
this.context.lineTo(this.offsetX + this.points[4].x,this.offsetY + this.points[4].y);
this.context.lineTo(this.offsetX + this.points[1].x,this.offsetY + this.points[1].y);
this.context.lineTo(this.offsetX + this.points[3].x,this.offsetY + this.points[3].y);
this.context.lineTo(this.offsetX + this.points[5].x,this.offsetY + this.points[5].y);
this.context.lineTo(this.offsetX + this.points[0].x,this.offsetY + this.points[0].y);
this.context.stroke();
this.context.restore();
if(this.clockwise) {
this.rotation += this.speed;
if(this.rotation >= 360) {
this.rotation = 0;
}
} else {
this.rotation -= this.speed;
if(this.rotation <= 0) {
this.rotation = 360;
}
}
}
};
App.main();
})({});
//# sourceMappingURL=app.js.map