Last active
February 19, 2018 01:46
-
-
Save mathdoodle/77e72fa4bf26ddcf59d5a8681ab9ae1b to your computer and use it in GitHub Desktop.
EIGHT Parallelepiped
This file contains hidden or 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> | |
<base href='/'> | |
<script src='https://jspm.io/[email protected]'></script> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body> | |
<canvas id='my-canvas'></canvas> | |
<script> | |
System.defaultJSExtensions = true | |
System.import('./index') | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
import { Geometric3 } from 'davinci-eight' | |
import { Engine, Capability, BlendingFactorSrc, BlendingFactorDest } from 'davinci-eight' | |
import { Scene } from 'davinci-eight' | |
import { Facet, PerspectiveCamera, DirectionalLight } from 'davinci-eight' | |
import { Arrow, Basis, Box, Parallelepiped } from 'davinci-eight' | |
import { Color } from 'davinci-eight' | |
import { TrackballControls } from 'davinci-eight' | |
const e1 = Geometric3.e1() | |
const e2 = Geometric3.e2() | |
const e3 = Geometric3.e3() | |
const engine = new Engine('my-canvas') | |
.size(500, 500) | |
.clearColor(0.1, 0.1, 0.1, 1.0) | |
.enable(Capability.DEPTH_TEST) | |
.enable(Capability.BLEND) | |
.blendFunc(BlendingFactorSrc.SRC_ALPHA, BlendingFactorDest.ONE) | |
const scene = new Scene(engine) | |
const ambients: Facet[] = [] | |
const camera = new PerspectiveCamera() | |
camera.eye.z = 3 | |
ambients.push(camera) | |
const dirLight = new DirectionalLight() | |
ambients.push(dirLight) | |
const shape = new Parallelepiped(engine) | |
shape.opacity = 0.5 | |
shape.transparent = true | |
shape.a = e1 | |
shape.b = e2 | |
shape.c = 0.01 * e3 | |
const color = Color.blueviolet.clone().scale(0.05) | |
shape.colors[0] = color | |
shape.colors[1] = color | |
shape.colors[2] = color | |
shape.colors[3] = color | |
shape.colors[4] = color | |
shape.colors[5] = color | |
scene.add(shape) | |
const a = new Arrow(engine) | |
a.color = Color.red | |
a.axis = shape.a | |
a.X = - shape.a / 2 - shape.b / 2 - shape.c / 2 | |
scene.add(a) | |
const b = new Arrow(engine) | |
b.color = Color.blue | |
b.axis = shape.b | |
b.X = shape.a / 2 - shape.b / 2 | |
scene.add(b) | |
const moveAB = function() { | |
shape.b.copyVector(b.axis) | |
a.X = - shape.a / 2 - shape.b / 2 | |
b.X = shape.a / 2 - shape.b / 2 | |
} | |
// tilt is ignored in the Basis | |
const box = new Box(engine, { mode: 'wire' }) | |
// box.opacity = 0.1 | |
// box.transparent = true | |
// console.log(box.vertexShaderSrc) | |
// console.log(box.fragmentShaderSrc) | |
scene.add(box) | |
const trackball = new TrackballControls(camera, window) | |
// Subscribe to mouse events from the canvas. | |
trackball.subscribe(engine.canvas) | |
const gui = new dat.GUI() | |
const bFolder = gui.addFolder("b") | |
bFolder.add(b.axis, 'x', -2, +2).onChange(moveAB) | |
bFolder.add(b.axis, 'y', -2, +2).onChange(moveAB) | |
bFolder.add(b.axis, 'z', -2, +2).onChange(moveAB) | |
bFolder.open() | |
const basis = new Basis(engine) | |
basis.X = 0.01 * e3 | |
// scene.add(basis) | |
/** | |
* animate is the callback point for requestAnimationFrame. | |
* This has been initialized with a function expression in order | |
* to avoid issues associated with JavaScript hoisting. | |
*/ | |
const animate: FrameRequestCallback = function(_: number) { | |
engine.clear() | |
// Update the camera based upon mouse events received. | |
trackball.update() | |
// Keep the directional light pointing in the same direction as the camera. | |
dirLight.direction.copy(camera.look).sub(camera.eye) | |
// const t = timestamp * 0.001 | |
// The scene draws the box in the canonical configuration. | |
scene.draw(ambients) | |
// This call keeps the animation going. | |
requestAnimationFrame(animate) | |
} | |
// This call "primes the pump". | |
requestAnimationFrame(animate) |
This file contains hidden or 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
{ | |
"description": "EIGHT Parallelepiped", | |
"dependencies": { | |
"DomReady": "1.0.0", | |
"jasmine": "2.5.2", | |
"davinci-eight": "7.3.0", | |
"dat-gui": "0.5.0" | |
}, | |
"name": "eight-parallelepiped", | |
"version": "0.1.0", | |
"keywords": [ | |
"EIGHT", | |
"Parallelepiped", | |
"mathdoodle" | |
], | |
"operatorOverloading": true, | |
"author": "David Geo Holmes", | |
"hideConfigFiles": true, | |
"linting": true | |
} |
This file contains hidden or 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
body { | |
background-color: blue; | |
} |
This file contains hidden or 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
Show hidden characters
{ | |
"allowJs": true, | |
"checkJs": true, | |
"declaration": true, | |
"emitDecoratorMetadata": true, | |
"experimentalDecorators": true, | |
"jsx": "react", | |
"module": "system", | |
"noImplicitAny": true, | |
"noImplicitReturns": true, | |
"noImplicitThis": true, | |
"noUnusedLocals": true, | |
"noUnusedParameters": true, | |
"preserveConstEnums": true, | |
"removeComments": false, | |
"skipLibCheck": true, | |
"sourceMap": true, | |
"strictNullChecks": true, | |
"suppressImplicitAnyIndexErrors": true, | |
"target": "es5", | |
"traceResolution": true | |
} |
This file contains hidden or 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
{ | |
"rules": { | |
"array-type": [ | |
true, | |
"array" | |
], | |
"curly": false, | |
"comment-format": [ | |
true, | |
"check-space" | |
], | |
"eofline": true, | |
"forin": true, | |
"jsdoc-format": true, | |
"new-parens": true, | |
"no-conditional-assignment": false, | |
"no-consecutive-blank-lines": true, | |
"no-construct": true, | |
"no-for-in-array": true, | |
"no-inferrable-types": [ | |
true | |
], | |
"no-magic-numbers": false, | |
"no-shadowed-variable": true, | |
"no-string-throw": true, | |
"no-trailing-whitespace": [ | |
true, | |
"ignore-jsdoc" | |
], | |
"no-var-keyword": true, | |
"one-variable-per-declaration": [ | |
true, | |
"ignore-for-loop" | |
], | |
"prefer-const": true, | |
"prefer-for-of": true, | |
"prefer-function-over-method": false, | |
"prefer-method-signature": true, | |
"radix": true, | |
"semicolon": [ | |
true, | |
"never" | |
], | |
"trailing-comma": [ | |
true, | |
{ | |
"multiline": "never", | |
"singleline": "never" | |
} | |
], | |
"triple-equals": true, | |
"use-isnan": true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment