I just couldn’t resist the temptation of checking the BZ-cellular automaton of my previous post with some perspective-effect.
Demo (keyboard: esc for fullScreen, delete for a new generation)
btw … if pattern appears too dense, make sure you’ve got the latest (FP 10.0r22) version installed.
I’ve already earlier demoed this principle, but I didn’t publish the code. The whole thing is done by first applying a perspective tiling, with graphics.drawTriangles, as in one of my earlier posts – and then adding the parallax effect by counting a displacement – a pixels position is raised by its color value – with BitmapData.set/getVector: then image is scanned through a vertical column by column. Here’s some essential part from the code: found in public function extrudeBitmapData
for (var column:Rectangle= new Rectangle(bmd.width,0,1,bmd.height); (column.x-=1)>-1 ; ) {
levels = new Vector.<int>(bmd.height, true);
pixels = bmd.getVector(column);
heights = (heightMap) ? heightMap.getVector(column) : pixels ;
// first loop marks the displacements for each pixel
// 'version 0.0' sampled from the blur-channel
for (i = 0; ++i != bmd.height; ) {
levels[i- ((heights[i]&0xFF) * i >>10) ] = i; // >>10 controls the height
}
// displace the column
for (iz = -1, i = 0; ++i != bmd.height;) {
pixels[i] = (levels[i] > iz) ? pxl = pixels[iz = levels[i]] : pxl ;
}
// rewrite on the image
bmd.setVector(column, pixels);
}
So finally here’s that messy source with too few comments !



























