-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
131 lines (111 loc) · 3.44 KB
/
index.ts
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
import p5 = require("p5");
const {dialog} = require("electron").remote;
//@ts-ignore
p5.RendererGL.prototype._initContext = function() {
this.attributes.antialias = true;
try {
this.drawingContext =
this.canvas.getContext('webgl', this.attributes) ||
this.canvas.getContext('experimental-webgl', this.attributes);
if (this.drawingContext === null) {
throw new Error('Error creating webgl context');
} else {
console.log('p5.RendererGL: enabled webgl context');
var gl = this.drawingContext;
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
this._viewport = this.drawingContext.getParameter(
this.drawingContext.VIEWPORT
);
}
} catch (er) {
throw er;
}
};
var num = 15;
var mid = num/2;
var distance = 2.5*num;
var colorScale = 255/num;
var parent = document.getElementById('vis')!;
var sketch = (p: p5) => {
let yaw = 0;
let pitch = 0;
p.setup = ()=>{
let size = getSize();
p.createCanvas(size,size,p.WEBGL);
p.angleMode("radians");
p.stroke(255);
p.noStroke();
pitch = p.radians(-30);
yaw = p.radians(-30);
}
p.draw = ()=>{
p.clear();
p.perspective(p.radians(40),1,0.1,500);
p.camera(mid, mid, mid+distance, mid, mid, mid, 0, 1, 0);
p.translate(mid, mid, mid);
p.rotateY(yaw);
p.rotate(pitch, p.createVector(p.cos(yaw),0,p.sin(yaw)));
p.translate(-mid, -mid-distance/16, -mid);
p.stroke(255,200);
p.strokeWeight(num*0.0075);
p.noFill();
p.line(0,0,0,num,0,0);
p.line(0,0,0,0,num,0);
p.line(0,0,0,0,0,num);
p.line(num,0,0,num,num,0);
p.line(num,0,0,num,0,num);
p.line(0,num,0,num,num,0);
p.line(0,num,0,0,num,num);
p.line(0,0,num,num,0,num);
p.line(0,0,num,0,num,num);
p.line(0,0,num,num,0,num);
p.line(num,num,num,0,num,num);
p.line(num,num,num,num,0,num);
p.line(num,num,num,num,num,0);
p.noStroke();
for(let x = 0; x <= num; x++) {
for(let y = 0; y <= num; y++){
for(let z = 0; z <= num; z++){
p.fill(x*colorScale, y*colorScale, z*colorScale);
// p.point(x, y, z);
p.translate(x,num-y,z);
p.sphere(0.2, 6, 4);
p.translate(-x,y-num,-z);
}
}
}
p.noLoop();
}
}
var sketchp5 = new p5(sketch, parent);
function getSize(){
return Math.min(parent.clientWidth, parent.clientHeight);
}
var timeout: NodeJS.Timeout;
function updateSize(){
clearTimeout(timeout);
let size = getSize();
sketchp5.resizeCanvas(size, size, true);
timeout = setTimeout(()=>{
sketchp5.redraw();
}, 100);
}
window.onresize = updateSize;
var fileInput = <HTMLInputElement> document.getElementById('file')!;
fileInput.addEventListener("change", async ()=>{
});
var inputType = <HTMLSelectElement> document.getElementById('inputType')!;
updateFilter();
function updateFilter(){
switch(inputType.value){
case "image":
fileInput.accept = ".png";
break;
case "cube":
fileInput.accept = ".cube";
break;
}
}
export = undefined;