Created
August 28, 2012 15:40
-
-
Save tmcw/3499228 to your computer and use it in GitHub Desktop.
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
var Canvas = require('canvas'), | |
fs = require('fs'), | |
Pre3d = require('./pre3d'), | |
w = 1280, | |
h = 800, | |
c = new Canvas(w, h), | |
ctx = c.getContext('2d'); | |
var td = 'json/tcx/'; | |
var tweets = fs.readdirSync(td); | |
var t = tweets.map(function(t) { | |
return JSON.parse(fs.readFileSync(td + t, 'utf8')); | |
}).filter(function(t) { | |
return t.features.length > 0 && t.features[0].bpm; | |
}); | |
var fgcolor = new Pre3d.RGBA(1, 0, 0, 1); | |
var renderer = new Pre3d.Renderer(c); | |
renderer.ctx.lineWidth = 1; | |
var paths = []; | |
for (var j = 0; j < t.length; j++) { | |
var features = t[j].features; | |
var path = new Pre3d.Path(); | |
path.points = []; | |
path.curves = []; | |
path.starting_point = 0; | |
for (var i = 0; i < features.length - 1; i++) { | |
path.points.push({ | |
x: (2 * (j / t.length)) - 0.5, | |
z: (i / 500) - 1, | |
y: (features[i].alt / 300) - 0.3 | |
}); | |
path.curves.push(new Pre3d.Curve(i, i, i)); | |
} | |
paths.push(path); | |
} | |
var camera_state = {"rotate_x":0.5,"rotate_y":0.5,"rotate_z":0,"x":0,"y":0,"z":-3 }; | |
function set_camera() { | |
var ct = renderer.camera.transform; | |
ct.reset(); | |
ct.rotateZ(camera_state.rotate_z); | |
ct.rotateY(camera_state.rotate_y); | |
ct.rotateX(camera_state.rotate_x); | |
ct.translate(camera_state.x, camera_state.y, camera_state.z); | |
} | |
renderer.camera.focal_length = 3.5; | |
for (var n = 0; n < 20; n++) { | |
if (n < 10) { | |
camera_state.rotate_y += (Math.PI * 2) / 90; | |
} else { | |
camera_state.rotate_y -= (Math.PI * 2) / 90; | |
} | |
set_camera(); | |
renderer.ctx.setFillColor(0.97, 0.97, 0.97, 1); | |
renderer.drawBackground(); | |
for (var j = 0; j < paths.length; j += 2) { | |
if (j % 4 === 0) { | |
renderer.ctx.setStrokeColor(0.5, 0.7, 0.6, 1); | |
} else { | |
renderer.ctx.setStrokeColor(0.7, 0.2, 0.6, 1); | |
} | |
renderer.drawPath(paths[j]); | |
} | |
if (n < 10) { | |
fs.writeFileSync('3ds/3d_0' + n + '.png', c.toBuffer()); | |
} else { | |
fs.writeFileSync('3ds/3d_' + n + '.png', c.toBuffer()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment