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

forked from: 【AS100本ノック】2回目:たま/お月見

AS100本ノック
* 2回目のお題は「たま」
* あなたなりの「たま」を表現してください。

「たま」→「球」→「星」→秋ということで月です。季節感出してみました。
少し過ぎてしまいましたが今年は10/3が十五夜だったそうです。
/**
 * Copyright mex_md ( http://wonderfl.net/user/mex_md )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vdsW
 */

// forked from mex's 【AS100本ノック】2回目:たま
/* 
* AS100本ノック
* 2回目のお題は「たま」
* あなたなりの「たま」を表現してください。
*/
//「たま」→「球」→「星」→秋ということで月です。季節感出してみました。
//少し過ぎてしまいましたが今年は10/3が十五夜だったそうです。


package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.display.GradientType;
	import flash.display.Shape;
    import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.filters.GlowFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import org.papervision3d.cameras.CameraType;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.shaders.PhongShader;
	import org.papervision3d.materials.shaders.ShadedMaterial;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.objects.primitives.Sphere;
	[SWF(width=400, height=400, frameRate=30, backgroundColor=0x000033)]
    public class FlashTest extends BasicView
	{
	     
        private var moon:Sphere;
		private var moonMat:ShadedMaterial;
		private var light:PointLight3D;
		private const lightCol:int = 0xffffff;
		private const texW:int = 800;
		private const texH:int = 400;
		private var pnt:Point = new Point();
		private var shader:PhongShader;
		private var cloudBmd:BitmapData;
		private var cloudSeed:Number;
		private var cloudOffset:Point;
		private var cloudCT:ColorTransform;
		
		public function FlashTest():void
		{
			
			super(0, 0, true, false, CameraType.TARGET);
		   
			//light
			light = new PointLight3D();
			light.x = 500;
			light.y = 0;
			light.z = -200;
			
			scene.addChild(light);
			
			//テクスチャ作る(PerlinNoiseとかよくわかってないので適当にそれっぽくなるようにしましたがそれっぽくならないときもあるかも知れません)
			var bumpBmd:BitmapData = new BitmapData(texW, texH,false, 0x818181);//bump
			bumpBmd.perlinNoise(texW, texH, 6, Math.random()*10,false,true,7,true);
				
			var blur:BitmapData = new BitmapData(texW,texH, false, 0x818181);
			
			//
			bumpBmd.threshold(bumpBmd, bumpBmd.rect, pnt, "<", 0x80, 0xffffffff, 0xff, false);
			bumpBmd.threshold(bumpBmd, bumpBmd.rect, pnt, ">", 200, 0xffffffff, 0xff, false);
				
			var texBmd:BitmapData = new BitmapData(texW, texH, true, 0xffffffff);//texture
			var noise:BitmapData = new BitmapData(texW, texH, true, 0x00818181);
			noise.perlinNoise(texW/2, texH/2,10, Math.random()*10,true,false,7,true);
			texBmd.draw(noise, new Matrix(), new ColorTransform(), BlendMode.MULTIPLY);
			noise.perlinNoise(texW/2, texH/2,5, Math.random()*10,true,false,7,true);
			texBmd.draw(noise, new Matrix(), new ColorTransform(1,1,1,0.35), BlendMode.LAYER);
			noise.perlinNoise(texW/2, texH/2,15, Math.random()*10,true,false,7,true);
			texBmd.draw(noise, new Matrix(), new ColorTransform(1,1,1,0.35),BlendMode.LAYER);
			texBmd.threshold(texBmd, texBmd.rect, new Point(), "<", 0x56, 0xffaaaaaa, 0xff, true);
			texBmd.threshold(texBmd, texBmd.rect, new Point(), ">", 180, 0xffffffff, 0xff, true);
			noise.perlinNoise(texW / 4, texH / 4, 6, Math.random() * 10, true, false, 7, true);
			texBmd.draw(noise, new Matrix(), new ColorTransform(1, 1, 1, 0.3));
			texBmd.colorTransform(texBmd.rect, new ColorTransform(1, 1, 1, 1, 80, 80, 80, 0));
			texBmd.applyFilter(texBmd, texBmd.rect, new Point(), new BlurFilter(2,2,1));
			
			var crater:Shape = new Shape();
			var gradientBox:Matrix = new Matrix();
			var lightSpot:Shape = new Shape();
			for (var j:int = 0; j < 1000; j++) 
			{
				var size:Number = Math.random() * 13;
				var tx:Number = Math.random() * (texW -size*2)+size; 
				var ty:Number = Math.random() * (texH-size*2)+size;
				
				gradientBox.createGradientBox(size, size, 0, tx, ty);
				crater.graphics.beginGradientFill(GradientType.RADIAL,[0xffffff,0x000000],[1,0],[200,255],gradientBox);
				crater.graphics.drawCircle(gradientBox.tx, gradientBox.ty, size);
				crater.graphics.endFill();
			}
			bumpBmd.draw(crater, new Matrix(), new ColorTransform(), BlendMode.DIFFERENCE,null,false);
			
			/*var test:Bitmap = new Bitmap(bumpBmd);
			test.scaleX = test.scaleY = 0.25;
			stage.addChild(test);*/
			
			//shader
			shader = new PhongShader(light,0xfffeee,0xEEDEAC,10, bumpBmd,bumpBmd);
			
			//bitmapMat
			var bmpMat:BitmapMaterial = new BitmapMaterial(texBmd,false);
			
			//material
			moonMat = new ShadedMaterial(bmpMat, shader);
		
			//moonObj
			moon = new Sphere(moonMat, 200, 30,20);
			moon.y = 120;
			moon.z = 450;
			scene.addChild(moon);
			
			//camera
			camera.z = -500;
			
			moon.useOwnContainer = true;
			moon.filters = [new GlowFilter(0xffffee,0.9,8,8,2,1,true,false)]
			
			//雲
			cloudSeed = Math.random() * 10;
			cloudOffset = new Point();
			cloudCT = new ColorTransform(1, 1, 1, 0.21);
			cloudBmd = new BitmapData(stage.stageHeight, stage.stageHeight,true,0x000000);
			cloudBmd.perlinNoise(250, 100, 4, cloudSeed, false, false, 7,true,[cloudOffset]);
			var cloud:Bitmap = new Bitmap(cloudBmd);
			//cloud.blendMode = BlendMode.DIFFERENCE;
			cloudBmd.colorTransform(cloudBmd.rect,cloudCT);
			stage.addChild(cloud);

			startRendering();
		}
		
		//renderTick
		override protected function onRenderTick(event:Event = null):void
		{
			//moon.yaw(0.5)
			cloudOffset.x += 8;
			cloudBmd.perlinNoise(250,100, 4,cloudSeed, false, false, 7, true, [cloudOffset]);
			cloudBmd.colorTransform(cloudBmd.rect,cloudCT);
			super.onRenderTick(event);
		}
    }
}