-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspinning-shapes.html
685 lines (577 loc) · 41.9 KB
/
spinning-shapes.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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
<!DOCTYPE html>
<html>
<head>
<!--
Copyright Cynthia Clementine
April-25-2022
The mushroom mesh and teapot mesh aren't mine, I got them from this website -> http://www.holmes3d.net/graphics/
-->
<title>3d Spinning Shapes</title>
<meta charset="UTF-8">
<style>
body {
background-color: slateblue;
}
#can {
display: block;
margin: auto;
}
#centerPara {
text-align: center;
}
#uploadBox {
display: none;
}
</style>
</head>
<script src="common/functions-coordinate.js"></script>
<script>
var canvas;
var ctx;
var camera = {
x: 0,
y: 0,
z: -10,
zMin: -5000,
zMax: -1,
scale: 1100,
};
window.onload = setup;
window.addEventListener("keydown", handleKeyPress);
window.addEventListener("mousewheel", handleScroll);
var color_bg = "#000";
var color_cube = "#8AF";
var shape_active = 0;
var shapes = [
"tetrahedron",
"hexahedron",
"octohedron",
"dodecahedron",
"icosahedron",
"torus",
"teapot",
"lorenz",
"mushroom",
"custom",
];
var shape_tet = [
[-1, 1, -1],
[1, 1, 1],
[-1, -1, 1],
[1, -1, -1],
];
var shape_hex = [
[-1, 1, -1],
[-1, 1, 1],
[1, 1, 1],
[1, 1, -1],
[-1, -1, -1],
[-1, -1, 1],
[1, -1, 1],
[1, -1, -1]
];
var shape_oct = [
[-1, 0, 0],
[0, 0, 1],
[1, 0, 0],
[0, 0, -1],
[0, 1, 0],
[0, -1, 0],
];
var phi = (1 + Math.sqrt(5)) / 2;
var ihp = 1 / phi;
var shape_dod = [
//I put an extra point in here. It isn't used, but it does allow me to use 1-indeces instead of 0-indexes.
[0, 0, 0],
//cube
[-1, 1, -1],
[-1, 1, 1],
[1, 1, 1],
[1, 1, -1],
[-1, -1, -1],
[-1, -1, 1],
[1, -1, 1],
[1, -1, -1],
//bars
[ihp, phi, 0],
[-ihp, phi, 0],
[ihp, -phi, 0],
[-ihp, -phi, 0],
[-phi, 0, -ihp],
[-phi, 0, ihp],
[phi, 0, ihp],
[phi, 0, -ihp],
[0, -ihp, -phi],
[0, ihp, -phi],
[0, ihp, phi],
[0, -ihp, phi],
];
var shape_ico = [
//top point
[0, phi, 0],
//upper 5
polToCart(Math.PI * 2 / 5, Math.PI / 6, phi),
polToCart(Math.PI * 4 / 5, Math.PI / 6, phi),
polToCart(Math.PI * 6 / 5, Math.PI / 6, phi),
polToCart(Math.PI * 8 / 5, Math.PI / 6, phi),
polToCart(Math.PI * 10 / 5, Math.PI / 6, phi),
//lower 5
polToCart(Math.PI * 1 / 5, Math.PI / -6, phi),
polToCart(Math.PI * 3 / 5, Math.PI / -6, phi),
polToCart(Math.PI * 5 / 5, Math.PI / -6, phi),
polToCart(Math.PI * 7 / 5, Math.PI / -6, phi),
polToCart(Math.PI * 9 / 5, Math.PI / -6, phi),
//lowest point
[0, -phi, 0],
];
var shape_tor = [];
var maxQ = 12;
var maxK = 8;
createTorus();
var shape_tea = [
[-0.554,-0.037,0],[-0.55,-0.049,0.042],[-0.55,-0.049,-0.042],[-0.543,0.05,0],[-0.541,-0.074,0.056],[-0.541,-0.074,-0.056],[-0.534,-0.111,0],[-0.532,-0.1,0.042],[-0.532,-0.1,-0.042],[-0.529,-0.112,0],[-0.515,-0.037,0.196],[-0.515,-0.037,-0.196],[-0.514,0.143,0],[-0.505,0.05,0.192],[-0.505,0.05,-0.192],[-0.497,-0.111,0.189],[-0.497,-0.111,-0.189],[-0.491,-0.166,0],[-0.479,0.143,0.181],[-0.479,0.143,-0.181],[-0.474,0.239,0],[-0.457,-0.166,0.172],[-0.457,-0.166,-0.172],[-0.454,0.244,0],[-0.45,0.253,0.042],[-0.45,0.253,-0.042],[-0.448,-0.203,0],[-0.442,0.239,0.165],[-0.442,0.239,-0.165],[-0.441,0.272,0.056],[-0.441,0.272,-0.056],[-0.432,0.291,0.042],[-0.432,0.291,-0.042],[-0.429,-0.225,0],[-0.429,0.3,0],[-0.429,0.338,0],[-0.417,-0.203,0.155],[-0.417,-0.203,-0.155],[-0.416,0.356,0],[-0.409,-0.037,0.355],[-0.409,-0.037,-0.355],[-0.404,0.362,0],[-0.404,0.338,0],[-0.401,0.05,0.347],[-0.401,0.05,-0.347],[-0.399,-0.225,0.147],[-0.399,0.338,0.147],[-0.399,-0.225,-0.147],[-0.399,0.338,-0.147],[-0.399,0.356,0],[-0.395,-0.111,0.341],[-0.395,-0.111,-0.341],[-0.388,0.356,0.142],[-0.388,0.356,-0.142],[-0.381,0.143,0.327],[-0.381,0.143,-0.327],[-0.379,0.338,0],[-0.377,0.362,0.138],[-0.377,0.362,-0.138],[-0.376,0.338,0.137],[-0.376,0.338,-0.137],[-0.372,0.356,0.135],[-0.372,0.356,-0.135],[-0.364,-0.166,0.311],
[-0.364,-0.166,-0.311],[-0.353,0.338,0.128],[-0.353,0.338,-0.128],[-0.352,0.239,0.299],[-0.352,0.239,-0.299],[-0.343,0.36,0],[-0.334,-0.203,0.28],[-0.334,-0.203,-0.28],[-0.32,0.36,0.113],[-0.32,0.36,-0.113],[-0.32,-0.225,0.266],[-0.32,0.338,0.266],[-0.32,-0.225,-0.266],[-0.32,0.338,-0.266],[-0.311,0.356,0.257],[-0.311,0.356,-0.257],[-0.303,0.362,0.249],[-0.303,0.362,-0.249],[-0.302,0.338,0.248],[-0.302,0.338,-0.248],[-0.299,0.356,0.245],[-0.299,0.356,-0.245],[-0.284,0.338,0.231],[-0.284,0.338,-0.231],[-0.26,0.375,0],[-0.259,0.36,0.205],[-0.259,0.36,-0.205],[-0.25,-0.037,0.461],[-0.25,-0.037,-0.461],[-0.246,0.05,0.451],[-0.246,0.05,-0.451],[-0.244,0.375,0.081],[-0.244,0.375,-0.081],[-0.242,-0.111,0.443],[-0.242,-0.111,-0.443],[-0.234,0.143,0.425],[-0.234,0.143,-0.425],[-0.225,-0.166,0.404],[-0.225,-0.166,-0.404],[-0.219,0.239,0.388],[-0.219,0.239,-0.388],[-0.208,-0.203,0.364],[-0.208,-0.203,-0.364],[-0.201,-0.225,0.346],[-0.201,0.338,0.346],[-0.201,-0.225,-0.346],[-0.201,0.338,-0.346],[-0.2,0.375,0.146],[-0.2,0.375,-0.146],[-0.196,0.356,0.334],[-0.196,0.356,-0.334],[-0.191,0.362,0.324],[-0.191,0.362,-0.324],[-0.191,0.338,0.323],[-0.191,0.338,-0.323],[-0.189,0.356,0.318],[-0.189,0.356,-0.318],[-0.181,0.338,0.3],[-0.181,0.338,-0.3],[-0.168,0.39,0],[-0.167,0.36,0.267],[-0.167,0.36,-0.267],
[-0.159,0.39,0.045],[-0.159,0.39,-0.045],[-0.139,0.513,0],[-0.135,0.483,0],[-0.134,0.39,0.081],[-0.134,0.39,-0.081],[-0.134,0.375,0.19],[-0.134,0.375,-0.19],[-0.132,0.513,0.034],[-0.132,0.513,-0.034],[-0.128,0.483,0.032],[-0.128,0.483,-0.032],[-0.114,0.513,0.061],[-0.114,0.513,-0.061],[-0.111,0.483,0.058],[-0.111,0.483,-0.058],[-0.104,0.413,0],[-0.103,0.446,0],[-0.1,0.413,0.02],[-0.1,0.413,-0.02],[-0.099,0.446,0.019],[-0.099,0.446,-0.019],[-0.098,0.39,0.105],[-0.098,0.39,-0.105],[-0.089,0.413,0.035],[-0.089,0.413,-0.035],[-0.088,0.446,0.035],[-0.088,0.446,-0.035],[-0.087,0.513,0.079],[-0.087,0.513,-0.079],[-0.085,0.483,0.075],[-0.085,0.483,-0.075],[-0.073,0.413,0.046],[-0.073,0.413,-0.046],[-0.073,0.446,0.045],[-0.073,0.446,-0.045],[-0.054,0.525,0],[-0.054,0.446,0.049],[-0.054,0.413,0.05],[-0.054,0.483,0.081],[-0.054,0.513,0.085],[-0.054,0.39,0.114],[-0.054,0.375,0.206],[-0.054,0.36,0.289],[-0.054,0.338,0.325],[-0.054,0.356,0.345],[-0.054,0.338,0.35],[-0.054,0.362,0.351],[-0.054,0.356,0.362],[-0.054,-0.225,0.375],[-0.054,0.338,0.375],[-0.054,-0.203,0.395],[-0.054,0.239,0.421],[-0.054,-0.166,0.438],[-0.054,0.143,0.461],[-0.054,-0.111,0.48],[-0.054,0.05,0.489],[-0.054,-0.037,0.5],[-0.054,0.446,-0.049],[-0.054,0.413,-0.05],[-0.054,0.483,-0.081],[-0.054,0.513,-0.085],[-0.054,0.39,-0.114],
[-0.054,0.375,-0.206],[-0.054,0.36,-0.289],[-0.054,0.338,-0.325],[-0.054,0.356,-0.345],[-0.054,0.338,-0.35],[-0.054,0.362,-0.351],[-0.054,0.356,-0.362],[-0.054,-0.225,-0.375],[-0.054,0.338,-0.375],[-0.054,-0.203,-0.395],[-0.054,0.239,-0.421],[-0.054,-0.166,-0.438],[-0.054,0.143,-0.461],[-0.054,-0.111,-0.48],[-0.054,0.05,-0.489],[-0.054,-0.037,-0.5],[-0.034,0.446,0.045],[-0.034,0.446,-0.045],[-0.034,0.413,0.046],[-0.034,0.413,-0.046],[-0.022,0.483,0.075],[-0.022,0.483,-0.075],[-0.02,0.513,0.079],[-0.02,0.513,-0.079],[-0.019,0.446,0.035],[-0.019,0.446,-0.035],[-0.018,0.413,0.035],[-0.018,0.413,-0.035],[-0.009,0.39,0.105],[-0.009,0.39,-0.105],[-0.008,0.446,0.019],[-0.008,0.446,-0.019],[-0.007,0.413,0.02],[-0.007,0.413,-0.02],[-0.004,0.446,0],[-0.004,0.413,0],[0.004,0.483,0.058],[0.004,0.483,-0.058],[0.007,0.513,0.061],[0.007,0.513,-0.061],[0.021,0.483,0.032],[0.021,0.483,-0.032],[0.025,0.513,0.034],[0.025,0.513,-0.034],[0.027,0.375,0.19],[0.027,0.375,-0.19],[0.027,0.39,0.081],[0.027,0.39,-0.081],[0.028,0.483,0],[0.032,0.513,0],[0.052,0.39,0.045],[0.052,0.39,-0.045],[0.06,0.36,0.267],[0.06,0.36,-0.267],[0.061,0.39,0],[0.074,0.338,0.3],[0.074,0.338,-0.3],[0.082,0.356,0.318],[0.082,0.356,-0.318],[0.084,0.338,0.323],[0.084,0.338,-0.323],[0.084,0.362,0.324],[0.084,0.362,-0.324],[0.089,0.356,0.334],
[0.089,0.356,-0.334],[0.093,0.375,0.146],[0.093,0.375,-0.146],[0.094,-0.225,0.346],[0.094,0.338,0.346],[0.094,-0.225,-0.346],[0.094,0.338,-0.346],[0.101,-0.203,0.364],[0.101,-0.203,-0.364],[0.112,0.239,0.388],[0.112,0.239,-0.388],[0.118,-0.166,0.404],[0.118,-0.166,-0.404],[0.127,0.143,0.425],[0.127,0.143,-0.425],[0.135,-0.111,0.443],[0.135,-0.111,-0.443],[0.137,0.375,0.081],[0.137,0.375,-0.081],[0.139,0.05,0.451],[0.139,0.05,-0.451],[0.143,-0.037,0.461],[0.143,-0.037,-0.461],[0.152,0.36,0.205],[0.152,0.36,-0.205],[0.153,0.375,0],[0.177,0.338,0.231],[0.177,0.338,-0.231],[0.192,0.356,0.245],[0.192,0.356,-0.245],[0.195,0.338,0.248],[0.195,0.338,-0.248],[0.196,0.362,0.249],[0.196,0.362,-0.249],[0.204,0.356,0.257],[0.204,0.356,-0.257],[0.213,-0.225,0.266],[0.213,0.338,0.266],[0.213,-0.225,-0.266],[0.213,0.338,-0.266],[0.213,0.36,0.113],[0.213,0.36,-0.113],[0.227,-0.203,0.28],[0.227,-0.203,-0.28],[0.236,0.36,0],[0.245,0.239,0.299],[0.245,0.239,-0.299],[0.246,0.338,0.128],[0.246,0.338,-0.128],[0.257,-0.166,0.311],[0.257,-0.166,-0.311],[0.265,0.356,0.135],[0.265,0.356,-0.135],[0.269,0.338,0.137],[0.269,0.338,-0.137],[0.27,0.362,0.138],[0.27,0.362,-0.138],[0.271,0.338,0],[0.274,0.143,0.327],[0.274,0.143,-0.327],[0.281,0.356,0.142],[0.281,0.356,-0.142],[0.288,-0.111,0.341],[0.288,-0.111,-0.341],
[0.292,0.356,0],[0.292,-0.225,0.147],[0.292,0.338,0.147],[0.292,-0.225,-0.147],[0.292,0.338,-0.147],[0.294,0.05,0.347],[0.294,0.05,-0.347],[0.296,0.338,0],[0.297,0.362,0],[0.301,-0.037,0.355],[0.301,-0.037,-0.355],[0.309,0.356,0],[0.31,-0.203,0.155],[0.31,-0.203,-0.155],[0.321,-0.225,0],[0.321,0.338,0],[0.335,0.239,0.165],[0.335,0.239,-0.165],[0.341,-0.203,0],[0.35,-0.166,0.172],[0.35,-0.166,-0.172],[0.367,0.239,0],[0.371,-0.112,0],[0.371,0.094,0],[0.371,-0.08,0.093],[0.371,0.062,0.093],[0.371,-0.009,0.124],[0.371,-0.08,-0.093],[0.371,0.062,-0.093],[0.371,-0.009,-0.124],[0.372,0.143,0.181],[0.372,0.143,-0.181],[0.384,-0.166,0],[0.39,-0.111,0.189],[0.39,-0.111,-0.189],[0.398,0.05,0.192],[0.398,0.05,-0.192],[0.407,0.143,0],[0.408,-0.037,0.196],[0.408,-0.037,-0.196],[0.427,-0.111,0],[0.436,0.05,0],[0.446,-0.037,0],[0.491,0.121,0],[0.501,0.098,0.084],[0.501,0.098,-0.084],[0.521,0.045,0.112],[0.521,0.045,-0.112],[0.541,-0.007,0.084],[0.541,-0.007,-0.084],[0.543,0.188,0],[0.55,-0.031,0],[0.555,0.174,0.064],[0.555,0.174,-0.064],[0.572,0.268,0],[0.581,0.143,0.085],[0.581,0.143,-0.085],[0.586,0.263,0.044],[0.586,0.263,-0.044],[0.607,0.113,0.064],[0.607,0.113,-0.064],[0.618,0.252,0.059],[0.618,0.252,-0.059],[0.618,0.099,0],[0.621,0.338,0],[0.639,0.348,0],[0.645,0.338,0.035],[0.645,0.338,-0.035],
[0.646,0.338,0],[0.649,0.241,0.044],[0.649,0.241,-0.044],[0.653,0.352,0],[0.657,0.348,0],[0.662,0.338,0.021],[0.662,0.338,-0.021],[0.663,0.236,0],[0.665,0.349,0.033],[0.665,0.349,-0.033],[0.676,0.352,0.028],[0.676,0.352,-0.028],[0.677,0.349,0.023],[0.677,0.349,-0.023],[0.696,0.338,0.028],[0.696,0.338,0.047],[0.696,0.338,-0.028],[0.696,0.338,-0.047],[0.72,0.35,0.044],[0.72,0.35,-0.044],[0.721,0.351,0.031],[0.721,0.351,-0.031],[0.728,0.354,0.037],[0.728,0.354,-0.037],[0.731,0.338,0.021],[0.731,0.338,-0.021],[0.746,0.338,0],[0.748,0.338,0.035],[0.748,0.338,-0.035],[0.765,0.352,0.023],[0.765,0.352,-0.023],[0.771,0.338,0],[0.775,0.351,0.033],[0.775,0.351,-0.033],[0.78,0.356,0.028],[0.78,0.356,-0.028],[0.785,0.353,0],[0.8,0.352,0],[0.804,0.357,0],[-0.57,0.243,0],[-0.574,0.252,0.042],[-0.574,0.252,-0.042],[-0.581,0.271,0.056],[-0.581,0.271,-0.056],[-0.589,0.29,0.042],[-0.589,0.29,-0.042],[-0.593,0.298,0],[-0.634,0.014,0],[-0.636,0.004,0.042],[-0.636,0.004,-0.042],[-0.642,-0.016,0.056],[-0.642,-0.016,-0.056],[-0.648,-0.036,0.042],[-0.648,-0.036,-0.042],[-0.651,-0.046,0],[-0.657,0.237,0],[-0.665,0.245,0.042],[-0.665,0.245,-0.042],[-0.683,0.261,0.056],[-0.683,0.261,-0.056],[-0.688,0.075,0],[-0.695,0.068,0.042],[-0.695,0.068,-0.042],[-0.701,0.278,0.042],[-0.701,0.278,-0.042],[-0.71,0.286,0],
[-0.71,0.22,0],[-0.712,0.051,0.056],[-0.712,0.051,-0.056],[-0.719,0.137,0],[-0.721,0.225,0.042],[-0.721,0.225,-0.042],[-0.729,0.188,0],[-0.729,0.035,0.042],[-0.729,0.035,-0.042],[-0.729,0.132,0.042],[-0.729,0.132,-0.042],[-0.736,0.027,0],[-0.74,0.188,0.042],[-0.74,0.188,-0.042],[-0.745,0.236,0.056],[-0.745,0.236,-0.056],[-0.753,0.121,0.056],[-0.753,0.121,-0.056],[-0.766,0.188,0.056],[-0.766,0.188,-0.056],[-0.769,0.248,0.042],[-0.769,0.248,-0.042],[-0.776,0.11,0.042],[-0.776,0.11,-0.042],[-0.78,0.253,0],[-0.787,0.105,0],[-0.792,0.188,0.042],[-0.792,0.188,-0.042],[-0.804,0.188,0]
];
var shape_tea_edges = [
[0,3],[0,10],[0,11],[0,6],[0,1],[0,432],[0,2],[1,433],[1,4],[2,434],[2,5],[3,12],[3,13],[3,14],[4,435],[4,7],[5,436],[5,8],[6,15],[6,17],[6,16],[7,437],[7,9],[8,438],[8,9],[9,439],[10,13],[10,39],[10,15],[11,14],[11,40],[11,16],[12,20],[12,18],[12,19],[13,18],[13,43],[14,19],[14,44],[15,50],[15,21],[16,51],[16,22],[17,21],[17,26],[17,22],[18,27],[18,54],[19,28],[19,55],[20,35],[20,27],[20,28],[21,63],[21,36],[22,64],[22,37],[23,24],[23,424],[23,25],[24,425],[24,29],[25,30],[25,426],[26,36],[26,33],[26,37],[27,46],[27,67],[28,48],[28,68],[29,427],[29,31],[30,32],[30,428],[31,429],[31,34],[32,34],[32,430],[33,45],[33,47],[34,431],[35,38],[35,46],[35,48],[36,70],[36,45],[37,71],[37,47],[38,41],[38,52],[38,53],[39,43],[39,91],[39,50],[40,44],[40,92],[40,51],[41,49],[41,57],[41,58],[42,59],[42,49],[42,60],[43,54],[43,93],[44,55],[44,94],[45,74],[46,52],[46,75],[47,76],[48,53],[48,77],[49,61],[49,62],[50,97],[50,63],[51,98],[51,64],[52,57],[52,78],[53,58],[53,79],[54,67],[54,99],[55,68],[55,100],[56,69],[56,65],[56,66],[57,61],[57,80],[58,62],[58,81],[59,82],[59,61],[60,62],[60,83],[61,84],[62,85],[63,101],[63,70],[64,102],[64,71],[65,72],[65,86],[66,73],[66,87],[67,75],[67,103],[68,77],[68,104],[69,88],[69,72],[69,73],[70,105],[70,74],[71,106],[71,76],[72,95],[72,89],[73,96],[73,90],
[74,107],[75,78],[75,108],[76,109],[77,79],[77,110],[78,80],[78,113],[79,81],[79,114],[80,84],[80,115],[81,85],[81,116],[82,117],[82,84],[83,85],[83,118],[84,119],[85,120],[86,89],[86,121],[87,90],[87,122],[88,123],[88,95],[88,96],[89,111],[89,124],[90,112],[90,125],[91,93],[91,183],[91,97],[92,94],[92,204],[92,98],[93,99],[93,182],[94,100],[94,203],[95,126],[95,111],[96,127],[96,112],[97,181],[97,101],[98,202],[98,102],[99,103],[99,180],[100,104],[100,201],[101,179],[101,105],[102,200],[102,106],[103,108],[103,178],[104,110],[104,199],[105,177],[105,107],[106,198],[106,109],[107,175],[108,113],[108,176],[109,196],[110,114],[110,197],[111,130],[111,132],[112,131],[112,133],[113,115],[113,174],[114,116],[114,195],[115,119],[115,173],[116,120],[116,194],[117,172],[117,119],[118,120],[118,193],[119,171],[120,192],[121,124],[121,170],[122,125],[122,191],[123,142],[123,126],[123,127],[124,132],[124,169],[125,133],[125,190],[126,144],[126,130],[127,145],[127,131],[128,162],[128,134],[128,129],[128,135],[129,136],[129,143],[129,137],[130,150],[130,148],[131,151],[131,149],[132,148],[132,168],[133,149],[133,189],[134,162],[134,138],[134,136],[135,162],[135,139],[135,137],[136,140],[136,146],[137,141],[137,147],[138,162],[138,154],[138,140],[139,162],[139,155],[139,141],[140,156],[140,152],
[141,157],[141,153],[142,143],[142,144],[142,145],[143,146],[143,147],[144,146],[144,150],[145,147],[145,151],[146,152],[147,153],[148,158],[148,167],[149,159],[149,188],[150,152],[150,158],[151,153],[151,159],[152,160],[153,161],[154,162],[154,166],[154,156],[155,162],[155,187],[155,157],[156,165],[156,160],[157,186],[157,161],[158,160],[158,164],[159,161],[159,185],[160,163],[161,184],[162,231],[162,238],[162,227],[162,211],[162,166],[162,187],[162,212],[162,228],[162,232],[163,165],[163,205],[163,164],[164,207],[164,167],[165,166],[165,209],[166,211],[167,217],[167,168],[168,233],[168,169],[169,241],[169,170],[170,244],[171,172],[171,246],[171,173],[172,248],[173,250],[173,174],[174,252],[174,176],[175,177],[175,256],[176,257],[176,178],[177,179],[177,260],[178,262],[178,180],[179,181],[179,264],[180,266],[180,182],[181,183],[181,268],[182,272],[182,183],[183,274],[184,186],[184,185],[184,206],[185,208],[185,188],[186,187],[186,210],[187,212],[188,189],[188,218],[189,190],[189,234],[190,191],[190,242],[191,245],[192,193],[192,194],[192,247],[193,249],[194,195],[194,251],[195,197],[195,253],[196,198],[196,258],[197,259],[197,199],[198,200],[198,261],[199,201],[199,263],[200,202],[200,265],[201,203],[201,267],[202,204],[202,269],[203,204],[203,273],[204,275],[205,209],[205,213],
[205,207],[206,210],[206,214],[206,208],[207,215],[207,217],[208,216],[208,218],[209,211],[209,225],[210,212],[210,226],[211,227],[212,228],[213,225],[213,219],[213,215],[214,226],[214,220],[214,216],[215,221],[215,235],[216,222],[216,236],[217,235],[217,233],[218,236],[218,234],[219,229],[219,223],[219,221],[220,230],[220,223],[220,222],[221,224],[221,239],[222,224],[222,240],[223,237],[223,224],[224,243],[225,227],[225,229],[226,228],[226,230],[227,231],[228,232],[229,231],[229,237],[230,232],[230,237],[231,238],[232,238],[233,254],[233,241],[234,255],[234,242],[235,239],[235,254],[236,240],[236,255],[237,238],[239,243],[239,270],[240,243],[240,271],[241,276],[241,244],[242,277],[242,245],[243,278],[244,279],[245,280],[246,248],[246,281],[246,250],[247,249],[247,282],[247,251],[248,283],[249,284],[250,285],[250,252],[251,286],[251,253],[252,287],[252,257],[253,288],[253,259],[254,270],[254,276],[255,271],[255,277],[256,260],[256,289],[257,290],[257,262],[258,261],[258,291],[259,292],[259,263],[260,264],[260,295],[261,265],[261,296],[262,298],[262,266],[263,299],[263,267],[264,268],[264,302],[265,269],[265,303],[266,311],[266,272],[267,312],[267,273],[268,274],[268,315],[269,275],[269,316],[270,278],[270,293],[271,278],[271,294],[272,322],[272,274],[273,323],[273,275],[274,326],
[275,327],[276,293],[276,279],[277,294],[277,280],[278,297],[279,300],[280,301],[281,283],[281,304],[281,285],[282,284],[282,305],[282,286],[283,306],[284,307],[285,308],[285,287],[286,309],[286,288],[287,313],[287,290],[288,314],[288,292],[289,295],[289,318],[290,319],[290,298],[291,296],[291,320],[292,321],[292,299],[293,297],[293,300],[294,297],[294,301],[295,302],[295,329],[296,303],[296,330],[297,310],[298,333],[298,311],[299,334],[299,312],[300,310],[301,310],[302,315],[302,336],[303,316],[303,337],[304,306],[304,317],[304,308],[305,307],[305,317],[305,309],[306,324],[307,324],[308,325],[308,313],[309,325],[309,314],[311,347],[311,322],[312,348],[312,323],[313,328],[313,319],[314,328],[314,321],[315,326],[315,350],[316,327],[316,351],[317,324],[317,325],[318,329],[318,331],[319,332],[319,333],[320,330],[320,331],[321,332],[321,334],[322,352],[322,326],[323,353],[323,327],[325,328],[326,355],[327,356],[328,332],[329,336],[329,335],[330,337],[330,335],[331,335],[332,338],[333,338],[333,347],[334,338],[334,348],[335,349],[336,350],[336,349],[337,351],[337,349],[338,354],[339,341],[339,368],[339,344],[340,342],[340,360],[340,345],[341,343],[341,365],[342,361],[342,343],[343,363],[344,366],[344,346],[345,346],[345,362],[346,364],[347,354],[347,352],[348,354],[348,353],[349,357],
[350,355],[350,357],[351,356],[351,357],[352,358],[352,355],[353,358],[353,356],[354,358],[355,359],[356,359],[357,359],[358,359],[360,361],[360,367],[360,362],[361,363],[361,369],[362,364],[362,370],[363,365],[363,372],[364,366],[364,373],[365,368],[365,376],[366,368],[366,377],[367,369],[367,371],[367,370],[368,380],[369,372],[369,374],[370,373],[370,375],[371,374],[371,381],[371,375],[372,376],[372,378],[373,377],[373,379],[374,378],[374,383],[375,379],[375,384],[376,380],[376,386],[377,380],[377,387],[378,386],[378,400],[379,387],[379,402],[380,392],[381,383],[381,384],[381,382],[382,393],[382,388],[382,394],[383,400],[383,393],[384,402],[384,394],[385,390],[385,389],[385,391],[386,392],[386,412],[387,392],[387,413],[388,395],[388,389],[388,396],[389,397],[389,398],[390,397],[390,399],[391,398],[391,401],[392,416],[393,403],[393,395],[394,404],[394,396],[395,407],[395,397],[396,408],[396,398],[397,405],[398,406],[399,405],[399,409],[400,412],[400,403],[401,406],[401,410],[402,413],[402,404],[403,417],[403,407],[404,418],[404,408],[405,407],[405,414],[406,408],[406,415],[407,419],[408,420],[409,414],[409,411],[410,415],[410,411],[411,421],[412,416],[412,417],[413,416],[413,418],[414,419],[414,421],[415,420],[415,421],[416,422],[417,422],[417,419],[418,422],[418,420],[419,423],
[420,423],[421,423],[422,423],[424,425],[424,440],[424,426],[425,427],[425,441],[426,428],[426,442],[427,429],[427,443],[428,430],[428,444],[429,431],[429,448],[430,431],[430,449],[431,450],[432,433],[432,445],[432,434],[433,446],[433,435],[434,447],[434,436],[435,452],[435,437],[436,453],[436,438],[437,458],[437,439],[438,459],[438,439],[439,462],[440,441],[440,451],[440,442],[441,443],[441,455],[442,444],[442,456],[443,448],[443,465],[444,449],[444,466],[445,446],[445,454],[445,447],[446,460],[446,452],[447,461],[447,453],[448,450],[448,471],[449,450],[449,472],[450,475],[451,455],[451,457],[451,456],[452,467],[452,458],[453,468],[453,459],[454,460],[454,457],[454,461],[455,465],[455,463],[456,466],[456,464],[457,463],[457,464],[458,473],[458,462],[459,474],[459,462],[460,463],[460,467],[461,464],[461,468],[462,476],[463,469],[464,470],[465,471],[465,469],[466,472],[466,470],[467,469],[467,473],[468,470],[468,474],[469,477],[470,478],[471,475],[471,477],[472,475],[472,478],[473,477],[473,476],[474,478],[474,476],[475,479],[476,479],[477,479],[478,479]
];
var shape_lor = [];
createLorenz();
var shape_msh = [
[-0.083,0.873,-0.076],[0.379,0.851,-0.102],[0.763,0.704,-0.125],[1.019,0.532,-0.142],[1.221,0.376,-0.155],[1.204,0.24,-0.157],[1.124,0.144,-0.154],[0.827,0.172,-0.137],[0.342,0.252,-0.11],[0.036,0.19,-0.094],[0.028,-0.055,-0.098],[0.221,-0.47,-0.115],[0.323,-0.759,-0.126],[0.234,-0.859,-0.122],[0.102,-0.87,-0.116],[-0.083,-0.864,-0.105],[0.311,0.848,0.093],[0.639,0.698,0.232],[0.858,0.524,0.323],[1.03,0.367,0.394],[1.016,0.231,0.386],[0.947,0.135,0.355],[0.695,0.166,0.246],[0.28,0.249,0.069],[0.019,0.19,-0.044],[0.012,-0.055,-0.051],[0.177,-0.472,0.013],[0.264,-0.762,0.045],[0.187,-0.862,0.011],[0.075,-0.871,-0.037],[0.192,0.846,0.183],[0.421,0.695,0.396],[0.574,0.521,0.537],[0.694,0.363,0.648],[0.684,0.227,0.636],[0.636,0.132,0.59],[0.46,0.163,0.424],[0.17,0.248,0.152],[-0.012,0.189,-0.021],[-0.016,-0.056,-0.029],[0.098,-0.473,0.072],[0.159,-0.763,0.124],[0.106,-0.863,0.072],[0.028,-0.872,-0.001],[0.048,0.844,0.338],[0.157,0.69,0.682],[0.23,0.515,0.909],[0.288,0.355,1.088],[0.283,0.219,1.071],[0.26,0.125,0.997],[0.176,0.158,0.731],[0.038,0.245,0.295],[-0.049,0.189,0.019],[-0.051,-0.056,0.008],[0.004,-0.475,0.175],[0.033,-0.765,0.261],[0.007,-0.864,0.179],[-0.03,-0.873,0.061],[-0.069,0.842,0.433],[-0.058,0.687,0.855],[-0.051,0.511,1.135],[-0.045,0.351,1.355],[-0.045,0.215,1.334],
[-0.048,0.121,1.244],[-0.056,0.154,0.917],[-0.07,0.244,0.382],[-0.079,0.188,0.044],[-0.079,-0.057,0.031],[-0.074,-0.476,0.237],[-0.071,-0.767,0.344],[-0.073,-0.865,0.244],[-0.077,-0.874,0.099],[-0.254,0.843,0.399],[-0.396,0.688,0.792],[-0.492,0.512,1.053],[-0.567,0.352,1.259],[-0.56,0.217,1.239],[-0.53,0.122,1.155],[-0.421,0.156,0.85],[-0.24,0.245,0.351],[-0.127,0.188,0.035],[-0.124,-0.057,0.023],[-0.195,-0.475,0.215],[-0.233,-0.766,0.315],[-0.2,-0.865,0.221],[-0.151,-0.873,0.085],[-0.375,0.845,0.27],[-0.619,0.692,0.557],[-0.782,0.517,0.747],[-0.91,0.359,0.896],[-0.9,0.223,0.881],[-0.849,0.128,0.819],[-0.661,0.16,0.597],[-0.352,0.247,0.232],[-0.158,0.189,0.002],[-0.153,-0.056,-0.008],[-0.276,-0.474,0.13],[-0.34,-0.764,0.202],[-0.283,-0.864,0.133],[-0.2,-0.873,0.034],[-0.454,0.847,0.141],[-0.763,0.696,0.32],[-0.97,0.523,0.438],[-1.132,0.365,0.531],[-1.119,0.229,0.521],[-1.054,0.133,0.481],[-0.815,0.164,0.342],[-0.424,0.249,0.114],[-0.178,0.189,-0.032],[-0.172,-0.056,-0.039],[-0.327,-0.473,0.045],[-0.409,-0.762,0.088],[-0.337,-0.862,0.044],[-0.232,-0.872,-0.018],[-0.486,0.85,-0.027],[-0.823,0.701,0.012],[-1.047,0.529,0.036],[-1.224,0.373,0.055],[-1.209,0.237,0.051],[-1.139,0.141,0.041],[-0.879,0.17,0.01],[-0.454,0.251,-0.041],[-0.187,0.19,-0.075],[-0.18,-0.055,-0.08],[-0.349,-0.471,-0.066],
[-0.438,-0.76,-0.06],[-0.359,-0.86,-0.071],[-0.245,-0.871,-0.086],[-0.482,0.854,-0.241],[-0.815,0.708,-0.38],[-1.037,0.538,-0.474],[-1.212,0.383,-0.549],[-1.198,0.247,-0.545],[-1.128,0.15,-0.518],[-0.871,0.177,-0.412],[-0.45,0.254,-0.238],[-0.186,0.191,-0.13],[-0.179,-0.054,-0.131],[-0.346,-0.468,-0.207],[-0.434,-0.757,-0.248],[-0.357,-0.858,-0.218],[-0.243,-0.869,-0.171],[-0.431,0.857,-0.428],[-0.722,0.714,-0.723],[-0.915,0.545,-0.921],[-1.068,0.392,-1.077],[-1.055,0.255,-1.067],[-0.995,0.158,-1.007],[-0.771,0.183,-0.781],[-0.403,0.257,-0.41],[-0.172,0.192,-0.178],[-0.167,-0.053,-0.176],[-0.312,-0.466,-0.33],[-0.389,-0.754,-0.413],[-0.322,-0.856,-0.346],[-0.223,-0.868,-0.246],[-0.281,0.858,-0.505],[-0.446,0.716,-0.864],[-0.557,0.548,-1.105],[-0.644,0.395,-1.296],[-0.636,0.259,-1.282],[-0.602,0.162,-1.209],[-0.474,0.186,-0.934],[-0.265,0.259,-0.481],[-0.134,0.192,-0.198],[-0.13,-0.053,-0.195],[-0.213,-0.465,-0.381],[-0.257,-0.753,-0.481],[-0.219,-0.855,-0.399],[-0.162,-0.867,-0.277],[-0.094,0.858,-0.52],[-0.104,0.717,-0.892],[-0.11,0.549,-1.141],[-0.115,0.396,-1.338],[-0.115,0.26,-1.324],[-0.113,0.162,-1.249],[-0.106,0.186,-0.963],[-0.093,0.259,-0.495],[-0.086,0.192,-0.202],[-0.085,-0.053,-0.199],[-0.09,-0.465,-0.391],[-0.093,-0.752,-0.494],[-0.091,-0.855,-0.409],[-0.087,-0.867,-0.284],
[0.062,0.857,-0.463],[0.182,0.715,-0.787],[0.262,0.547,-1.004],[0.325,0.393,-1.176],[0.32,0.257,-1.164],[0.295,0.16,-1.098],[0.202,0.184,-0.85],[0.05,0.258,-0.442],[-0.045,0.192,-0.187],[-0.048,-0.053,-0.185],[0.013,-0.466,-0.353],[0.044,-0.753,-0.443],[0.016,-0.855,-0.37],[-0.025,-0.868,-0.26],[0.231,0.856,-0.396],[0.492,0.713,-0.664],[0.666,0.544,-0.844],[0.803,0.39,-0.987],[0.791,0.254,-0.977],[0.737,0.157,-0.923],[0.536,0.182,-0.718],[0.206,0.257,-0.38],[-0.002,0.192,-0.17],[-0.007,-0.053,-0.169],[0.124,-0.467,-0.309],[0.193,-0.754,-0.384],[0.132,-0.856,-0.324],[0.043,-0.868,-0.234],[0.356,0.854,-0.283],[0.721,0.709,-0.458],[0.964,0.539,-0.575],[1.156,0.385,-0.668],[1.14,0.248,-0.663],[1.063,0.152,-0.629],[0.782,0.178,-0.496],[0.32,0.255,-0.277],[0.03,0.191,-0.141],[0.023,-0.054,-0.142],[0.206,-0.468,-0.235],[0.303,-0.756,-0.285],[0.218,-0.857,-0.247],[0.093,-0.869,-0.188]
];
var shape_msh_edges = [
[0,16],[1,16],[0,1],[16,17],[2,17],[1,2],[17,18],[3,18],[2,3],[18,19],[4,19],[3,4],[19,20],[5,20],[4,5],[20,21],[6,21],[5,6],[21,22],[7,22],[6,7],[22,23],[8,23],[7,8],[23,24],[9,24],[8,9],[24,25],[10,25],[9,10],[25,26],[11,26],[10,11],[26,27],[12,27],[11,12],[27,28],[13,28],[12,13],[28,29],[14,29],[13,14],[15,29],[14,15],[0,30],[16,30],[30,31],[17,31],[31,32],[18,32],[32,33],[19,33],[33,34],[20,34],[34,35],[21,35],[35,36],[22,36],[36,37],[23,37],[37,38],[24,38],[38,39],[25,39],[39,40],[26,40],[40,41],[27,41],[41,42],[28,42],[42,43],[29,43],[15,43],[0,44],[30,44],[44,45],[31,45],[45,46],[32,46],[46,47],[33,47],[47,48],[34,48],[48,49],[35,49],[49,50],[36,50],[50,51],[37,51],[51,52],[38,52],[52,53],[39,53],[53,54],[40,54],[54,55],[41,55],[55,56],[42,56],[56,57],[43,57],[15,57],[0,58],[44,58],[58,59],[45,59],[59,60],[46,60],[60,61],[47,61],[61,62],[48,62],[62,63],[49,63],[63,64],[50,64],[64,65],[51,65],[65,66],[52,66],[66,67],[53,67],[67,68],[54,68],[68,69],[55,69],[69,70],[56,70],[70,71],[57,71],[15,71],[0,72],[58,72],[72,73],[59,73],[73,74],[60,74],[74,75],[61,75],[75,76],[62,76],[76,77],[63,77],[77,78],[64,78],[78,79],[65,79],[79,80],[66,80],[80,81],[67,81],[81,82],[68,82],[82,83],[69,83],[83,84],[70,84],[84,85],[71,85],[15,85],[0,86],[72,86],[86,87],[73,87],[87,88],[74,88],[88,89],
[75,89],[89,90],[76,90],[90,91],[77,91],[91,92],[78,92],[92,93],[79,93],[93,94],[80,94],[94,95],[81,95],[95,96],[82,96],[96,97],[83,97],[97,98],[84,98],[98,99],[85,99],[15,99],[0,100],[86,100],[100,101],[87,101],[101,102],[88,102],[102,103],[89,103],[103,104],[90,104],[104,105],[91,105],[105,106],[92,106],[106,107],[93,107],[107,108],[94,108],[108,109],[95,109],[109,110],[96,110],[110,111],[97,111],[111,112],[98,112],[112,113],[99,113],[15,113],[0,114],[100,114],[114,115],[101,115],[115,116],[102,116],[116,117],[103,117],[117,118],[104,118],[118,119],[105,119],[119,120],[106,120],[120,121],[107,121],[121,122],[108,122],[122,123],[109,123],[123,124],[110,124],[124,125],[111,125],[125,126],[112,126],[126,127],[113,127],[15,127],[0,128],[114,128],[128,129],[115,129],[129,130],[116,130],[130,131],[117,131],[131,132],[118,132],[132,133],[119,133],[133,134],[120,134],[134,135],[121,135],[135,136],[122,136],[136,137],[123,137],[137,138],[124,138],[138,139],[125,139],[139,140],[126,140],[140,141],[127,141],[15,141],[0,142],[128,142],[142,143],[129,143],[143,144],[130,144],[144,145],[131,145],[145,146],[132,146],[146,147],[133,147],[147,148],[134,148],[148,149],[135,149],[149,150],[136,150],[150,151],[137,151],[151,152],[138,152],[152,153],[139,153],[153,154],[140,154],[154,155],[141,155],
[15,155],[0,156],[142,156],[156,157],[143,157],[157,158],[144,158],[158,159],[145,159],[159,160],[146,160],[160,161],[147,161],[161,162],[148,162],[162,163],[149,163],[163,164],[150,164],[164,165],[151,165],[165,166],[152,166],[166,167],[153,167],[167,168],[154,168],[168,169],[155,169],[15,169],[0,170],[156,170],[170,171],[157,171],[171,172],[158,172],[172,173],[159,173],[173,174],[160,174],[174,175],[161,175],[175,176],[162,176],[176,177],[163,177],[177,178],[164,178],[178,179],[165,179],[179,180],[166,180],[180,181],[167,181],[181,182],[168,182],[182,183],[169,183],[15,183],[0,184],[170,184],[184,185],[171,185],[185,186],[172,186],[186,187],[173,187],[187,188],[174,188],[188,189],[175,189],[189,190],[176,190],[190,191],[177,191],[191,192],[178,192],[192,193],[179,193],[193,194],[180,194],[194,195],[181,195],[195,196],[182,196],[196,197],[183,197],[15,197],[0,198],[184,198],[198,199],[185,199],[199,200],[186,200],[200,201],[187,201],[201,202],[188,202],[202,203],[189,203],[203,204],[190,204],[204,205],[191,205],[205,206],[192,206],[206,207],[193,207],[207,208],[194,208],[208,209],[195,209],[209,210],[196,210],[210,211],[197,211],[15,211],[0,212],[198,212],[212,213],[199,213],[213,214],[200,214],[214,215],[201,215],[215,216],[202,216],[216,217],[203,217],[217,218],[204,218],[218,219],
[205,219],[219,220],[206,220],[220,221],[207,221],[221,222],[208,222],[222,223],[209,223],[223,224],[210,224],[224,225],[211,225],[15,225],[1,212],[2,213],[3,214],[4,215],[5,216],[6,217],[7,218],[8,219],[9,220],[10,221],[11,222],[12,223],[13,224],[14,225]
];
var shape_csm = [];
var shape_csm_edges = [];
var rotationMatrix = [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]
];
function createLorenz() {
var q = 28;
var w = 10;
var b = 8/3;
var dt = 0.005;
var skips = 5;
var p = [1, 1, 1];
for (var f=0; f<3000; f++) {
//push to array
if (f % skips == 0) {
shape_lor.push([p[0], p[1], p[2]]);
}
//iterate
[p[0], p[1], p[2]] = [
p[0] + (w * (p[1] - p[0])) * dt,
p[1] + (p[0] * (q - p[2]) - p[1]) * dt,
p[2] + (p[0] * p[1] - b * p[2]) * dt
];
}
}
function createRotationMatrix(theta, phi) {
return [
polToCart(theta + (Math.PI / 2), 0, 1),
polToCart(theta, phi + (Math.PI / 2), 1),
polToCart(theta, phi, 1),
];
}
function createTorus() {
for (var q=0; q<maxQ; q++) {
var offset = polToCart(Math.PI * 2 * q / maxQ, 0, 1);
for (var k=0; k<maxK; k++) {
shape_tor.push(polToCart(Math.PI * 2 * q / maxQ, Math.PI * 2 * k / maxK, 0.3));
shape_tor[shape_tor.length-1][0] += offset[0];
shape_tor[shape_tor.length-1][2] += offset[2];
}
}
}
function drawTetrahedron() {
var pts = shape_tet.map(a => spaceToScreen(...a));
ctx.strokeStyle = color_cube;
//all points connect to each other once
drawLine(pts[0], pts[1]);
drawLine(pts[0], pts[2]);
drawLine(pts[0], pts[3]);
drawLine(pts[1], pts[2]);
drawLine(pts[1], pts[3]);
drawLine(pts[2], pts[3]);
}
function drawCube() {
//draw points
var pts = shape_hex.map(a => spaceToScreen(...a));
//01 12 23 30 45 56 67 74 04 15 26 37
ctx.strokeStyle = color_cube;
drawLine(pts[0], pts[1]);
drawLine(pts[1], pts[2]);
drawLine(pts[2], pts[3]);
drawLine(pts[3], pts[0]);
drawLine(pts[4], pts[5]);
drawLine(pts[5], pts[6]);
drawLine(pts[6], pts[7]);
drawLine(pts[7], pts[4]);
drawLine(pts[0], pts[4]);
drawLine(pts[1], pts[5]);
drawLine(pts[2], pts[6]);
drawLine(pts[3], pts[7]);
}
function drawOctohedron() {
var pts = shape_oct.map(a => spaceToScreen(...a));
//middle lines
drawLine(pts[0], pts[1]);
drawLine(pts[1], pts[2]);
drawLine(pts[2], pts[3]);
drawLine(pts[3], pts[0]);
//connect to top / connect to bottom
for (var a=0; a<4; a++) {
drawLine(pts[a], pts[4]);
drawLine(pts[a], pts[5]);
}
}
function drawDodecahedron() {
var pts = shape_dod.map(a => spaceToScreen(...a));
//it's a mess but that's ok sometimes.
//not in this instance. In this instance I am fully aware it's not ok
//drawing cube-bar connections
drawLine(pts[1], pts[13]);
drawLine(pts[1], pts[10]);
drawLine(pts[1], pts[18]);
drawLine(pts[2], pts[10]);
drawLine(pts[2], pts[14]);
drawLine(pts[2], pts[19]);
drawLine(pts[3], pts[9]);
drawLine(pts[3], pts[19]);
drawLine(pts[3], pts[15]);
drawLine(pts[4], pts[9]);
drawLine(pts[4], pts[16]);
drawLine(pts[4], pts[18]);
drawLine(pts[5], pts[12]);
drawLine(pts[5], pts[13]);
drawLine(pts[5], pts[17]);
drawLine(pts[6], pts[12]);
drawLine(pts[6], pts[14]);
drawLine(pts[6], pts[20]);
drawLine(pts[7], pts[11]);
drawLine(pts[7], pts[15]);
drawLine(pts[7], pts[20]);
drawLine(pts[8], pts[11]);
drawLine(pts[8], pts[16]);
drawLine(pts[8], pts[17]);
//drawing all bars
drawLine(pts[9], pts[10]);
drawLine(pts[11], pts[12]);
drawLine(pts[13], pts[14]);
drawLine(pts[15], pts[16]);
drawLine(pts[17], pts[18]);
drawLine(pts[19], pts[20]);
}
function drawIcosahedron() {
var pts = shape_ico.map(a => spaceToScreen(...a));
//top to top layer
for (var v=1; v<=5; v++) {
drawLine(pts[0], pts[v]);
}
//top layer circle
for (var v=0; v<=4; v++) {
drawLine(pts[v+1], pts[((v+1)%5)+1]);
}
//top layer to lower layer
for (var v=0; v<=4; v++) {
drawLine(pts[v+1], pts[((v+1)%5)+6]);
drawLine(pts[v+1], pts[v+6]);
}
//lower layer circle
for (var v=0; v<=4; v++) {
drawLine(pts[v+6], pts[((v+1)%5)+6]);
}
//lower layer to bottom
for (var v=6; v<=10; v++) {
drawLine(pts[11], pts[v]);
}
}
function drawTorus() {
var pts = shape_tor.map(a => spaceToScreen(...a));
for (var q=0; q<maxQ; q++) {
for (var k=0; k<maxK; k++) {
//around line
drawLine(pts[q*maxK + k], pts[q*maxK + ((k+1) % maxK)]);
//forwards line
drawLine(pts[q*maxK + k], pts[((q+1) % maxQ)*maxK + k]);
}
}
}
function drawTeapot() {
var pts = shape_tea.map(a => spaceToScreen(...a));
shape_tea_edges.forEach(c => {
drawLine(pts[c[0]], pts[c[1]]);
});
}
function drawLorenz() {
var pts = shape_lor.map(a => spaceToScreen(...a));
for (var k=1; k<pts.length; k++) {
drawLine(pts[k], pts[k-1]);
}
//make new linies
var q = 28;
var w = 10;
var b = 8/3;
var dt = 0.005;
var skips = 5;
var p = JSON.parse(JSON.stringify(shape_lor[shape_lor.length-1]));
for (var f=0; f<=skips; f++) {
//iterate
[p[0], p[1], p[2]] = [
p[0] + (w * (p[1] - p[0])) * dt,
p[1] + (p[0] * (q - p[2]) - p[1]) * dt,
p[2] + (p[0] * p[1] - b * p[2]) * dt
];
//push to array
if (f % skips == 0) {
shape_lor.splice(0, 1);
shape_lor.push([p[0], p[1], p[2]]);
}
}
}
function drawMushroom() {
var pts = shape_msh.map(a => spaceToScreen(...a));
shape_msh_edges.forEach(c => {
drawLine(pts[c[0]], pts[c[1]]);
});
}
function drawCustom() {
var pts = shape_csm.map(a => spaceToScreen(...a));
shape_csm_edges.forEach(c => {
drawLine(pts[c[0]], pts[c[1]]);
});
}
function drawLine(p1, p2) {
ctx.beginPath();
ctx.moveTo(p1[0], p1[1]);
ctx.lineTo(p2[0], p2[1]);
ctx.stroke();
}
function file_import() {
//file reference
var newFile = document.getElementById('uploadBox').files[0];
//read the file in, this is asynchronous
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent) {
shape_csm = [];
shape_csm_edges = [];
//function for when the text actually loads
var textDat = fileLoadedEvent.target.result;
//remove annoying formatting bits
//why are these here in the first place?
textDat = textDat.replaceAll("\r", "");
textDat = textDat.replaceAll("\t", " ");
var lines = textDat.split("\n");
//first line will probably be OFF, and can be ignored. This is optional so I have to check for it
if (lines[0] == "4OFF") {
console.error(`Can't read in 4 dimensional shapes!`);
return;
}
//remove all whitespace / comment lines by only including lines with numbers
lines = lines.filter(a => /\d/.test(a));
//removing trailing / leading spaces, as well as comments
for (var a=0; a<lines.length; a++) {
lines[a] = lines[a].replaceAll(/#.*/g, "");
if (lines[a][0] == " ") {
lines[a] = lines[a].slice(1);
}
while (lines[a][lines[a].length-1] == " ") {
lines[a] = lines[a].slice(0, lines[a].length - 1);
}
lines[a] = lines[a].replaceAll(/ +/g, " ");
}
//first line is in the format [number of vertices] [number of faces] [number of edges]
//I don't care about the last two, but the first two tell me how many lines it'll be until the format switches, which is useful
var buffer1 = lines[0];
buffer1 = +buffer1.split(" ")[0];
lines.splice(0, 1);
//gathering vertices
var vertices = lines.slice(0, buffer1);
vertices = vertices.map(a => a.split(" "));
vertices = vertices.map(a => [+a[0], +a[1], +a[2]]);
//center the vertices on the origin by first getting the bounds and then subtracting those bounds
var offsetX = (vertices.reduce((a, b) => Math.min(a, b[0]), 1e1001) + vertices.reduce((a, b) => Math.max(a, b[0]), -1e1001)) / 2;
var offsetY = (vertices.reduce((a, b) => Math.min(a, b[1]), 1e1001) + vertices.reduce((a, b) => Math.max(a, b[1]), -1e1001)) / 2;
var offsetZ = (vertices.reduce((a, b) => Math.min(a, b[2]), 1e1001) + vertices.reduce((a, b) => Math.max(a, b[2]), -1e1001)) / 2;
//var scaleFactor =(Math.abs(camera.z) - 1) * maxSize;
shape_csm = vertices = vertices.map(a => [a[0] - offsetX, a[1] - offsetY, a[2] - offsetZ]);
//gathering edge data, this should be the rest of the file after the vertices
lines = lines.slice(buffer1);
lines = lines.map(a => JSON.parse(`[${a.replaceAll(" ", ",")}]`));
var edges = [];
var buffer2 = [];
//go through each face and convert it to a set of lines
lines.forEach(q => {
var numEdges = q[0];
var tempEdges = [];
for (var p=2; p<=numEdges; p++) {
tempEdges.push(q.slice(p-1, p+1));
}
tempEdges.push([q[1], q[numEdges]]);
for (var a=0; a<tempEdges.length; a++) {
//make sure the edges are always ordered least->greatest
if (tempEdges[a][1] < tempEdges[a][0]) {
[tempEdges[a][0], tempEdges[a][1]] = [tempEdges[a][1], tempEdges[a][0]];
}
}
tempEdges.forEach(l => {
var hash = "" + l;
if (buffer2.indexOf(hash) == -1) {
buffer2.push(hash);
edges.push(l);
}
});
});
shape_csm_edges = edges;
};
fileReader.readAsText(newFile, "UTF-8");
}
function handleKeyPress(a) {
if (a.code.indexOf("Digit") == 0) {
var number = +a.code.slice(5);
if (number == 9 && shape_active != 9) {
//request input
document.getElementById("uploadBox").click();
}
if (number < shapes.length) {
shape_active = number;
}
}
}
function handleScroll(a) {
camera.z = Math.min(Math.max(camera.z * (1 + a.deltaY / -100), camera.zMin), camera.zMax);
}
function main() {
//bg
ctx.fillStyle = color_bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
switch (shapes[shape_active]) {
case "tetrahedron":
drawTetrahedron();
break;
case "hexahedron":
drawCube();
break;
case "octohedron":
drawOctohedron();
break;
case "dodecahedron":
drawDodecahedron();
break;
case "icosahedron":
drawIcosahedron();
break;
case "torus":
drawTorus();
break;
case "teapot":
drawTeapot();
break;
case "lorenz":
drawLorenz();
break;
case "mushroom":
drawMushroom();
break;
case "custom":
drawCustom();
break;
}
rotateShape();
//call self
window.requestAnimationFrame(main);
}
function rotateShape() {
var activeArr;
switch (shapes[shape_active]) {
case "tetrahedron":
activeArr = shape_tet;
break;
case "hexahedron":
activeArr = shape_hex;
break;
case "octohedron":
activeArr = shape_oct;
break;
case "dodecahedron":
activeArr = shape_dod;
break;
case "icosahedron":
activeArr = shape_ico;
break;
case "torus":
activeArr = shape_tor;
break;
case "teapot":
activeArr = shape_tea;
break;
case "lorenz":
activeArr = shape_lor;
break;
case "mushroom":
activeArr = shape_msh;
break;
case "custom":
activeArr = shape_csm;
break;
}
for (var p=0; p<activeArr.length; p++) {
activeArr[p] = rotatePointByMatrix(activeArr[p], rotationMatrix);
}
}
function rotatePointByMatrix(point, matrix) {
return [
point[0] * matrix[0][0] + point[1] * matrix[1][0] + point[2] * matrix[2][0],
point[0] * matrix[0][1] + point[1] * matrix[1][1] + point[2] * matrix[2][1],
point[0] * matrix[0][2] + point[1] * matrix[1][2] + point[2] * matrix[2][2]
];
}
function setup() {
canvas = document.getElementById("can");
ctx = canvas.getContext("2d");
rotationMatrix = createRotationMatrix(Math.PI / -160, Math.PI / 250);
window.requestAnimationFrame(main);
}
function spaceToScreen(x, y, z) {
x -= camera.x;
y -= camera.y;
z -= camera.z;
x /= z;
y /= z;
x *= camera.scale;
y *= -camera.scale;
x += canvas.width / 2;
y += canvas.height / 2;
return [x, y];
}
</script>
<body>
<canvas id="can" width="640" height="480"></canvas>
<p id="centerPara">Press the number keys to change the shape!<br>
Scroll up / down to zoom in / out, and pressing number 9 will allow you to import your<br> own 3d models, as long as they are in .OFF.
</p>
<input type="file" id="uploadBox" onChange="file_import();">
</body>
</html>