forked from enkimute/ganja.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added motor orbit rendering example.
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<HEAD> | ||
<SCRIPT SRC="../ganja.js"></SCRIPT> | ||
</HEAD> | ||
<BODY><SCRIPT> | ||
Algebra(3,0,1,()=>{ | ||
|
||
// Ganja.js can graph the orbits of parametrised motor variables : | ||
// these are functions that take one parameter 0<x<1 and return a motor. | ||
// For a function of 1 parameter, the orbit is rendered as a curve. | ||
|
||
var circle = (BV,r)=>x=>Math.E**(Math.PI*x*BV)*(1+r*.5e01), | ||
segment = (BV)=>x=>1+x*0.5*BV; | ||
|
||
// The product of two such parametrised 1D orbits is a 2D manifold : | ||
// In ganja, you can simply multiply the two 1-parameter orbits to | ||
// make a 2-parameter manifold. (rendered as a sheet) | ||
|
||
// this allows us to multiply two circles into a torus or sphere, | ||
// two segments into a plane, or a segment and a circle to produce | ||
// a disk, cone or cylinder. | ||
|
||
var torus = (r1,r2)=>circle(1e12,r1)*circle(1e13,r2), | ||
sphere = (r)=>circle(1e13,0)*circle(1e12,r), | ||
plane = (x,y)=>segment(x*1e02)*segment(y*1e03), | ||
cylinder = (r,l)=>segment(l*1e02)*circle(1e13,r), | ||
disk = (r)=>circle(1e12,0)*segment(r*1e01), | ||
cone = (r,l)=>circle(1e12,0)*segment(r*1e01-l*1e03); | ||
|
||
// we can render these now just as our other primitives .. | ||
var elements = [ | ||
0xff0000, circle(1e12,1), | ||
0x0000ff, segment(1e01), | ||
0xff0088, torus(.5,.2), | ||
0xffff00, sphere(0.1), | ||
0x00ffff, plane(0.2,0.2), | ||
0x8800ff, cylinder(.05,1), | ||
0x00ff00, disk(0.2), | ||
0xffffff, cone(0.1,0.2) | ||
]; | ||
|
||
// show with rotating camera.. | ||
var camera=0e1+1; | ||
document.body.appendChild(this.graph(()=>{ | ||
var t=performance.now()/1234; | ||
camera.set( Math.cos(t) + Math.sin(t)*1e13 ); | ||
return elements; | ||
},{camera,gl:1,animate:1})); | ||
|
||
})</SCRIPT></BODY> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.