-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
261 lines (231 loc) · 9.78 KB
/
index.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
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
<!DOCTYPE html>
<html>
<head>
<title>StarfishJS - Automatic tiled wallpaper generator</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="support/jquery-ui.min.css" rel="stylesheet" />
<script src="support/jquery-2.1.4.min.js"></script>
<script src="support/jquery-ui.min.js"></script>
<script src="lib/sf.js"></script>
<script src="lib/generators/sf-coswave.js"></script>
<script src="lib/generators/sf-spinflake.js"></script>
<script src="lib/generators/sf-rangefrac.js"></script>
<script src="lib/generators/sf-flatwave.js"></script>
<script src="lib/generators/sf-bubble.js"></script>
<script src="support/download.js"></script>
<script type="text/javascript">
// @license magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt CC0
var instance;
var canvas;
var ctx;
var hash;
var args;
function adjustCanvasSize() {
// Reads hash (for label-testing flags), and read the
// form fields for size info.
if (hash != window.location.hash) {
args = {};
hash = window.location.hash;
hash.replace(/^#!/,'').split('&')
.forEach(function(arg) {
var s = arg.split('=', 2);
if (s.length == 2)
args[s[0]] = s[1];
else if (s[0])
args[s[0]] = true;
});
}
canvas.width = $('#width').val();
canvas.height = $('#height').val();
}
function drawIt(ev) {
adjustCanvasSize();
if (ev && ev.preventDefault)
ev.preventDefault();
if (args.test && args.test in Starfish.generators) {
instance = new Starfish.generators[args.test]();
}
else {
instance = new Starfish.Instance;
}
render(ev);
}
function canvasToBackground() {
var body = document.getElementsByTagName("body")[0];
var data = canvas.toDataURL();
body.style.background = "url(" + data + ")";
// draw to image. We need this because some browsers
// (mobile/tablet) don't provide a way to save the
// canvas image, but do for img elements.
var img = document.getElementById("starfish-img");
img.src = data;
img.style.display = 'block';
canvas.style.display = 'none';
}
function render(ev) {
adjustCanvasSize();
if (ev && ev.preventDefault)
ev.preventDefault();
// Show canvas instead of image until rendering's done,
// So we can see progress.
var img = document.getElementById("starfish-img");
img.style.display = 'none';
canvas.style.display = 'block';
if (instance instanceof Starfish.Instance) {
$('.post-render').prop('disabled', true);
// Set up progress display
$('#render-info > div').css('display', 'none');
$('#render-info > p').html('Initializing layers...');
$('#render-info').css('display', 'block');
instance.render(
ctx.getImageData(0, 0, canvas.width, canvas.height)
// callback for progress updates:
, function(info) {
ctx.putImageData(instance.imageData, 0, 0);
$('#render-info > p')
.html('Pattern generation in progress');
$('#inst-info, #layer-info').css('display', 'block');
$('#inst-info > p')
.html('Layer ' + info.curLayer
+ '/' + info.numLayers);
var totalProg
= ((info.curLayer - 1 + info.percentDone/100)
/ info.numLayers);
$('#inst-prog')
.progressbar('value', 100 * totalProg);
$('#layer-percent')
.html(info.percentDone + '%');
$('#layer-prog')
.progressbar('value', info.percentDone);
}
// callback when complete:
, function() {
ctx.putImageData(instance.imageData, 0, 0);
canvasToBackground();
$('.post-render').prop('disabled', false);
$('#render-info').slideUp();
});
}
else {
// layer
instance.drawToCanvas(ctx);
canvasToBackground();
}
}
function downloadImg() {
var url = $('#starfish-img').prop('src');
download(url, 'starfish.png', 'image/png');
}
function start() {
canvas = $("#starfish")[0];
ctx = canvas.getContext("2d");
$('#refresh-link').click( drawIt );
$('#render-link').click( render );
$('#download-link').click( downloadImg );
$('#inst-prog').progressbar({value: 25});
$('#layer-prog').progressbar({value: 85});
drawIt();
}
window.addEventListener('load', start);
// @license-end
</script>
<style type="text/css">
@keyframes background-drift {
from { background-position: 0 0 }
to { background-position: 384px 384px}
}
body {
background: #ccf;
animation-name: background-drift;
animation-duration: 64s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
#starfish {
border: solid 0.5em red;
}
#starfish-img {
border: solid 0.5em navy;
display: none;
}
div.outer {
background-color: rgba(255,255,255,0.7);
font-weight: 500;
padding: 0.33em;
width: 384px;
font: 0.8em sans-serif;
margin-bottom: 0.50em;
}
.smaller {
font-size: 0.8em;
}
.spacer {
width: 100%;
}
.form {
white-space: nowrap;
}
#render-info {
display: none;
font-weight: bold;
margin: 0.33em;
padding: 0.33em;
background: #ddd;
}
#render-info > div {
margin: 0.33em;
padding: 0.33em;
border: 1px solid #aad;
border-radius: 0.67em;
font-size: 0.85em;
}
.ui-progressbar {
height: 1em;
margin: 0.12em;
}
</style>
</head>
<body>
<iframe style="display: none" id="download-iframe"></iframe>
<div class="outer">
<div id="render-info">
<p>Pattern generation in progress</p>
<div id="inst-info">
<p>Layer 1/4</p>
<div id="inst-prog"></div>
</div><!-- inst-info -->
<div id="layer-info">
<p>Layer progress: <span id="layer-percent">0%</span></p>
<div id="layer-prog"></div>
</div>
</div>
<div class="form">
<label for="width">Width</label>
<input id="width" type="number" value="384" />
<div class="spacer"></div>
<label for="height">Height</label>
<input id="height" type="number" value="384" />
<br />
<button id="refresh-link" class="post-render">New Pattern</button>
<button id="render-link" class="post-render">Render Again</button>
<button id="download-link" class="post-render">Download</button>
</div>
<hr />
<p>This is StarfishJS, a JavaScript port of Starfish, which
randomly generates a beautiful new wallpaper whenever you ask it
to.</p>
<p class="smaller">The original Starfish program was written in
C by <a href="http://www.redecho.org/">Mars Saxman</a> (<a
href="http://http.debian.net/debian/pool/main/x/xstarfish/xstarfish_1.1.orig.tar.gz">src tar</a>);
<br />
The version you are now viewing was translated to JavaScript by
<a href="mailto:[email protected]">Micah Cowan</a>.</p>
<p class="smaller">The GitHub source repository for StarfishJS is <a
href="https://github.com/micahcowan/starfishjs">here</a></p>
<p class="smaller">The various Free/Libre licenses covering this
project are detailed <a href="licenses.html" rel="jslicense">here</a>.
</div>
<img id="starfish-img" src="data:image/png," alt="[generated pattern]"/>
<canvas id="starfish" width="384" height="384"></canvas>
</body>
</html>