-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.html
337 lines (286 loc) · 7.72 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
<title>Plumin.js | Create and Manipulate fonts using javascript | Live font scripting</title>
<meta name="description" content="An experiment with plumin.js, WebWorkers and requestAnimationFrame. It Vorx!">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="node_modules/knacss/css/knacss.css">
<link rel="stylesheet" href="node_modules/codemirror/lib/codemirror.css">
<style>
html,
body,
body > .row > .col {
height: 100%;
}
body > .row {
height: calc( 100% - 100px );
}
textarea.editor,
textarea.result {
width: 100%;
/* Doesn't work in Chrome :-/
height: calc( 100% - 100px ); */
height: 400px;
margin: 0;
}
textarea.editor,
.CodeMirror {
font-size: 20px;
}
textarea.result {
padding: 20px;
border: 0;
border-radius: 0;
font-family: 'Demo', sans-serif;
font-size: 100px;
resize: none;
}
.btn {
border: 1px solid #CCC;
border-radius: 3px;
margin-top: 10px;
padding: 5px 10px;
font-size: 25px;
text-decoration: none;
}
.fb-like {
height: 20px;
font-size: 0;
}
.gh-star {
width: 106px;
}
</style>
</head>
<body>
<!--[if lt IE 10]>
<p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
<![endif]-->
<h1 class="man pam">
<a href="http://www.pluminjs.com"><img src="plumin.png" alt="Plumin.js" style="height: 50px;"></a>
<span class="h2" style="vertical-align: -12px">
– Playground like no one's watching –
<iframe src="https://ghbtns.com/github-btn.html?user=byte-foundry&repo=plumin.js&type=fork&count=true&size=large" frameborder="0" scrolling="0" width="158px" height="30px" style="vertical-align: baseline;"></iframe>
</span>
</h1>
<div class="row">
<div class="col w50 plm">
<textarea id="editor" class="editor">
(function(p) {
var font = new p.Font({
familyName: 'Demo',
ascender: 800,
descender: -200
}),
// glyphs
A = new p.Glyph({
name: 'A',
unicode: 'A',
advanceWidth: 512
}),
B = new p.Glyph({
name: 'B',
unicode: 'B',
advanceWidth: 512
}),
C = new p.Glyph({
name: 'C',
unicode: 'C',
advanceWidth: 512
}),
shape,
counter;
// A contours
shape = new p.Path.RegularPolygon({
center: [256, 136],
sides: 3,
radius: 256
});
counter = new p.Path.RegularPolygon({
center: [256, 61],
sides: 3,
radius: 256
});
shape.rotate(180, [256, 136]);
counter.rotate(180, [256, 61]);
A.addContour(shape.subtract(counter));
A.scale(1,2, [256, 0]);
// B contours
shape = new p.Path.Rectangle({
point: [0, 0],
size: [450, 450]
});
counter = new p.Path.Rectangle({
point: [40, 40],
size: [370, 370]
});
B.addContour(shape.subtract(counter));
shape = new p.Path.Rectangle({
point: [0, 410],
size: [340, 340]
});
counter = new p.Path.Rectangle({
point: [40, 450],
size: [260, 260]
});
B.addContour(shape.subtract(counter));
// C contours
shape = new p.Path.Ellipse({
point: [0, 0],
size: [520, 800]
});
counter = new p.Path.Ellipse({
point: [40, 40],
size: [440, 720]
});
shape = shape.subtract(counter);
counter = new p.Path.Rectangle({
point: [430, 180],
size: [100, 440]
});
C.addContour(shape.subtract(counter));
this.font = font.addGlyphs([ A, B, C ]);
font.updateOTCommands();
font.addToFonts();
/*
// animation is only fluid in Chrome and Firefox
var center = p.Point([256, 500]);
this.onFrame = function() {
A.rotate(3, center);
B.rotate(-3, center);
C.rotate(3, center);
font.updateOTCommands();
font.addToFonts();
};
*/
})(plumin);
</textarea>
<div class="mtm txtcenter">
<a href="#" class="btn" onclick="_run();">▷ Run</a> <label><input id="workerSwitch" type="checkbox"/> Using a WebWorker</label>
</div>
</div>
<div class="col w50">
<textarea id="result" class="result pal"> A B C</textarea>
<div class="mtm txtcenter">
<a href="#" class="btn" onclick="_download(event);">▽ Download</a>
</div>
</div>
</div>
<canvas id="hidden-canvas" width="1024" height="1024" hidden />
<script src="node_modules/codemirror/lib/codemirror.js"></script>
<script src="node_modules/codemirror/mode/javascript/javascript.js"></script>
<script src="node_modules/codemirror/addon/edit/closebrackets.js"></script>
<script src="dist/plumin.js"></script>
<script>
plumin.paper.setup('hidden-canvas');
var cm = CodeMirror.fromTextArea( document.getElementById('editor'), {
autoCloseBrackets: true
});
cm.setSize('100%', document.getElementById('result').offsetHeight );
var _URL = window.URL || window.webkitURL,
lastBuffer,
request,
worker,
pluminSource,
workerSwitch = document.getElementById('workerSwitch'),
xhr = new XMLHttpRequest(),
_font = new plumin.Font({
familyName: 'Demo'
});
xhr.open('GET', 'dist/plumin.js', true);
xhr.onload = function(e) {
if ( this.status === 200 ) {
pluminSource = this.response;
}
};
xhr.send();
function _run() {
// stop previous run
if ( request ) {
cancelAnimationFrame(request);
window.onFrame = false;
if ( worker ) {
worker.terminate();
}
}
return workerSwitch.checked ?
_runWorker():
_runNoWorker();
}
function _runNoWorker() {
/*jslint evil: true */
try {
( new Function( cm.getValue() ) )();
} catch(e) {
console.error(e);
}
if ( window.onFrame ) {
(function _onFrame() {
window.onFrame();
request = requestAnimationFrame(_onFrame);
})();
}
}
function _runWorker() {
// Create a worker using the inline script tag below
// (only to avoid adding one more file to the project)
worker = new Worker(
_URL.createObjectURL( new Blob(
[document.getElementById('workerscript')
.textContent
.replace('PLUMINSOURCE', pluminSource)
.replace('TEXTAREASOURCE', cm.getValue())],
{type: "text/javascript"}
))
);
worker.onmessage = function(e) {
_font.addToFonts( lastBuffer = e.data );
};
(function _onFrame() {
worker.postMessage('frame');
request = requestAnimationFrame(_onFrame);
})();
}
function _download(e) {
e.preventDefault();
return lastBuffer ?
_font.download( lastBuffer ):
window.font
.updateOTCommands()
.download();
}
</script>
<script id="workerscript" type="text/workerscript">
// importScripts doesn't work with inline worker.
// The following placeholder will be replaced with plumin source.
// You wouldn't use inline workers and this trick in prod, though.
PLUMINSOURCE
plumin.paper.install(this);
plumin.paper.setup({
width: 1024,
height: 1024
});
var acceptMessage = true;
// Overwrite addToFonts to send the buffer over to the UI
plumin.paper.Font.prototype.addToFonts = function() {
var buffer = this.ot.toArrayBuffer();
postMessage( buffer, [buffer] );
// the font has been generated and posted to the UI,
// we're ready to generate a new font
acceptMessage = true;
};
onmessage = function() {
if ( acceptMessage && self.onFrame ) {
// Don't accept new messages until we have finished generating this font.
// Without this condition, the worker starts drawning, resulting in lower framerate.
acceptMessage = false;
self.onFrame();
}
};
TEXTAREASOURCE
</script>
</body>
</html>