Last active
August 29, 2015 14:22
-
-
Save mathdoodle/6b02512b10aa4b7d1e5f to your computer and use it in GitHub Desktop.
Surface Intersection
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
{ | |
"uuid": "a9917079-877a-4c11-817d-b1900f054d97", | |
"description": "Surface Intersection", | |
"dependencies": { | |
"domready": "latest", | |
"MathBox": "latest" | |
} | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>MathBox - Empty Example.</title> | |
<!-- STYLE-MARKER --> | |
<!-- SCRIPTS-MARKER --> | |
</head> | |
<body> | |
<div id="info"></div> | |
<script type='text/javascript'> | |
try { | |
<!-- CODE-MARKER --> | |
} | |
catch(e) { | |
console.log(e); | |
} | |
</script> | |
</body> | |
</html> |
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
DomReady.ready(function() { | |
ThreeBox.preload([ | |
'../shaders/snippets.glsl.html', | |
], function () { | |
// MathBox boilerplate | |
var mathbox = window['mathbox'] = mathBox({ | |
cameraControls: true, | |
cursor: true, | |
controlClass: ThreeBox.OrbitControls, | |
elementResize: true, | |
fullscreen: true, | |
screenshot: true, | |
stats: false, | |
scale: 1, | |
}).start(); | |
// Viewport camera/setup | |
mathbox | |
// Cartesian viewport | |
.viewport({ | |
type: 'cartesian', | |
range: [[-1, 1], [-2, 5], [-1, 1]], | |
scale: [1, 1, 1], | |
polar: 0, | |
}) | |
.camera({ | |
orbit: 4, | |
phi: τ/4-.5, | |
theta: .7, | |
}) | |
.transition(300) | |
// Grid | |
.grid({ | |
axis: [0, 2], | |
color: 0xa0a0a0 | |
}) | |
// Surface function | |
.surface({ | |
shaded: true, | |
domain: [[-1, 1], [-1, 1]], | |
n: [32, 32], | |
expression: surfaceFunc, | |
opacity: .999, // Bugfix: for some reason, tangent attribute is gone when material.transparent = false | |
}) | |
.surface({ | |
shaded: false, | |
domain: [[-1, 1], [-1, 1]], | |
n: [2, 2], | |
expression: sliceFunc, | |
color: 0x20C050, | |
opacity: .5, | |
}); | |
}); | |
}); | |
// Clock that starts as soon as it is first called (per id). | |
var clocks: {[key:number]:number} = {}; | |
function clock(id: number) { | |
if (!clocks[id]) clocks[id] = Date.now(); | |
return (Date.now() - clocks[id]) * .001; | |
} | |
// Arbitrary function | |
function surfaceFunc(x: number, y: number) { | |
return [x, 3 + -1 + Math.cos(x*5) + Math.cos(y*5), y]; | |
} | |
// Horizontal slice | |
function sliceFunc(x: number, y: number) { | |
var t = clock(1); | |
return [x, Math.sin(t) * .75 + 2, y]; | |
} |
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
html, body { height: 100%; } | |
body { margin: 0; padding: 0 } | |
canvas { display: block } | |
#info { | |
position: absolute; | |
left: 50%; | |
bottom: 50px; | |
z-index: 20; | |
width: 300px; | |
margin-left: -150px; | |
padding: 25px; | |
background: rgba(0, 0, 0, .5); | |
color: #fff; | |
font-family: "Lucida Grande", sans-serif; | |
font-size: 16px; | |
text-align: center; | |
border-radius: 3px; | |
text-shadow: 0px 1px 0px rgba(0, 0, 0, .4); | |
opacity: 0; | |
} | |
#info.transition { | |
-webkit-transition: opacity 300ms ease-in-out; | |
-moz-transition: opacity 300ms ease-in-out; | |
transition: opacity 300ms ease-in-out; | |
} | |
#info kbd { | |
background: #aaa; | |
box-shadow: 0px 1px 1px rgba(0, 0, 0, .3); | |
border-radius: 3px; | |
padding: 3px; | |
margin: 3px; | |
font-family: inherit; | |
} | |
.mathbox-label { | |
font-family: 'klavika-web', sans-serif; | |
font-weight: normal; | |
font-style: normal; | |
text-shadow: | |
3px 0px 1px rgb(255, 255, 255), | |
-3px 0px 1px rgb(255, 255, 255), | |
0px -3px 1px rgb(255, 255, 255), | |
0px 3px 1px rgb(255, 255, 255), | |
2px 2px 1px rgb(255, 255, 255), | |
-2px 2px 1px rgb(255, 255, 255), | |
2px -2px 1px rgb(255, 255, 255), | |
-2px -2px 1px rgb(255, 255, 255), | |
3px 2px 1px rgb(255, 255, 255), | |
-3px 2px 1px rgb(255, 255, 255), | |
3px -2px 1px rgb(255, 255, 255), | |
-3px -2px 1px rgb(255, 255, 255), | |
1px 3px 1px rgb(255, 255, 255), | |
-1px 3px 1px rgb(255, 255, 255), | |
1px -3px 1px rgb(255, 255, 255), | |
-1px -3px 1px rgb(255, 255, 255), | |
-1px -1px 1px rgb(255, 255, 255), | |
-1px 1px 1px rgb(255, 255, 255), | |
1px -1px 1px rgb(255, 255, 255), | |
1px 1px 1px rgb(255, 255, 255); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment