-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexport.php
265 lines (229 loc) · 7.27 KB
/
export.php
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/**
* @projectDescription Canvas Particles Test
*
* @author Diego Vilariño - http://www.dieg0v.com - @dieg0v - http://www.sond3.com
* @version 0.1
*/
extract($_POST);
$data = '<!DOCTYPE html>
<!--
Generated by Canvas Particles Test Script on '.date("d/m/Y H:i:s").'
Web: http://www.dieg0v.com/lab/html5-canvas-particles/
GitHub: https://github.com/dieg0v/html5-canvas-particles/
-->
<html>
<head>
<meta charset="utf-8">
<title>Particles</title>
<style type="text/css">
html,body {margin: 0;padding: 0;overflow: hidden;width: 100%;height: 100%;}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
function randomRange(min, max) {
return ((Math.random() * (max - min)) + min);
}
function hexToR(h) {
return parseInt((cutHex(h)).substring(0,2),16);
}
function hexToG(h) {
return parseInt((cutHex(h)).substring(2,4),16);
}
function hexToB(h) {
return parseInt((cutHex(h)).substring(4,6),16);
}
function cutHex(h) {
return (h.charAt(0)=="#") ? h.substring(1,7):h;
}
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = ( function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
}
var MAX_PARTICLES = '.$MAX_PARTICLES.';
var NOW_PARTICLES = '.$NOW_PARTICLES.';
var COLOR = "'.$COLOR.'";
var TYPE_PARTICLE = "'.$TYPE_PARTICLE.'";
var POSITION = "'.$POSITION.'";
var RANDOM_COLOR = '.$RANDOM_COLOR.';
var VELOCITY = '.$VELOCITY.';
var BACK_COLOR= "'.$BACK_COLOR.'";
var MAX_SIZE = '.$MAX_SIZE.';
var STROKE_SIZE = '.$STROKE_SIZE.';
var STROKE_COLOR = "'.$STROKE_COLOR.'";
var OPACITY = '.$OPACITY.';
var RANDOM_SIZE = '.$RANDOM_SIZE.';
var PARTICLE_SIZE = '.$PARTICLE_SIZE.';
var DEAD_PARTICLE = '.$DEAD_PARTICLE.';
var SHADOW_BLUR = '.$SHADOW_BLUR.';
var mousePosX = window.innerWidth/2;
var mousePosY = window.innerHeight/2;
var stats;
var canvas;
var c;
var particleArray = [];
window.onload = function() {
init();
};
$(window).resize(function(){
var canvas = document.getElementById("canvas");
canvas.width=window.innerWidth;
canvas.height = window.innerHeight;
});
function getMousePos(canvas, evt) {
var rect = canvas.getBoundingClientRect();
var root = document.documentElement;
var mouseX = evt.clientX - rect.top - root.scrollTop;
var mouseY = evt.clientY - rect.left - root.scrollLeft;
return {
x: mouseX,
y: mouseY
};
}
function createParticle(){
var particle = {};
switch (POSITION){
case "mouse":
particle.x = mousePosX;
particle.y = mousePosY;
break;
case "center":
particle.x = window.innerWidth/2;
particle.y = window.innerHeight/2;
break;
case "random":
particle.x = randomRange(0,window.innerWidth);
particle.y = randomRange(0,window.innerHeight);
break;
}
particle.xSpeed = randomRange( (-1) * VELOCITY , VELOCITY);
particle.ySpeed = randomRange( (-1) * VELOCITY , VELOCITY);
var size;
if(RANDOM_SIZE==1){
size = randomRange(1,MAX_SIZE);
}else{
size = PARTICLE_SIZE;
}
particle.size = size;
return particle;
}
function init(){
canvas = document.getElementById("canvas");
c = canvas.getContext("2d");
c.canvas.width = window.innerWidth;
c.canvas.height = window.innerHeight;
canvas.addEventListener("mousemove", function(evt) {
var mousePos = getMousePos(canvas, evt);
mousePosX = mousePos.x;
mousePosY = mousePos.y;
}, false);
generateParticles();
animate();
}
function generateParticles(){
for (var i = 0; i < MAX_PARTICLES; i++) {
particleArray.push(createParticle());
}
}
function draw(){
c.clearRect(0,0,window.innerWidth,window.innerHeight);
c.fillStyle = BACK_COLOR;
c.fillRect(0,0,window.innerWidth,window.innerHeight);
for(var i=0; i<NOW_PARTICLES;i++){
var particle = particleArray[i];
var particle_color = COLOR;
if(RANDOM_COLOR==1){
var r = Math.random()*255>>0;
var g = Math.random()*255>>0;
var b = Math.random()*255>>0;
particle_color = "rgba("+r+", "+g+", "+b+", "+OPACITY+")";
}else{
particle_color = "rgba("+hexToR(particle_color)+", "+hexToG(particle_color)+", "+hexToB(particle_color)+", "+OPACITY+")";
}
c.beginPath();
c.lineWidth = STROKE_SIZE;
c.fillStyle = particle_color;
if(SHADOW_BLUR>0){
c.shadowBlur = SHADOW_BLUR;
c.shadowOffsetX = 1;
c.shadowOffsetY = 1;
c.shadowColor = "rgba(100, 100, 100, 1)";
}else{
c.shadowBlur = null;
c.shadowOffsetX = 0;
c.shadowOffsetY = 0;
c.shadowColor = "rgba(100, 100, 100, 0)";
}
var particle_stroke_color = "rgba("+hexToR(STROKE_COLOR)+", "+hexToG(STROKE_COLOR)+", "+hexToB(STROKE_COLOR)+", "+OPACITY+")";
c.strokeStyle = particle_stroke_color;
switch (TYPE_PARTICLE){
case "rect":
c.fillRect(particle.x, particle.y, particle.size, particle.size);
if(STROKE_SIZE>0){
c.strokeRect(particle.x, particle.y, particle.size, particle.size);
}
break;
case "circle":
var radius = particle.size/2;
c.arc(particle.x, particle.y, radius, 0, 2 * Math.PI, false);
c.fill();
if(STROKE_SIZE>0){
c.stroke();
}
break;
case "triangle":
c.moveTo(particle.x, particle.y);
c.lineTo(particle.x + (particle.size*2) , particle.y);
c.lineTo(particle.x + particle.size , particle.y - particle.size);
c.lineTo(particle.x, particle.y);
c.fill();
if(STROKE_SIZE>0){
c.stroke();
}
break;
}
c.closePath();
particle.x = particle.x + particle.xSpeed;
particle.y = particle.y + particle.ySpeed;
if(DEAD_PARTICLE==1){
particle.size = particle.size * (0.9 + (randomRange(1,10)/100));
if(particle.size<=0.25){
particleArray[i] = createParticle();
}
}else{
if(particle.x < -(particle.size) ||
particle.y < -(particle.size) ||
particle.x > window.innerWidth+particle.size ||
particle.y > window.innerHeight+particle.size){
particleArray[i] = createParticle();
}
}
}
}
function animate(){
requestAnimationFrame(animate);
draw();
}
</script>
</body>
</html>
';
if($TYPE==0){
echo $data;
}else{
header('Content-disposition: attachment; filename=export.html');
header('Content-type: text/html');
echo $data;
}
?>