/
circles.php
118 lines (84 loc) · 2.23 KB
/
circles.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
<?php
if (isset($_GET['3141592654'])) die(highlight_file(__FILE__, 1));
function getPageJS($canvas, $width, $height)
{
$output = '';
$output .= '<script src="surface.js"></script>';
$output .= '<script>';
$output .= "var canvas = '$canvas';";
$output .= "var width = '$width';";
$output .= "var height = '$height';";
$output .= <<< 'EOD'
var d;
var xPoint;
var yPoint;
var color = '0xFF0000';
function drawCircle(centerX, centerY, radius)
{
d = 3 - (2 * radius);
xPoint = 0;
yPoint = radius;
while(xPoint <= yPoint)
{
Surface.plot(centerX + xPoint, centerY + yPoint, color);
Surface.plot(centerX + xPoint, centerY - yPoint, color);
Surface.plot(centerX - xPoint, centerY + yPoint, color);
Surface.plot(centerX - xPoint, centerY - yPoint, color);
Surface.plot(centerX + yPoint, centerY + xPoint, color);
Surface.plot(centerX + yPoint, centerY - xPoint, color);
Surface.plot(centerX - yPoint, centerY + xPoint, color);
Surface.plot(centerX - yPoint, centerY - xPoint, color);
if(d < 0)
{
d = d + (4 * xPoint) + 6;
}
else
{
d = d + 4 * (xPoint - yPoint) + 10;
yPoint--;
}
xPoint++;
}
}
var rad;
var xPt;
var yPt;
function circleLoop()
{
rad = Math.floor(Math.random() * 20) + 5;
xPt = Math.floor(Math.random() * (width - (rad * 2))) + Math.floor(rad / 2);
yPt = Math.floor(Math.random() * (height - (rad * 2))) + Math.floor(rad / 2);
drawCircle(xPt, yPt, rad);
Surface.render();
}
function main(canvas, width, height, mainFunc, loopFunc)
{
var canvasContext = document.getElementById(canvas);
Surface.init(canvasContext, width, height);
Surface.loop(loopFunc, 60);
}
main(canvas, width, height, circleLoop, circleLoop);
EOD;
$output .= '</script>';
return $output;
}
function getPageHTML($canvas, $width, $height)
{
$output = '';
$output .= '<!DOCTYPE html>';
$output .= '<html>';
$output .= '<head>';
$output .= '</head>';
$output .= '<body>';
$output .= '<canvas id="'.$canvas.'" width="'.$width.'" height="'.$height.'">';
$output .= 'herp derp nice browser';
$output .= '</canvas>';
$output .= getPageJS($canvas, $width, $height);
$output .= '</body>';
$output .= '</html>';
return $output;
}
$output = '';
$output .= getPageHTML('canvas', 1024, 768);
echo $output;
?>