Created
February 18, 2013 18:49
-
-
Save bingomanatee/4979637 to your computer and use it in GitHub Desktop.
bitmap problem with easel 6.0
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
(function (window) { | |
var node_topo = require('node-topography'); | |
var fluid_canvas = document.getElementById("fluid_sim_canvas"); | |
var stage = new createjs.Stage(fluid_canvas); | |
var fluid = document.createElement('canvas'); | |
fluid.width = Math.ceil(stage.canvas.width / 4); | |
fluid.height = Math.ceil(stage.canvas.height / 4); | |
var fluid_bitmap = new createjs.Bitmap(fluid); | |
var fluid_shape = new createjs.Shape(fluid_bitmap); | |
fluid_shape.scaleX = fluid_shape.scaleY = 4; | |
stage.addChild(fluid_shape); | |
var ator = Math.PI / 180; | |
FluidSim({ | |
width: fluid.width, | |
height: fluid.height, | |
time_scale: 1, | |
rand_cycle: 4, | |
vector_source: function (x, y) { | |
return {vx: 10 * Math.sin(x * ator), vy: 10}; | |
}, | |
fluid_source: function (x, y) { | |
return (x > 2 && x < 10 && y > 2 && y < 20) ? 200 : 0 | |
} | |
}, function (err, sim) { | |
console.log('fluid sim: ', sim); | |
function draw_fluid() { | |
sim.output_vectors(function () { | |
sim.reflow(function () { | |
sim.fluid_grid.filter(function (err, fgrey) { | |
fgrey.data_to_canvas(fluid); | |
stage.update(); | |
}, function (value, x, y) { | |
value = Math.max(0, Math.min(255, value)); | |
return [value / 4, value, value / 2, 255]; | |
}, true); | |
sim.scale_vectors(_.identity); | |
}); | |
}) | |
} | |
function move_fluid() { | |
draw_fluid(); | |
} | |
sim.scale_vectors(_.identity); | |
var t = 0; | |
function handleTick(event) { | |
if ((!t) || (event.time - t > 100)) { | |
t = event.time; | |
move_fluid(); | |
} | |
} | |
createjs.Ticker.addEventListener("tick", handleTick); | |
}); | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When this runs, get an error "Uncaught TypeError: Object [Bitmap (name=null)] has no method 'isEmpty' "