In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

fly

Get Adobe Flash player
by lizhi 08 May 2013
    Embed
/**
 * Copyright lizhi ( http://wonderfl.net/user/lizhi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pgFIc
 */

package  
{
	import flash.display.BitmapData;
	import flash.display.BitmapDataChannel;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.geom.Point;
	/**
	 * ...
	 * @author lizhi http://matrix3d.github.io/
	 */
	public class TestFly extends Sprite
	{
		private var isMouseDown:Boolean = false;
		private var fly:Fly = new Fly;
		private var uphigh:BitmapData = new BitmapData(400, 1, false);
		private var downhigh:BitmapData = new BitmapData(400, 1, false);
		private var star:BitmapData = new BitmapData(400, 400, false);
		private var offset:Point = new Point;
		private var matr:Matrix = new Matrix;
		public function TestFly() 
		{
			star.perlinNoise(15, 15, 2, 1, true, true,7, true);
			var map:Array = [];
			map[90] = 0xffffff;
			star.paletteMap(star, star.rect, new Point, map,map,map);
			stage.addEventListener(MouseEvent.MOUSE_DOWN, stage_mouseDown);
			stage.addEventListener(MouseEvent.MOUSE_UP, stage_mouseUp);
			addEventListener(Event.ENTER_FRAME, enterFrame);
			addChild(fly);
			fly.x = 200;
			fly.y = 200;
			
		}
		
		private function enterFrame(e:Event):void 
		{
			offset.x++;
			uphigh.perlinNoise(150, 150, 2, 1, true, true, BitmapDataChannel.BLUE, false, [offset,offset]);
			downhigh.perlinNoise(150, 150, 2, 100, true, true, BitmapDataChannel.BLUE, false, [offset,offset]);
			graphics.clear();
			matr.tx-=.5;
			graphics.beginBitmapFill(star, matr, true, false);
			graphics.drawRect(0, 0, 400, 400);
			graphics.endFill();
			graphics.lineStyle(0, 0xffffff);
			for (var i:int = 0; i < 400; i++ ) {
				var color:uint = uphigh.getPixel(i, 0);
				var up:Number = (color & 0xff) / 0xff * 230;
				if (i==200) {
					var up200:Number = up;
				}
				if (i==0) {
					graphics.moveTo(i, up);
				}else {
					graphics.lineTo(i, up);
				}
			}
			for (i = 0; i < 400; i++ ) {
				color = downhigh.getPixel(i, 0);
				var down:Number = 400 - (color & 0xff) / 0xff * 230;
				if (i==200) {
					var down200:Number = down;
				}
				if (i==0) {
					graphics.moveTo(i, down);
				}else {
					graphics.lineTo(i, down);
				}
			}
			if (isMouseDown) {
				fly.vy-=2;
			}else {
				fly.vy+=4;
			}
			if (fly.vy<-10) {
				fly.vy = -10;
			}else if (fly.vy>10) {
				fly.vy = 10;
			}
			fly.x += fly.vx;
			fly.y += fly.vy;
			if (fly.y<up200) {
				fly.y = up200;
                                fly.vy=0;
			}
			if (fly.y>down200) {
				fly.y = down200;
                                fly.vy=0;
			}
		}
		
		private function stage_mouseUp(e:MouseEvent):void 
		{
			isMouseDown = false;
		}
		
		private function stage_mouseDown(e:MouseEvent):void 
		{
			isMouseDown = true;
		}
		
	}

}
import flash.display.Shape;
class Fly extends Shape{
	public var vx:Number=0;
	public var vy:Number=0;
	public function Fly() {
		graphics.lineStyle(0,0xffffff);
		graphics.drawRect( -20, -5, 40, 10);
	}
}