-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
executable file
·472 lines (424 loc) · 12.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Stereogranimator</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<!-- Import EaselJS Framework -->
<script src="src/easeljs/utils/UID.js"></script>
<script src="src/easeljs/geom/Matrix2D.js"></script>
<script src="src/easeljs/events/MouseEvent.js"></script>
<script src="src/easeljs/display/DisplayObject.js"></script>
<script src="src/easeljs/display/Container.js"></script>
<script src="src/easeljs/display/Bitmap.js"></script>
<script src="src/easeljs/display/Graphics.js"></script>
<script src="src/easeljs/display/Shape.js"></script>
<script src="src/easeljs/display/Stage.js"></script>
<script src="src/easeljs/utils/Ticker.js"></script>
<script src="src/easeljs/geom/Point.js"></script>
<script src="src/easeljs/ui/Touch.js"></script>
<!-- End EaselJS Imports -->
<script>
var canvas;
var stage;
var bmp;
// interface elements
var ln;
var c1;
var c2;
var sq1;
var sq2;
// square positions
var sq1x = 0;
var sq1y = 0;
var sq2x = 0;
var sq2y = 0;
// vertical
var vert;
var vertx = 0;
var verty = 0;
var VERTWIDTH = 10;
var VERTHEIGHT = 50;
var OFFSET = 50;
var INSET = 10;
// handle positions
var c1x = INSET;
var c1y = INSET;
var c2x = INSET;
var c2y = INSET;
var SIDE = 320;
var RAD = 5;
var THICK = 2;
var COLOR = "#fff";
var FILL = "#000";
var FILLALPHA = "rgba(0,0,0,0.5)";
var img = new Image();
var update = true;
var first = true;
function init() {
//find canvas and load images, wait for last image to load
canvas = document.getElementById("testCanvas");
stage = new Stage(canvas);
stage.enableMouseOver(10);
loadPhoto('G92F111_027ZF');
}
function run() {
// place image in bitmap:
bmp = new Bitmap(img);
bmp.x = img.width/2+OFFSET;
bmp.y = img.height/2+OFFSET;
bmp.regX = img.width/2;
bmp.regY = img.height/2;
stage.addChild(bmp);
// starting points for handles
c1x = c2x = img.x + (img.width / 2) + OFFSET;
c1y = img.y + INSET + OFFSET;
c2y = img.y + img.height - INSET + OFFSET;
// starting points for squares
sq1x = img.x + (img.width / 2) - SIDE - INSET + OFFSET;
sq1y = (img.height / 2) - (SIDE / 2) + OFFSET;
sq2x = img.x + (img.width / 2) + INSET + OFFSET;
sq2y = (img.height / 2) - (SIDE / 2) + OFFSET;
// starting point for vertical bar
vertx = img.x + (img.width / 2) + OFFSET;
verty = img.y + (img.height / 2) + OFFSET;
// joining line
ln = new Shape();
stage.addChild(ln);
// top handle
c1 = new Shape();
c1.x = c1x;
c1.y = c1y;
c1.scale = 1;
stage.addChild(c1);
// bottom handle
c2 = new Shape();
c2.x = c2x;
c2.y = c2y;
c2.scale = 1;
stage.addChild(c2);
// the squares
sq1 = new Shape();
sq1.over = false;
// to control for mouse position when dragging
sq1.mx = 0;
sq1.my = 0;
stage.addChildAt(sq1,1);
sq2 = new Shape();
sq2.over = false;
// to control for mouse position when dragging
sq2.mx = 0;
sq2.my = 0;
stage.addChildAt(sq2,1);
// vertical handle
vert = new Shape();
vert.over = false;
// to control for mouse position when dragging
vert.mx = 0;
vert.sq1x = 0;
vert.sq2x = 0;
stage.addChild(vert);
// adding interaction
addBasicInteractivity();
// we want to do some work before we update the canvas,
Ticker.addListener(window);
}
function addBasicInteractivity() {
// handle movement for VERTICAL handle
// wrapper function to provide scope for the event handlers:
(function(target) {
vert.onPress = function(evt) {
// drag
vert.mx = stage.mouseX - vertx;
vert.sq1x = vertx - sq1x;
vert.sq2x = vertx - sq2x;
//console.log("vs1:"+vert.sq1x+" vs2:"+vert.sq2x+" s1:"+sq1x+" s2:"+sq2x+" vm:"+vert.mx+" vx:"+vertx);
evt.onMouseMove = function(ev) {
vertx = stage.mouseX + target.mx;
// move squares along with bar
sq1x = vertx - target.sq1x;
sq2x = vertx - target.sq2x;
// indicate that the stage should be updated on the next tick:
update = true;
};
};
vert.onMouseOver = function() {
target.over = true;
update = true;
};
vert.onMouseOut = function() {
target.over = false;
update = true;
};
})(vert);
// handle movement for LEFT square
// wrapper function to provide scope for the event handlers:
(function(target) {
sq1.onPress = function(evt) {
// drag
// save mouse position for future reference
sq1.mx = sq1x - stage.mouseX;
sq1.my = sq1y - stage.mouseY;
var d = vertx - sq1x;
evt.onMouseMove = function(ev) {
sq1x = stage.mouseX + target.mx;
sq1y = stage.mouseY + target.my;
// move the other square in a mirror direction
d = vertx - sq1x;
sq2x = vertx + d - SIDE;
sq2y = sq1y;
// indicate that the stage should be updated on the next tick:
update = true;
};
};
sq1.onMouseOver = function() {
target.over = true;
update = true;
};
sq1.onMouseOut = function() {
target.over = false;
update = true;
};
})(sq1);
// handle movement for RIGHT square
// wrapper function to provide scope for the event handlers:
(function(target) {
sq2.onPress = function(evt) {
// drag
// save mouse position for future reference
sq2.mx = sq2x - stage.mouseX;
sq2.my = sq2y - stage.mouseY;
var d = vertx - sq2x;
evt.onMouseMove = function(ev) {
sq2x = stage.mouseX + target.mx;
sq2y = stage.mouseY + target.my;
// move the other square in a mirror direction
d = vertx - sq2x;
sq1x = vertx + d - SIDE;
sq1y = sq2y;
// indicate that the stage should be updated on the next tick:
update = true;
};
};
sq2.onMouseOver = function() {
target.over = true;
update = true;
};
sq2.onMouseOut = function() {
target.over = false;
update = true;
};
})(sq2);
}
function addFineInteractivity() {
// handle movement for TOP handle
// wrapper function to provide scope for the event handlers:
(function(target) {
c1.onPress = function(evt) {
// drag
evt.onMouseMove = function(ev) {
target.x = stage.mouseX;
target.y = stage.mouseY;
c1x = target.x;
c1y = target.y;
console.log("x:"+c1x+" y:"+c1y);
// indicate that the stage should be updated on the next tick:
update = true;
};
};
c1.onMouseOver = function() {
console.log("scale:"+target.scaleX);
target.scaleX = target.scaleY = target.scale*1.5;
update = true;
};
c1.onMouseOut = function() {
target.scaleX = target.scaleY = target.scale;
update = true;
};
})(c1);
// handle movement for BOTTOM handle
// wrapper function to provide scope for the event handlers:
(function(target) {
c2.onPress = function(evt) {
// drag
evt.onMouseMove = function(ev) {
target.x = stage.mouseX;
target.y = stage.mouseY;
c2x = target.x;
c2y = target.y;
console.log("x:"+c2x+" y:"+c2y);
// indicate that the stage should be updated on the next tick:
update = true;
};
};
c2.onMouseOver = function() {
target.scaleX = target.scaleY = target.scale*1.5;
update = true;
};
c2.onMouseOut = function() {
target.scaleX = target.scaleY = target.scale;
update = true;
};
})(c2);
// handle movement for LEFT square
// wrapper function to provide scope for the event handlers:
(function(target) {
sq1.onPress = function(evt) {
// drag
// bump up but below line
stage.addChildAt(target,2);
sq1.mx = sq1.x-stage.mouseX;
sq1.my = sq1.y-stage.mouseY;
console.log(" mx:"+sq1.mx+" my:"+sq1.my);
evt.onMouseMove = function(ev) {
sq1x = stage.mouseX + target.mx;
sq1y = stage.mouseY + target.my;
// indicate that the stage should be updated on the next tick:
update = true;
};
};
sq1.onMouseOver = function() {
target.over = true;
update = true;
};
sq1.onMouseOut = function() {
target.over = false;
update = true;
};
})(sq1);
// handle movement for RIGHT square
// wrapper function to provide scope for the event handlers:
(function(target) {
sq2.onPress = function(evt) {
// drag
// bump up but below line
stage.addChildAt(target,2);
sq2.mx = sq2.x-stage.mouseX;
sq2.my = sq2.y-stage.mouseY;
console.log(" mx:"+sq2.mx+" my:"+sq2.my);
evt.onMouseMove = function(ev) {
sq2x = stage.mouseX + target.mx;
sq2y = stage.mouseY + target.my;
// indicate that the stage should be updated on the next tick:
update = true;
};
};
sq2.onMouseOver = function() {
target.over = true;
update = true;
};
sq2.onMouseOut = function() {
target.over = false;
update = true;
};
})(sq2);
}
function draw() {
//drawHandle(c1,c1x,c1y);
//drawHandle(c2,c2x,c2y);
//drawLine();
//drawSquare(sq1, img.x + (img.width / 2) - SIDE - INSET + OFFSET, (img.height / 2) - (SIDE / 2) + OFFSET);
//drawSquare(sq2, img.x + (img.width / 2) + INSET + OFFSET, (img.height / 2) - (SIDE / 2) + OFFSET);
drawStereoscope();
}
function drawStereoscope() {
drawVertical();
drawSquare(sq1, sq1x, sq1y);
drawSquare(sq2, sq2x, sq2y);
}
function drawVertical() {
var g = vert.graphics;
g.clear();
g.setStrokeStyle(THICK, "round", "round");
g.beginStroke(COLOR);
g.beginFill(FILLALPHA);
g.drawRect(vertx - (VERTWIDTH / 2), verty - (VERTHEIGHT / 2),VERTWIDTH,VERTHEIGHT);
g.moveTo(vertx, verty - (VERTHEIGHT / 2)).lineTo(vertx, verty - (VERTHEIGHT * 2)).moveTo(vertx, verty + (VERTHEIGHT / 2)).lineTo(vertx, verty + (OFFSET * 2));
}
function drawHandle(handle,xp,yp) {
var g = handle.graphics;
g.clear();
g.setStrokeStyle(THICK, "round", "round");
g.beginStroke(COLOR);
g.beginFill(FILL);
g.drawCircle(0,0,RAD);
g.endFill();
}
function drawLine() {
var g = ln.graphics;
g.clear();
g.setStrokeStyle(THICK, "round", "round");
g.beginStroke(COLOR);
g.moveTo(c1x,c1y).lineTo(c2x,c2y);
}
function drawSquare(square,x,y) {
var g = square.graphics;
var CROSSSIZE = INSET;
if (square.over) {
CROSSSIZE = INSET*2;
}
g.clear();
g.setStrokeStyle(THICK, "round", "round");
g.beginStroke(COLOR);
g.beginFill(FILLALPHA);
g.drawRect(x,y,SIDE,SIDE);
g.moveTo(x-CROSSSIZE+SIDE/2,y-CROSSSIZE+SIDE/2).lineTo(x+CROSSSIZE+SIDE/2,y+CROSSSIZE+SIDE/2).moveTo(x+CROSSSIZE+SIDE/2,y-CROSSSIZE+SIDE/2).lineTo(x-CROSSSIZE+SIDE/2,y+CROSSSIZE+SIDE/2);
}
function tick() {
// this set makes it so the stage only re-renders when an event handler indicates a change has happened.
if (update) {
update = false; // only update once
draw();
stage.update();
}
}
function rotate() {
var deg;
deg = Math.atan((c2x-c1x)/(c2y-c1y)) * 180 / Math.PI;
console.log("rotate:"+deg);
bmp.rotation = deg;
update = true;
}
function loadPhoto(id) {
console.log("photo");
img.onload = (function () {
if (first) {
first = false;
run();
}
update = true;
});
img.src = "https://images.nypl.org/index.php?id="+id+"&t=w";
//img.src = "img/demo"+num+".jpg";
}
window.onload = init;
</script>
</head>
<body>
<div class="description">
<ol>
<li>Move the divider line so that it coincides with the middle of the stereograph.</li>
<li>Move the rectangles so that they cover each side of the photo.</li>
<li>Press ANIMATE.</li>
</ol>
</div>
<div id="nav">
<!-- <input type="button" value="ROTATE" id="btn-rotate" onclick="rotate();" /> -->
<input type="button" value="photo 1" id="btn-ph1" onclick="loadPhoto('G92F111_027ZF');" />
<input type="button" value="photo 2" id="btn-ph2" onclick="loadPhoto('TH-04569');" />
<input type="button" value="photo 3" id="btn-ph3" onclick="loadPhoto('G92F111_044ZF');" />
<input type="button" value="photo 4" id="btn-ph4" onclick="loadPhoto('G92F111_051ZF');" />
<input type="button" value="photo 5" id="btn-ph5" onclick="loadPhoto('G92F148_003F');" />
<input type="button" value="photo 6" id="btn-ph6" onclick="loadPhoto('G90F151_006F');" />
<input type="button" value="photo 7" id="btn-ph7" onclick="loadPhoto('G90F151_009F');" />
<input type="button" value="photo 8" id="btn-ph8" onclick="loadPhoto('G89F192_023F');" />
<input type="button" value="photo 9" id="btn-ph9" onclick="loadPhoto('G92F111_009F');" />
<input type="button" value="photo 10" id="btn-ph10" onclick="loadPhoto('G92F111_008F');" />
<input type="button" value="photo 11" id="btn-ph11" onclick="loadPhoto('1531160');" />
<input type="button" value="photo 12" id="btn-ph12" onclick="loadPhoto('1531158');" />
</div>
<div class="canvasHolder">
<canvas id="testCanvas" width="900" height="600"></canvas>
</div>
</body>
</html>