-
Notifications
You must be signed in to change notification settings - Fork 3
/
glot.html
402 lines (343 loc) · 12.9 KB
/
glot.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
<!DOCTYPE html>
<html>
<head>
<!--
This is a very early version of what will become WebGLot - a WebGL-
based plotting library for mathematical primitives.
-->
<title>WebGLot Alpha</title>
<!--
This is a matrix library I have been using for the time being, though
I may move to something more standard. I originally got this code from
http://webkit.org/blog/603/webgl-now-available-in-webkit-nightlies/
-->
<script src="CanvasMatrix.js"> </script>
<!--
These are the class files used in WebGLot. I'm not really an expert
in JavaScript, and would prefer an analog to the #include macro in
C++ for this task so that only one script must be included. For the
time being, just copy-and-paste this.
-->
<script src="emptytexture.js"> </script>
<script src="texture.js"> </script>
<script src="ray.js"> </script>
<script src="primitive.js"> </script>
<script src="datasurface.js"> </script>
<script src="box.js"> </script>
<script src="pde3d.js"> </script>
<script src="pde.js"> </script>
<script src="ftexture.js"> </script>
<script src="nurbs.js"> </script>
<script src="noisetexture.js"> </script>
<script src="flow.js"> </script>
<script src="sphere.js"> </script>
<script src="stopwatch.js"> </script>
<script src="screen.js"> </script>
<script src="surface.js"> </script>
<script src="p_surface.js"> </script>
<script src="grapher.js"> </script>
<script src="isosurface.js"> </script>
<script>
var glot = null;
function keyboard(key_event) {
var key = Number(key_event.keyCode);
if (key == 65) {
glot.set("isovalue", glot.get("isovalue") + 0.01);
glot.display();
} else if (key == 90) {
glot.set("isovalue", glot.get("isovalue") - 0.01);
glot.display();
}
}
var mySurface = null;
function gen_isosurface(string) {
if (mySurface) {
glot.primitives.pop();
mySurface = new isosurface(document.forms["function"].elements.fn.value);
glot.add(mySurface);
} else {
mySurface = new isosurface(document.forms["function"].elements.fn.value);
glot.add(mySurface);
}
glot.restart();
}
function start() {
/* Instantiate a grapher
*
* In the C++ version, it's a singleton, and so it's possible that
* this interface will change, so use with caution.
*/
glot = new grapher();
glot.setKeyboardFunction(keyboard);
glot.setDomain(-2, 2, -2, 2);
//glot.set("alpha", 0.5);
/*
glot.set("isovalue", 0.2);
glot.set("width", 256);
glot.set("height", 256);
glot.set("b_width", 8);
glot.set("b_height", 8);
glot.add(new datasurface("volumes/orange.png", 256, 256, 8, 8));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 256);
glot.set("height", 256);
glot.set("b_width", 20);
glot.set("b_height", 12);
glot.add(new datasurface("volumes/ct-chest-small.png", 256, 256, 20, 12));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 256);
glot.set("height", 256);
glot.set("b_width", 16);
glot.set("b_height", 16);
glot.add(new datasurface("volumes/foot.png", 256, 256, 16, 16));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 256);
glot.set("height", 256);
glot.set("b_width", 13);
glot.set("b_height", 12);
glot.add(new datasurface("volumes/bruce.png", 256, 256, 13, 12));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 256);
glot.set("height", 256);
glot.set("b_width", 11);
glot.set("b_height", 10);
glot.add(new datasurface("volumes/cadaver-small.png", 256, 256, 11, 10));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 32);
glot.set("height", 32);
glot.set("b_width", 6);
glot.set("b_height", 6);
glot.add(new datasurface("volumes/bucky.png", 32, 32, 6, 6));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 192);
glot.set("height", 180);
glot.set("b_width", 14);
glot.set("b_height", 12);
glot.add(new datasurface("volumes/daisy.png", 192, 180, 14, 12));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 256);
glot.set("height", 256);
glot.set("b_width", 9);
glot.set("b_height", 5);
glot.add(new datasurface("volumes/frog.png", 256, 256, 9, 5));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 301);
glot.set("height", 324);
glot.set("b_width", 8);
glot.set("b_height", 7);
glot.add(new datasurface("volumes/lobster.png", 301, 324, 8, 7));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 64);
glot.set("height", 64);
glot.set("b_width", 8);
glot.set("b_height", 8);
glot.add(new datasurface("volumes/neghip.png", 64, 64, 8, 8));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 256);
glot.set("height", 256);
glot.set("b_width", 14);
glot.set("b_height", 10);
glot.add(new datasurface("volumes/pig-small.png", 256, 256, 14, 10));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 176);
glot.set("height", 176);
glot.set("b_width", 16);
glot.set("b_height", 16);
glot.add(new datasurface("volumes/sheep-small.png", 176, 176, 16, 16));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 512);
glot.set("height", 512);
glot.set("b_width", 8);
glot.set("b_height", 8);
glot.add(new datasurface("volumes/teddy.png", 512, 512, 8, 8));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 256);
glot.set("height", 256);
glot.set("b_width", 8);
glot.set("b_height", 8);
glot.add(new datasurface("volumes/tomato.png", 256, 256, 8, 8));
//*/
/*
glot.set("isovalue", 0.2);
glot.set("width", 256);
glot.set("height", 256);
glot.set("b_width", 16);
glot.set("b_height", 16);
glot.add(new datasurface("volumes/engine.png", 256, 256, 16, 16));
//*/
// You can add new primitives to the display with the add function.
// The unit sphere
//glot.add(new isosurface("sqrt(x * x + y * y + z * z)"));
// The unit cylinder
//glot.add(new isosurface("sqrt(x * x + y * y) - 1.0"));
// A sinusodal lathe
//glot.add(new isosurface("abs(sin(z - t)) - sqrt(x * x + y * y)"));
//glot.add(new isosurface("1.0 - sin(z) + cos(sqrt(x * x + y * y + sin(t)))"));
/* Test surface - cylinder
glot.add(new p_surface("6.3 * u, 1.0, 3.0 * v - 1.5", CYLINDRICAL));
//*/
/* Test surface - sphere
glot.add(new p_surface("1.0, 3.14159265 * u, 6.3 * v", SPHERICAL));
//*/
/* Test surface - Grapher's example conchoid
glot.set("k", 1.2);
glot.set("k2", 1.2);
glot.set("a", 1.5);
glot.add(new p_surface("pow(k, u)*(1.0 + cos(v))*cos(u), pow(k, u)*(1.0 + cos(v))*sin(u), pow(k, u) * sin(v) - a * pow(k2, u)", 0, Math.PI, 0, 2 * Math.PI));
//*/
//glot.add(new surface("sin(x * x + y * y - 1.3 * t) + cos((x - 1.5) * (x - 1.5) + (y - 0.7) * (y - 0.7) + 1.7 * t)"));
glot.add(new sphere(0, 0, 0, 1));
glot.add(new sphere(0, 1, 1, 0.2));
/*
// Epicycloid
glot.set("R", 6.0);
glot.set("r", 1.0);
glot.add(new p_surface("(R + cos(u / 3.0) * (2.0 * r * cos(v) + r * cos(2.0 * v)) + sin(u / 3.0) * (2.0 * r * sin(v) - r * sin(2.0 * v))) * cos(u), (R + cos(u / 3.0) * (2.0 * r * cos(v) + r * cos(2.0 * v)) + sin(u / 3.0) * (2.0 * r * sin(v) - r * sin(2.0 * v))) * sin(u), (R - sin(u / 3.0) * (2.0 * r * cos(v) + r * cos(2.0 * v)) + cos(u / 3.0) * (2.0 * r * sin(v) - r * sin(2.0 * v)))", 0, 2 * Math.PI, 0, 2 * Math.PI))
// s = u
// a = v
glot.add(new p_surface("(R + cos(3.0 * u) * (2.0 * r * cos(v) - r * cos(2.0 * v)) + sin(3.0 * u) * (2.0 * r * sin(v) - r * sin(2.0 * v))) * cos(u) + 7.0, (R - sin(3.0 * u) * (2.0 * r * cos(v) - r * cos(2.0 * v)) + cos(3.0 * u) * (2.0 * r * sin(v) - r * sin(2.0 * v))) - 6.0, (R + cos(3.0 * u) * (2.0 * r * cos(v) - r * cos(2.0 * v)) + sin(3.0 * u) * (2.0 * r * sin(v) - r * sin(2.0 * v))) * sin(u) + 6.0", 0, 2 * Math.PI, 0, 2 * Math.PI));
//*/
/* Test surface - a funky "sphere" - a sphere with changing radius.
// You can have a lot of fun with it.
glot.set("a", 0.4);
glot.set("b", 1.2);
glot.add(new p_surface("2.0 * abs(cos(v * u) * sin(b * v * u)), u, a * v / 3.0", 0, Math.PI, 0, 2 * Math.PI, SPHERICAL));
//*/
/*
glot.set("a", 1.0);
glot.set("b", 1.0);
glot.add(new p_surface("2.0 + 0.5 * sin(a * u) * sin(b * v), u, v", 0, Math.PI, 0, 2 * Math.PI, SPHERICAL));
//*/
/* Test surface - a cylinder with isosurfacing
glot.set("alpha", 1.0);
glot.add(new isosurface("x", CYLINDRICAL));
//*/
/* Test surface - a sphere with isosurfacing
glot.set("alpha", 1.0);
glot.add(new isosurface("x", SPHERICAL));
//*/
/* Test surface - using a parameter
glot.set("alpha", 1.0);
glot.set("d", 2.0);
glot.add(new isosurface("x / d", SPHERICAL));
//*/
/* Test surface - using cylindrical coordinates with surface class
glot.set("a", 3.0);
glot.set("b", 1.0)
glot.add(new surface("b * sin(a * x - 3.0 * t) / 5.0", CYLINDRICAL, "textures/kaust.png"));
//*/
//glot.add(new pde());
/* Some implicit surfaces from http://virtualmathmuseum.org/
// http://virtualmathmuseum.org/Surface/clebsch_cubic/clebsch_cubic.html
81.0*(pow(x,3.0) + pow(y,3.0) + pow(z,3.0)) - 189.0*(x*x*y + x*x*z + y*y*x + y*y*z + z*z*x + z*z*y) + 54.0*(x*y*z) + 126.0*(x*y + x*z + y*z) - 9.0*(x * x + y * y + z * z) - 9.0*(x + y + z) + 1.0
// http://virtualmathmuseum.org/Surface/orthocircles/orthocircles.html
(pow(x*x + y*y - 1.0,2.0) + z * z)*(pow(y * y + z * z - 1.0,2.0) + x * x)*(pow(z * z + x * x - 1.0, 2.0) + y * y) - pow(0.075, 2.0)*(1.0 + 3.0*(x * x + y * y + z * z))
// This description does not appear to be correct
// http://virtualmathmuseum.org/Surface/bretzel5/bretzel5.html
(x * x + y * y * 0.25 - 1.0) * ( x * x * 0.25 + y * y - 1.0) - 0.075
// Incomplete description?
// http://virtualmathmuseum.org/Surface/pilz/pilz.html
pow(pow(x*x + y*y - 1.0, 2.0) + pow(z - 0.5, 2.0),2.0) * (pow(y * y * 0.64 + pow(z + 0.03, 2.0) - 1.0,2.0) + x * x) - 0.28 * (1.0 + 3.0*(pow(z - 0.5, 2.0)))
// http://virtualmathmuseum.org/Surface/barth_sextic/barth_sextic.html
glot.set("phi", 1.61803);
glot.set("w", 1.0);
4.0*(phi*phi*x*x - y*y) * (phi*phi*y*y - z*z) * (phi*phi*z*z - x*z) - (1.0 + 2.0*phi) * pow(x*x + y*y + z*z - w*w, 2.0) * w*w == 0
*/
/*
Parametric surfaces
*/
/*
var aa = 0.9;
var w = Math.sqrt(1 - aa * aa);
glot.set("aa", aa);
glot.set("w", w);
glot.add(new surface("4.0 * atan( (aa / w) * (sin(w * y))) / (cosh(aa * x))"));
*/
/*
var aa = 0.7;
var wsqr = 1 - aa * aa;
var w = Math.sqrt(wsqr);
glot.set("aa", aa);
glot.set("wsqr", wsqr);
glot.set("w", w);
var x = "-u + (2.0 * wsqr * cosh(aa * u) * sinh(aa * u) / (aa * (pow(w * cosh(aa * u), 2.0) + pow(aa * sin(w * v), 2.0))))";
var y = "2.0 * w * cosh(aa * u) * (-(w * cos(v) * cos(w * v)) - sin(v) * sin(w * v)) / (aa * (pow(w * cosh(aa * u), 2.0) + pow(aa * sin(w * v), 2.0)))";
var z = "2.0 * w * cosh(aa * u) * (-(w * sin(v) * cos(w * v)) - cos(v) * sin(w * v)) / (aa * (pow(w * cosh(aa * u), 2.0) + pow(aa * sin(w * v), 2.0)))";
glot.add(new p_surface(x + "," + y + "," + z, 0, 5, 0, 5))
//*/
/*
glot.add(new p_surface("u - u * u * u / 3.0 + u * v * v, v - v * v * v / 3.0 + v * u * u, u * u - v * v", 0, 3, 0, 3));
//x = u - u * u * u / 3 + u * v * v
//y = v - v * v * v / 3 + v * u * u
//z = u * u - v * v
//*/
//glot.set("isovalue", 0.1);
//glot.add(new pde());
//glot.set("alpha", 0.2);
//glot.add(new pde3d());
//glot.add(new flow("sin(3.0 * sqrt(x * x + y * y) - 1.5 * t) * cos(5.0 * sqrt((x - 1.5) * (x - 1.5) + (y - 0.75) * (y - 0.75)) - 2.0 * t) * 0.3"));
//glot.add(new flow("sin(sqrt(x * x + y * y) * 4.0 - t) * 0.25"));
glot.add(new box());
//glot.add(new nurbs("0.0"));
/* If you've got a function that's time-dependent and thus you'd like
* for it to animate, then call glot.run. It makes sure it constantly
* refreshes, otherwise the plot will be interactive, but static. Well,
* that is to say, it will only refresh when the perpective changes,
* like with zooming in and out, or rotating it.
*/
//glot.run();
}
</script>
<style type="text/css">
canvas {
border: 1px solid black;
width:100%;
height:95%;
}
</style>
</head>
<body onload="start()">
<!--
WebGLot currently requires there to be a canvas with id="glot" to work.
This will likely remain the default behavior, but there may be a new
interface added so that drawing on multiple canvases can take place.
Though, it's a long way down on the roadmap.
-->
<canvas id="glot">It seems you do not have support for WebGL.</canvas>
<!--
<div id="function_form">
<form name="function" onsubmit="gen_isosurface(); return false">
f(x, y, z, t) = <input size='100' name="fn" /> = 0
</form>
<p><em>Note:</em> If you need to enter numerical constants, make sure they are written as floating-point numbers. Eg, 2.0, not 2</p>
</div>
<div id="framerate">Framerate: </div>
-->
</body>
</html>