forked from binarymax/guilloche
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguilloche3d.js
158 lines (127 loc) · 5.53 KB
/
guilloche3d.js
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
Math.tau = Math.PI*2;
var Guilloche = (function(){
var _step = 0.0001;
var _zoom = 5;
var geobuffer = function(pos0,pos1,pos2) {
return function(R,r,p,step,zoom){
step = step || _step;
zoom = zoom || _zoom;
var size = Math.floor(Math.tau/step);
var geometry = new THREE.BufferGeometry();
var positions = new Float32Array(size * 3);
var thetas = new Float32Array(size);
var rr = R+r;
var rp = r+p;
var rrr = (R+r)/r;
for(var theta=0,x=0,y=0,i=0;i<size;i++) {
thetas[i] = theta;
positions[i+0] = pos0(rr,rp,rrr,theta,zoom);
positions[i+1] = pos1(rr,rp,rrr,theta,zoom);
positions[i+2] = pos2(rr,rp,rrr,theta,zoom);
theta+=step;
}
geometry.addAttribute('position',new THREE.BufferAttribute(positions,3));
geometry.addAttribute('theta',new THREE.BufferAttribute(thetas,1));
return geometry;
}
}
//------------------------------------------------------
//A rosette!
var rosette = geobuffer(
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.cos(theta)) + (rp*Math.cos(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) - (rp*Math.sin(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) + (rp*Math.cos(rrr*theta))) * zoom;}
);
rosette.shader =
"rr*cos(theta) + rp*cos(rrr*theta) * zoom,"+
"rr*sin(theta) - rp*sin(rrr*theta) * zoom,"+
"rr*sin(theta) + rp*cos(rrr*theta) * zoom";
//------------------------------------------------------
//A shell!
var shell = geobuffer(
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.cos(theta)) + (rp*Math.cos(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) + (rp*Math.sin(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.tan(theta)) + (rp*Math.tan(rrr*theta))) * zoom;}
);
shell.shader =
"rr*cos(theta) + rp*cos(rrr*theta) * zoom,"+
"rr*sin(theta) + rp*sin(rrr*theta) * zoom,"+
"rr*tan(theta) + rp*tan(rrr*theta) * zoom";
//------------------------------------------------------
//A cylinder!
var cylinder = geobuffer(
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.cos(theta)) + (rp*Math.sin(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) - (rp*Math.sin(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.cos(theta)) + (rp*Math.cos(rrr*theta))) * zoom;}
);
cylinder.shader =
"rr*cos(theta) + rp*sin(rrr*theta) * zoom,"+
"rr*sin(theta) - rp*sin(rrr*theta) * zoom,"+
"rr*cos(theta) + rp*cos(rrr*theta) * zoom";
//------------------------------------------------------
//A ribbon!
var ribbon = geobuffer(
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.tan(theta)) + (rp*Math.tan(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) - (rp*Math.cos(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.tan(theta)) + (rp*Math.sin(rrr*theta))) * zoom;}
);
ribbon.shader =
"rr*tan(theta) + rp*tan(rrr*theta) * zoom,"+
"rr*sin(theta) - rp*cos(rrr*theta) * zoom,"+
"rr*tan(theta) + rp*sin(rrr*theta) * zoom";
//------------------------------------------------------
//A river!
var river = geobuffer(
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.tan(theta)) + (rp*Math.tan(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) - (rp*Math.sin(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.tan(theta)) + (rp*Math.cos(rrr*theta))) * zoom;}
);
river.shader =
"rr*tan(theta) + rp*tan(rrr*theta) * zoom,"+
"rr*sin(theta) - rp*sin(rrr*theta) * zoom,"+
"rr*tan(theta) + rp*cos(rrr*theta) * zoom";
//------------------------------------------------------
//A cross!
var cross = geobuffer(
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) + (rp*Math.tan(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.tan(theta)) - (rp*Math.sin(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) + (rp*Math.cos(rrr*theta))) * zoom;}
);
cross.shader =
"rr*sin(theta) + rp*tan(rrr*theta) * zoom,"+
"rr*tan(theta) - rp*sin(rrr*theta) * zoom,"+
"rr*sin(theta) + rp*cos(rrr*theta) * zoom";
//------------------------------------------------------
//A knee!
var knee = geobuffer(
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.cos(theta)) + (rp*Math.cos(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) - (rp*Math.tan(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.cos(theta)) + (rp*Math.sin(rrr*theta))) * zoom;}
);
knee.shader =
"rr*cos(theta) + rp*cos(rrr*theta) * zoom,"+
"rr*sin(theta) - rp*tan(rrr*theta) * zoom,"+
"rr*cos(theta) + rp*sin(rrr*theta) * zoom";
//------------------------------------------------------
//A donut!
var donut = geobuffer(
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.cos(theta)) + (rp*Math.sin(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) + (rp*Math.sin(rrr*theta))) * zoom;},
function(rr,rp,rrr,theta,zoom) { return ((rr*Math.sin(theta)) + (rp*Math.cos(rrr*theta))) * zoom;}
);
donut.shader =
"rr*cos(theta) + rp*sin(rrr*theta) * zoom,"+
"rr*sin(theta) + rp*sin(rrr*theta) * zoom,"+
"rr*sin(theta) + rp*cos(rrr*theta) * zoom";
//------------------------------------------------------
return {
cylinder:cylinder,
rosette:rosette,
ribbon:ribbon,
river:river,
cross:cross,
knee:knee,
shell:shell,
donut:donut
}
})();