Toggle navigation
Sign Up
Log In
Explore
Works
Folders
Tools
Collections
Artists
Groups
Groups
Topics
Tasks
Tasks
Jobs
Teams
Jobs
Recommendation
More Effects...
ActionScript
// forked from Johannes's forked from: Plasmountains // forked from yonatan's Plasmountains package { import flash.filters.BevelFilter; import flash.display.*; import flash.geom.*; import flash.utils.*; [SWF(width=465,height=465,frameRate=30,backgroundColor=0x88aaff)] public class Plasmountains extends Sprite { private static const SIZE:int = 32; private static const OCTAVES:int = 5; private var vertices:Vector.
= new Vector.
(SIZE*SIZE*3, true); private var projected:Vector.
= new Vector.
(0, false); private var uvtData:Vector.
= new Vector.
(SIZE*SIZE*3, true); private var heightMap:BitmapData = new BitmapData(SIZE, SIZE, false); private var indices:Vector.
= new Vector.
((SIZE-1)*(SIZE-1)*6, true); private var tmpBmd1:BitmapData = new BitmapData(SIZE, SIZE); private var texture:BitmapData = new BitmapData(SIZE, SIZE); private var projection:PerspectiveProjection = new PerspectiveProjection(); private var viewport:Shape = new Shape(); public function Plasmountains() { viewport.x = viewport.y = 465 / 2; addChild(viewport); projection.fieldOfView = 20; addEventListener("enterFrame", loop); } private function loop(e:*):void { var offsets:Array = []; var offset:Number = -getTimer()/100; for(var i:uint = 0; i < OCTAVES; i++) { offsets.push(new Point(0, offset/(i+1))); } heightMap.perlinNoise(SIZE, SIZE, OCTAVES, 16, true, false, BitmapDataChannel.RED | BitmapDataChannel.GREEN | BitmapDataChannel.BLUE, true, offsets); texture.perlinNoise(SIZE, SIZE, OCTAVES, 3, false, false, BitmapDataChannel.RED | BitmapDataChannel.GREEN | BitmapDataChannel.BLUE, false, offsets); // "shadows" in valleys tmpBmd1.draw(heightMap) tmpBmd1.draw(heightMap, null, null, "screen"); texture.draw(tmpBmd1, null, null, "multiply"); // generate vertices, uvtdata and indices i = 0; var ii:uint = 0; // indices index for(var y:int = 0; y < SIZE; y++) { for(var x:int = 0; x < SIZE; x++) { vertices[i] = -(x*2-SIZE); uvtData[i++] = x/SIZE; vertices[i] = ((heightMap.getPixel(x,y) & 0xFF) - 0x80) / 0x80 * SIZE; uvtData[i++] = y/SIZE; vertices[i] = y*2-SIZE; uvtData[i++] = 0; if(x < SIZE-1 && y < SIZE-1) { var i1:uint = y*SIZE+x; var i2:uint = i1+SIZE; indices[ii++]=i1; indices[ii++]=i1+1; indices[ii++]=i2; indices[ii++]=i1+1; indices[ii++]=i2+1; indices[ii++]=i2; } } } // project var m:Matrix3D = new Matrix3D; m.appendScale(.6,.4,.6); m.appendRotation(38, Vector3D.X_AXIS); m.appendTranslation(0,-SIZE/8,-SIZE*2.3); m.append(projection.toMatrix3D()); Utils3D.projectVectors(m, vertices, projected, uvtData); viewport.graphics.clear(); viewport.graphics.beginBitmapFill(texture, null, false, true); viewport.graphics.drawTriangles(projected, indices, uvtData, TriangleCulling.NEGATIVE); viewport.graphics.endFill(); } } }
Join Effecthub.com
Working with Global Gaming Artists and Developers!
Login
Sign Up
Or Login with Your Email Address:
Email
Password
Remember
Or Sign Up with Your Email Address:
Your Email
This field must contain a valid email
Set Password
Password should be at least 1 character
Stay informed via email