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
var curve = new THREE.DaeAnimationCurve(); | |
curve.addKey(new THREE.DaeAnimationKey(0, 0)); | |
curve.addKey(new THREE.DaeAnimationKey(1, Math.PI*0.5)); | |
curve.addKey(new THREE.DaeAnimationKey(2, Math.PI)); | |
curve.addKey(new THREE.DaeAnimationKey(3, Math.PI*1.5)); | |
curve.addKey(new THREE.DaeAnimationKey(4, Math.PI*2)); | |
var channel = new THREE.DaeAnimationChannel(dae.rotation, "x"); | |
channel.addCurve(curve); | |
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
setFromRotationMatrix: function ( m ) { | |
// Adapted from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm | |
function copySign(a, b) { | |
return b < 0 ? -Math.abs(a) : Math.abs(a); | |
} | |
var absQ = Math.pow(m.determinant(), 1.0 / 3.0); | |
this.w = Math.sqrt( Math.max( 0, absQ + m.n11 + m.n22 + m.n33 ) ) / 2; | |
this.x = Math.sqrt( Math.max( 0, absQ + m.n11 - m.n22 - m.n33 ) ) / 2; | |
this.y = Math.sqrt( Math.max( 0, absQ - m.n11 + m.n22 - m.n33 ) ) / 2; | |
this.z = Math.sqrt( Math.max( 0, absQ - m.n11 - m.n22 + m.n33 ) ) / 2; |
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
/** | |
* Decompose a THREE.Matrix4 into translation, rotation and scale. | |
*/ | |
var translation = new THREE.Vector3(); | |
var rotation = new THREE.Quaternion(); | |
var scale = new THREE.Vector3(); | |
// decompose! | |
matrix.decompose(translation, rotation, scale); | |
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
pointInside: function(pt) { | |
var i, j, a, b, xpi, ypi, xpj, ypj; | |
var x = pt.x; | |
var y = pt.y; | |
var c = false; | |
for (i = 0; i < this.points.length; i++) { | |
j = (i+1) % this.points.length; | |
a = this.points[i]; | |
b = this.points[j]; | |
xpi = a.x; |
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
var G = new networkx.Graph(); | |
var tmp = new Map(); | |
forEach (graph.getNodes(), function(n) { | |
tmp.set(n, new Point2(n.x, n.y)); | |
}); | |
forEach (graph.getEdges(), function(e) { | |
G.addEdge(tmp.get(e[0]), tmp.get(e[1])); | |
}); |
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
listen(this.view.getElement(), ['mousedown', 'touchstart'], function(e) { | |
var v = this.listenVertex_.get(goog.getUid(e.target)); | |
if (v) { | |
dispatchEvent(this, new SelectionEvent(this, e, v)); | |
} else { | |
var edge = this.listenEdge_.get(goog.getUid(e.target)); | |
if (edge) { | |
dispatchEvent(this, new SelectionEvent(this, e, edge)); | |
} | |
} |
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
console.log size.x, size.y, size.z | |
min = gl.vec3().set(vmax, vmax, vmax) | |
max = gl.vec3().set(vmin, vmin, vmin) | |
vs = [ | |
gl.vec3().set(-size.x/2, -size.y/2, -size.z/2), | |
gl.vec3().set( size.x/2, -size.y/2, -size.z/2), | |
gl.vec3().set( size.x/2, size.y/2, -size.z/2), | |
gl.vec3().set(-size.x/2, size.y/2, -size.z/2), | |
gl.vec3().set(-size.x/2, -size.y/2, size.z/2), |
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
(defn crop-old | |
[ctx w h] | |
(let [data (.-data (.getImageData ctx 0 0 w h)) | |
s (* w h 4) | |
[a b] (loop [y 0 px [] py []] | |
(if (< y h) | |
(let [[x' y'] | |
(loop [x 0 px' px py' py] | |
(if (< x w) | |
(let [a? (> (aget data (+ (* (+ (* y w) x) 4) 3)) 0)] |
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
(defn trimmed-bounds | |
[ctx w h] | |
(let [data (.-data (.getImageData ctx 0 0 w h))] | |
(loop [y 0 minx Infinity miny Infinity maxx -Infinity maxy -Infinity] | |
(if (< y h) | |
(let [yw (* y w) | |
minx' (loop [x 0] | |
(when (< x w) | |
(if (= (aget data (+ (* (+ yw x) 4) 3)) 0) | |
(recur (inc x)) |
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
pngtopnm -mix assign.png > a.pnm && potrace a.pnm -s -o a.svg |
OlderNewer