-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboilerplate.php
executable file
·94 lines (72 loc) · 1.65 KB
/
boilerplate.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
#!/usr/bin/php
<?php
$title = @$argv[1];
if ( empty($title) )
{
fwrite( STDERR, "Usage: {$argv[0]} TITLE\n" );
exit( 1 );
}
$title = ucfirst($title);
$name = str_replace(" ", "-", strtolower($title));
$nr = 1;
while ( count(glob(sprintf("%03d-*.html",$nr))) )
$nr++;
$id = sprintf("%03d", $nr);
$js = "{$id}-{$name}.js";
$html = "{$id}-{$name}.html";
file_put_contents( $html, "<!DOCTYPE html>
<html>
<head>
<meta charset=\"UTF-8\"/>
<link rel=\"stylesheet\" href=\"doodle.css\" />
<title>".htmlspecialchars($title)."</title>
</head>
<body>
<header id=\"doodle-header\">
<a href=\".\"><strong>←</strong> all doodles</a>
<h1>".htmlspecialchars($title)."</h1>
</header>
<main id=\"doodle-main\">
<canvas id=\"canvas\"></canvas>
</main>
<script src=\"".htmlspecialchars($js)."\"></script>
</body>
</html>" );
file_put_contents( $js, "
var canvas, ctx;
var width = 800, height = 480;
var setup = function()
{
canvas = document.getElementById(\"canvas\");
canvas.height = height;
canvas.width = width;
ctx = canvas.getContext(\"2d\");
ctx.fillStyle = 'rgb( 20, 20, 20 )';
ctx.fillRect( 0, 0, width, height );
};
var draw = function( deltaT )
{
ctx.fillStyle = 'rgb( 20, 20, 20 )';
ctx.fillRect( 0, 0, width, height );
};
(function()
{
setup();
var nextFrame = null;
var then = 0;
nextFrame = function( now )
{
var deltaT = (now - then) * 0.001;
if ( deltaT > 0.1 )
deltaT = 0.1;
draw( deltaT );
then = now;
requestAnimationFrame( nextFrame );
};
requestAnimationFrame( nextFrame );
})();
" );
file_put_contents( "README.md", "
## {$nr}. [{$title}]({$html})
(enter description here)
", FILE_APPEND );