-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.html
191 lines (185 loc) · 7.89 KB
/
start.html
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<style>
body,
canvas {
margin: 60px 0 0 300px;
padding: 0;
overflow: hidden;
position: fixed;
top: 0;
}
</style>
</head>
<body onload="init()">
<div id="msgboard">
<label><p>Reg polygon vertex count:<br/></p></label>
<input placeholder="" type="number" id="verticesCount" value="3"><br/>
<label><p>Radius(px) of regular polygon:<br/></p></label>
<input type="number" id="radius" value="300"><br/>
<label><p>The depth of the vortex:<br/></p></label>
<input type="number" id="depth" value="25"><br/>
<label><p>Ratio:<br/></p></label>
<input type="number" id="ratio" value="0.125"><br/>
<button id="creation">Create Vortex</button><br/>
<label><p>Save name:<br/></p></label>
<input type="text" id="savename"><button id="save">Save</button><br/>
<div id="savesboard"><ol></ol></div><br/>
<button id="rec">Record</button>
<button id="stop" style="display: none;">Stop Recording</button>
</div>
<canvas id="canvas-id" width="800" height="600">
<script>
if (endlessCanvas == undefined) {
var endlessCanvas = false;
}
var canvas = document.getElementById("canvas-id");
if (endlessCanvas) {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
window.onresize = function () {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
};
}
else {
canvas.width = 1000;
canvas.height = 800;
}
var context = canvas.getContext("2d");
context.fillStyle = "#0000ff";
// global variables with mouse coordinates
var mouseX = 0;
var mouseY = 0;
// some keycodes
var key_left = 37;
var key_up = 38;
var key_right = 39;
var key_down = 40;
var key_a = 65;
var key_z = 90;
var isKeyPressed = [];
for (i = 0; i < 256; ++i) {
isKeyPressed.push(0);
}
// gridSize = 50; // uncomment or add to game.js if you want a grid
var reqAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) {
setTimeout(callback, 1000 / 30);
};
function redraw() {
context.clearRect(0, 0, canvas.width, canvas.height);
context.globalAlpha = 1;
// draw grid
//context.fillStyle = "#FF0000";
context.font = "10px Arial";
if (typeof gridSize != "undefined" && gridSize >= 25) {
context.fillText(0, 4, 10);
context.beginPath();
for (i = gridSize; i < canvas.width; i += gridSize) {
context.moveTo(i, 0);
context.lineTo(i, canvas.height);
context.fillText(i, i + 4, 10);
}
for (i = gridSize; i < canvas.height; i += gridSize) {
context.moveTo(0, i);
context.lineTo(canvas.width, i);
context.fillText(i, 4, i + 10);
}
context.stroke();
}
draw(); // call progammer's draw() function
reqAnimationFrame(redraw);
};
function callupdate() {
update(); // call programmer's update() function
setTimeout(callupdate, 10); // and 10 ms after that ...
};
function areColliding(Ax, Ay, Awidth, Aheight, Bx, By, Bwidth, Bheight) {
if (Bx <= Ax + Awidth) {
if (Ax <= Bx + Bwidth) {
if (By <= Ay + Aheight) {
if (Ay <= By + Bheight) {
return 1;
}
}
}
}
return 0;
};
function init() {
if ('ontouchstart' in window || navigator.maxTouchPoints) {
isMobile = true;
window.addEventListener("touchstart", function (e) {
var touchobj = e.changedTouches[0];
mouseX = parseInt(touchobj.pageX - canvas.offsetLeft);
mouseY = parseInt(touchobj.pageY - canvas.offsetTop);
mousedown();
});
window.addEventListener("touchend", function (e) {
var touchobj = e.changedTouches[0];
mouseX = parseInt(touchobj.pageX - canvas.offsetLeft);
mouseY = parseInt(touchobj.pageY - canvas.offsetTop);
mouseup();
});
window.addEventListener("touchmove", function (e) {
var touchobj = e.changedTouches[0];
mouseX = parseInt(touchobj.pageX - canvas.offsetLeft);
mouseY = parseInt(touchobj.pageY - canvas.offsetTop);
});
}
window.addEventListener("mousemove", function (e) {
mouseX = e.pageX - canvas.offsetLeft;
mouseY = e.pageY - canvas.offsetTop;
});
if (typeof mousemove != "undefined") {
window.addEventListener("mousemove", mousemove);
}
if (typeof mouseup != "undefined") {
window.addEventListener("mouseup", mouseup);
}
if (typeof mousedown != "undefined") {
window.addEventListener("mousedown", mousedown);
}
if (typeof keydown != "undefined") {
window.addEventListener("keydown", function (e) {
isKeyPressed[e.keyCode] = 1;
keydown(e.keyCode);
});
}
else {
window.addEventListener("keydown", function (e) {
isKeyPressed[e.keyCode] = 1;
});
}
if (typeof keyup != "undefined") {
window.addEventListener("keyup", function (e) {
isKeyPressed[e.keyCode] = 0;
keyup(e.keyCode);
});
}
else {
window.addEventListener("keyup", function (e) {
isKeyPressed[e.keyCode] = 0;
});
}
if (typeof draw == "undefined") {
redraw = function () {
context.clearRect(0, 0, canvas.width, canvas.height);
context.globalAlpha = 1;
context.fillStyle = "#FF0000";
context.font = "20px Arial";
context.fillText("Press <F12> for error info!", 40, 40);
};
}
redraw();
callupdate();
};
//version ~9- edited by roshav. Should be fine with all touchscreendevices. Uploaded to iashu.free.bg/code.zip on 24.12.2016
</script>
<script src="dist/gif.js"></script>
<script src="demo.js"></script>
</canvas>
</body>
</html>