-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
372 lines (306 loc) · 13.3 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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<!DOCTYPE html>
<html>
<head>
<title>TelidonP5</title>
<link type="text/css" rel="stylesheet" href="./css/main.css"/>
<script type="text/javascript" src="./js/libraries/p5js/p5.min.js"></script>
<script type="text/javascript" src="./js/libraries/p5js/p5.dom.min.js"></script>
<script type="text/javascript" src="./js/libraries/p5js/p5.svg.js"></script>
<script type="text/javascript" src="./js/libraries/gifjs/gif.js"></script>
<script type="text/javascript" src="./js/telidon/naplps.js"></script>
<script type="text/javascript" src="./js/telidon/TelidonP5.js"></script>
<script type="text/javascript">
"use strict";
let recording = true;
let c;
let gif;
let posCounterX = 0;
let posCounterY = 0;
let telidon = [];
let maxLength = 3;
let dropZone;
let sW = 640;
let sH = 480;
let defaultFont;
let preview, explanation, explanationbg;
let shark, skull, santa, beer, haunt, email, mouse;
let isMobile = false;
function preload() {
isMobile = detectMobile();
if (isMobile) loadNewTelidon("./images/shark.nap");
}
function setup() {
c = createCanvas(sW, sH);
c.position(0, 29);
if (!isMobile) setupGif();
dropZone = document.getElementsByTagName("body")[0];
dropZone.addEventListener('dragover', onDragOver);
dropZone.addEventListener('drop', onDrop);
defaultFont = loadFont("./archives/fonts/Telidon-Bold/Telidon-Bold.ttf", function(font) {
textFont(font);
textSize(36);
textAlign(LEFT);
});
preview = document.getElementById("preview");
setPreview("shark");
explanation = document.getElementById("explanation");
explanationbg = document.getElementById("explanation-bg");
explanation.addEventListener("click", function() {
explanation.style = "opacity: 0";
explanationbg.style = "opacity: 0";
});
shark = document.getElementById("shark").addEventListener("click", function() {
loadNewTelidon("./images/shark.nap");
setPreview("shark");
});
skull = document.getElementById("skull").addEventListener("click", function() {
loadNewTelidon("./images/wast.nap");
setPreview("skull");
});
santa = document.getElementById("santa").addEventListener("click", function() {
loadNewTelidon("./images/santa.nap");
setPreview("santa");
});
beer = document.getElementById("beer").addEventListener("click", function() {
loadNewTelidon("./images/beer.nap");
setPreview("beer");
});
haunt = document.getElementById("haunt").addEventListener("click", function() {
loadNewTelidon("./images/haunt.nap");
setPreview("haunt");
});
email = document.getElementById("email").addEventListener("click", function() {
loadNewTelidon("./images/email2.nap");
setPreview("email");
});
mouse = document.getElementById("mouse").addEventListener("click", function() {
loadNewTelidon("./images/tb1.nap");
setPreview("mouse");
});
}
function draw() {
background(0);
if (telidon.length < 1) {
fill(255);
textAlign(CENTER);
text("\\\\ DRAG ' n ' DROP //", width/2, height/2);
textAlign(LEFT);
return;
}
translate(0,sH-sW);
for (let i=0; i<telidon.length; i++) {
telidon[i].draw();
}
if (!isMobile && recording && frameCount % 2 == 0) {
gif.addFrame(c.elt, {delay: 1, copy: true});
}
if (!isMobile && recording && telidon[telidon.length-1].finished) {
recording = false;
gif.render();
}
}
// Show the copy icon when dragging over. Seems to only work for chrome.
function onDragOver(e) {
e.stopPropagation();
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
}
function onDrop(e) {
e.stopPropagation();
e.preventDefault();
let file = e.dataTransfer.files[0];
let reader = new FileReader();
reader.onload = function(e2) {
const fileNameArray = file.name.split(".");
if (fileNameArray[fileNameArray.length-1] === "svg") {
let div = document.createElement('div');
let element = new p5.SVGElement(div);
div.innerHTML = e2.target.result;
let svg = div.querySelector('svg');
element.elt = svg;
setupSvg(element);
} else {
loadTelidonFromText(e2.target.result);
}
}
reader.readAsText(file, 'UTF-8');
}
function loadTelidonFromText(input) {
if (telidon.length >= maxLength) telidon.splice(0,1);
telidon.push(new TelidonDraw([input], sW, sW));
recording = true;
preview.style.backgroundImage = null;
}
function onFormSubmit() {
const field = document.getElementById("naplps_field");
loadTelidonFromText(field.value);
}
function loadNewTelidon(fileName) {
loadStrings(fileName, function(response) {
telidon = [];
let reader = new FileReader();
reader.onload = function(e2) {
telidon.push(new TelidonDraw([e2.target.result], sW, sW));
recording = true;
}
reader.readAsText(new Blob(response), 'UTF-8');
});
}
function setPreview(name) {
preview.style.backgroundImage = "url(./tools/rosetta_stone/cover/png/" + name + ".png)";
}
function setupGif() {
gif = new GIF({
workers: 4,
workerScript: './js/libraries/gifjs/gif.worker.js', // https://github.com/jnordberg/gif.js/issues/59
quality: 40
});
gif.on('finished', function(blob) {
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject
let img = document.createElement('img');
img.src = URL.createObjectURL(blob);
img.style = "width: " + sW/2 + "px; height: " + sH/2 + "px; position: absolute; left: " + posCounterX + "px; top: " + (posCounterY + sH + 29) + "px;";
posCounterX += sW/2;
if (posCounterX > 1.5 * sW) {
posCounterX = 0;
posCounterY += sH/2;
}
document.body.appendChild(img);
setupGif();
});
}
function detectMobile() {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i.test(navigator.userAgent)) {
return true;
} else {
return false;
}
}
// svg
function setupSvg(ps) {
let pg, polylines, polygons;
let input = [];
let offsetX = 0;
let offsetY = 0.25;
pg = createGraphics(sW, sH, SVG);
pg.push();
pg.image(ps, 0, 0);
pg.pop();
polygons = pg.querySVG('polygon');
polylines = pg.querySVG('polyline');
// NAPLPS can only use a fill color or a stroke color in one path, not both.
// fill-opacity, stroke-opacity, stroke-linecap, and stroke-width are not used.
for (let path of polygons) {
let points = [];
let color = new Vector3(255, 255, 255);
let isFill = true;
let strokeColorAttr = path.attribute("stroke"); // "#FEFEFE" or "none"
let fillColorAttr = path.attribute("fill"); // "#FEFEFE" or "none"
if (fillColorAttr !== "none") {
let colorHex = hexToRgb(fillColorAttr);
color = new Vector3(colorHex.r, colorHex.g, colorHex.b);
} else if (fillColorAttr === "none" && strokeColorAttr !== "none") {
let colorHex = hexToRgb(strokeColorAttr);
color = new Vector3(colorHex.r, colorHex.g, colorHex.b);
}
let pointsAttr = path.attribute("points").split(" ");
for (let pointAttr of pointsAttr) {
let pointAttrArray = pointAttr.split(",");
let point = new Vector2((float(pointAttrArray[0]) / sW) + offsetX, (float(pointAttrArray[1]/ sH * 0.75) + offsetY));
if (point.x >= 0 && point.x <= 1 && point.y >= 0 && point.y <= 1) {
points.push(point);
}
}
const stroke = new NapInputWrapper(color, points, isFill);
input.push(stroke);
}
for (let path of polylines) {
let points = [];
let color = new Vector3(0, 0, 0);
let isFill = false;
let strokeColorAttr = path.attribute("stroke"); // "#FEFEFE" or "none"
let fillColorAttr = path.attribute("fill"); // "#FEFEFE" or "none"
if (strokeColorAttr === "none" && fillColorAttr !== "none") {
let colorHex = hexToRgb(fillColorAttr);
color = new Vector3(colorHex.r, colorHex.g, colorHex.b);
} else if (strokeColorAttr !== "none") {
let colorHex = hexToRgb(strokeColorAttr);
color = new Vector3(colorHex.r, colorHex.g, colorHex.b);
}
let pointsAttr = path.attribute("points").split(" ");
for (let pointAttr of pointsAttr) {
let pointAttrArray = pointAttr.split(",");
let point = new Vector2((float(pointAttrArray[0]) / sW) + offsetX, (float(pointAttrArray[1]/ sH * 0.75) + offsetY));
if (point.x >= 0 && point.x <= 1 && point.y >= 0 && point.y <= 1) {
points.push(point);
}
}
const stroke = new NapInputWrapper(color, points, isFill);
input.push(stroke);
}
const encoder = new NapEncoder(input);
loadTelidonFromText(encoder.napRaw);
}
function hexToRgb(hex) {
let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
function componentToHex(c) {
let hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
</script>
</head>
<body>
<div id="container">
<div class="sketch">
<a href="https://github.com/n1ckfg/Telidon"><i>source</i></a> |
<a href="javascript:void(0)" id="shark">shark</a> |
<a href="javascript:void(0)" id="skull">skull</a> |
<a href="javascript:void(0)" id="santa">santa</a> |
<a href="javascript:void(0)" id="beer">beer</a> |
<a href="javascript:void(0)" id="haunt">haunt</a> |
<a href="javascript:void(0)" id="email">email</a> |
<a href="javascript:void(0)" id="mouse">mouse</a><br>
</div>
<div class="preview-base" id="preview"></div>
<div class="preview-base" id="explanation-bg"></div>
<div class="explanation-base" id="explanation">
<p>
<b><a href="https://github.com/n1ckfg/Telidon/blob/master/js/telidon/TelidonP5.js">TelidonP5.js</a></b> allows NAPLPS vector graphics files to be displayed in a browser using <a href="https://p5js.org/">p5.js</a>. It depends on a companion encoder/decoder library <b><a href="https://github.com/n1ckfg/Telidon/blob/master/js/telidon/naplps.js">naplps.js</a></b> can also be used separately.
</p>
<p>
August 15th, 2018 marked the 40th anniversary of the <a href="https://en.wikipedia.org/wiki/Telidon">Telidon</a> vector graphics workstation, launched in 1978. The Telidon hardware was discontinued in 1985, but its file format, standardized as <a href="https://en.wikipedia.org/wiki/NAPLPS">NAPLPS</a>, thrived and remained in wide use throughout the <a href="https://en.wikipedia.org/wiki/Bulletin_board_system">BBS</a> era, until the mid-1990s. Thanks to its exceptionally small file size and limited animation features, NAPLPS can be seen as a technological ancestor of the <a href="https://en.wikipedia.org/wiki/GIF#Animated_GIF">animated GIF</a> and the <a href="https://en.wikipedia.org/wiki/SWF">Flash SWF</a>—a new artistic medium that could be both produced and distributed on the same machine.
</p>
<p>
From 1982–1985, members of the Toronto arts org <a href="http://interaccess.org/">InterAccess</a> used Telidon systems to produce an ambitious series of <a href="https://motherboard.vice.com/en_us/article/ezveak/the-original-net-artists">interactive BBS-based artworks</a> in the format.
</p>
<!--
<p>
Three anniversary events were held at InterAccess in spring 2018:<br/>
<a href="http://interaccess.org/event/2018/naplps-adventure-new-media-art-history">http://interaccess.org/event/2018/naplps-adventure-new-media-art-history</a><br/>
<a href="http://interaccess.org/event/2018/digital-archaeology-excavating-telidon">http://interaccess.org/event/2018/digital-archaeology-excavating-telidon</a><br/>
<a href="http://interaccess.org/exhibition/telidon">http://interaccess.org/exhibition/telidon</a>
</p>
-->
<p>
Nick Fox-Gieg / 180326
</p>
</div>
<div id="naplps_field_container">
<form>
<label style="color: #ffffff;" for="naplps_field">NAPLPS Text: </label>
<input type="text" id="naplps_field" name="naplps_field"><br><br>
<input type="button" onclick="onFormSubmit()" value="Submit">
</form>
<div>
</div>
</body>
</html>