Skip to content

Commit d69106c

Browse files
author
Dan Lecocq
committed
Updated demos, updated shaders. Long commit:
First, flow textures were having some problems. In particular, they were expecting a scalar function instead of a vector function. It was then plotting the gradient of that scalar function, which, while nice, wasn't what I was wanting it to do. Second, pde solving wasn't (and still isn't working). It's beginning to work again, but it appears as though I'm running into numerical stability issues rather than programatic access issues. Still looking into this one. Lasly, updated demos to look a little nicer than they used to.
1 parent c79e7b7 commit d69106c

18 files changed

+177
-245
lines changed

demos/curve.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
var glot = new grapher(AXES_ON | GRID_OFF);
3030
glot.set("a", 1.0);
3131

32-
glot.add(new curve("sin(x)", [1, 0, 0, 1], CARTESIAN | X_LIN | Y_LIN));
32+
glot.add(new curve("sin(x) * sqrt(x) * cos(t)", [1, 0, 0, 1], CARTESIAN | X_LIN | Y_LIN));
33+
glot.add(new curve("exp(sin(3.0 * x * cos(t * 2.0)))", [1, 0, 0, 1], CARTESIAN | X_LIN | Y_LIN));
3334

3435
glot.setClickFunction(click);
3536

demos/flow.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
var glot = new grapher(AXES_ON | GRID_OFF);
3232
glot.set("a", 0.5);
3333

34-
//glot.add(new flow("-y * sin(t) * 2.0, 2.0 * x * sin(t * y) - 4.0 * cos(1.5 * t)"));
3534
//glot.add(new flow())
36-
glot.add(new flow("-a * y, a * x"));
35+
//glot.add(new flow("x, y"));
3736
//glot.add(new flow("a * sin(t) + x, a * cos(t) + y"));
3837
//glot.add(new flow("(7.0 / ((x - 3.0 * (mod(t, 7.0) - 3.0)) * (x - 3.0 * (mod(t, 7.0) - 3.0)) + y * y + 1.0)) * -y, (7.0 / ((x - 3.0 * (mod(t, 7.0) - 3.0)) * (x - 3.0 * (mod(t, 7.0) - 3.0)) + y * y + 1.0)) * (x - 3.0 * (mod(t, 7.0) - 3.0))"))
38+
glot.add(new flow('x * sin(t), y * cos(t)'));
3939
//glot.add(new gradient("a * sin(t) + x"));
4040

4141
glot.setClickFunction(click);

demos/mootools.html

Lines changed: 0 additions & 96 deletions
This file was deleted.

demos/p_curve.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
var glot = new grapher(AXES_ON | GRID_OFF);
3030
glot.set("a", 0.5);
3131

32-
glot.add(new p_curve("sin(s * 6.3 * a), cos(1.5 * s * 6.3 * 2.0)", [1, 0, 0, 1]));
32+
glot.add(new p_curve("3.0 * sin(s * 6.3 * 4.0 * sin(t / 4.0)), 3.0 * cos(1.5 * s * 12.6)", [1, 0, 0, 1]));
3333
glot.add(new p_curve("t * s, s", [1, 0, 0, 1], POLAR | X_LIN | Y_LIN));
34-
3534
glot.setClickFunction(click);
3635

3736
glot.run();

demos/pde.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<script src="../emptytexture.js"> </script>
88
<script src="../noisetexture.js"> </script>
99
<script src="../texture.js"> </script>
10+
<script src="../ftexture.js"> </script>
1011

1112
<script src="../grid.js"> </script>
1213
<script src="../axes.js"> </script>
@@ -21,7 +22,8 @@
2122
<script src="../grapher.js"> </script>
2223

2324
<script>
24-
var p = new pde();
25+
//var p = new pde('-x - y * y / t');
26+
var p = new pde('sin(x * omega)');
2527

2628
function start() {
2729
var glot = new grapher(AXES_ON | GRID_OFF);

demos/scalar_field.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,23 @@
2929
var glot = new grapher(AXES_ON | GRID_OFF);
3030
glot.set("a", 0.5);
3131

32-
glot.add(new scalar_field("sin(3.0 * sqrt(x * x + y * y) - 2.0 * t) * cos(5.0 * sqrt((x - 1.5 + 0.8 * t) * (x - 1.5 + 0.8 * t) + (y - 0.75) * (y - 0.75)) - t)"));
32+
/*
33+
sin(3.0 * sqrt(x * x + y * y) - 2.0 * t) * cos(5.0 * sqrt((x - 1.5 + 0.8 * t) * (x - 1.5 + 0.8 * t) + (y - 0.75) * (y - 0.75)) - t)
34+
*/
35+
36+
glot.set('sf', 3.0);
37+
glot.set('mf', 45.0);
38+
glot.set('sc', 0.2);
39+
glot.set('ec', 1.07);
40+
glot.set('speed', 0.4);
41+
42+
var f = '(1.0 - sc) * sin(sf * sqrt(pow(x, 2.0) + pow(y, 2.0)))';
43+
var g = 'sc * sin(mf * sqrt(pow(x - 3.0 * sin(ec * speed * t), 2.0) + pow(y - 5.0 * cos(ec * speed * t), 2.0)))';
44+
var h = 'sc * sin(mf * sqrt(pow(x - 5.0 * sin(speed * t), 2.0) + pow(y - 3.0 * cos(speed * t), 2.0)))';
45+
// var g = '0.1 * sin(mf * sqrt(pow(x - 5.0 * sin(6.3 * t), 2.0) + pow(y - 3.0 * cos(6.3 * t), 2.0)))';
46+
glot.add(new scalar_field(f + ' + ' + g + ' + ' + h));
47+
48+
// glot.add(new p_curve("3.0 * sin(6.3 * s), 5.0 * cos(6.3 * s)", [1, 0, 0, 1]));
3349

3450
glot.setClickFunction(click);
3551

demos/slider.html

Lines changed: 0 additions & 64 deletions
This file was deleted.

flow.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function flow(string, options) {
9090
f = function(pixels) {
9191
var count = scr.width * scr.height * 4;
9292
for (var i = 0; i < count; i += 4) {
93-
pixels[i] = Math.random() * 3.0;
93+
pixels[i] = Math.random() * 1.5;
9494
}
9595
return pixels;
9696
}
@@ -204,7 +204,9 @@ function flow(string, options) {
204204
}
205205

206206
this.calculate = function(scr) {
207-
this.gl.uniform1i(this.gl.getUniformLocation(this.program, "accumulation"), 0);
207+
this.setUniforms(scr, this.program);
208+
209+
this.gl.uniform1i(this.gl.getUniformLocation(this.program, "accumulation"), 0);
208210
this.gl.uniform1i(this.gl.getUniformLocation(this.program, "source"), 1);
209211

210212
this.gl.enableVertexAttribArray(0);
@@ -253,10 +255,10 @@ function flow(string, options) {
253255
* was before it's called.
254256
*/
255257
this.draw = function(scr) {
256-
this.setUniforms(scr);
257-
258258
this.calculate(scr);
259-
this.calculate(scr);
259+
this.calculate(scr);
260+
261+
this.setUniforms(scr);
260262

261263
this.gl.uniform1i(this.gl.getUniformLocation(this.program, "accumulation"), 0);
262264

ftexture.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/* Reference: http://learningwebgl.com/blog/?p=507 */
2323
function ftexture(context, width, height, f, type) {
24-
24+
console.log('ftexture');
2525
this.texture = null;
2626
this.image = null;
2727

@@ -33,6 +33,7 @@ function ftexture(context, width, height, f, type) {
3333
this.height = height;
3434

3535
this.initialize = function(f) {
36+
console.log('initialize');
3637
this.texture = this.gl.createTexture();
3738
this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture);
3839

noisetexture.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ function noisetexture(context, width, height) {
4949
var count = this.width * this.height * 4;
5050
//*
5151
for (var i = 0; i < count; i += 1) {
52-
pixels[i] = Math.random() * 3.0;
52+
//pixels[i] = Math.random() * 3.0;
5353
//pixels[i] = 4.0 * i / count;
54-
//pixels[i] = 0.0;
54+
pixels[i] = 0.0;
5555
}
5656
//*/
5757

0 commit comments

Comments
 (0)