Murayama blog.

AIの民主化。

Tweenerのディレイとバウンドで

つづいてドミノっぽいのを作ってみました。


気づきとしては、

  • Tweenerのバウンドが面白い。
Tweener.addTween(cubeList[i], {y:cubeList[i].y - size, time:1, delay:i * 0.2, transition:"easeOutBounce"});

これだけでバウンドしてくれる。


ソース。

package
{
	import caurina.transitions.Tweener;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.materials.special.CompositeMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.view.BasicView;
	
	[SWF(backgroundColor=0x000000)]
 	public class CubeSort extends BasicView
	{
		private var cubeList:Array = [];
		
		private var size:Number = 80;
		private var count:int = 10;
		
		public function CubeSort()
		{
			camera.y=500;
			for(var i:int = 0; i < count * count; i++){
				var compositMaterial:CompositeMaterial = new CompositeMaterial();
				compositMaterial.addMaterial(new ColorMaterial(0xFFFFFF * Math.random()));
				compositMaterial.addMaterial(new WireframeMaterial(0xFFFFFF * Math.random()));
				var materialsList:MaterialsList = new MaterialsList();
				materialsList.addMaterial(compositMaterial, "all");
				var cube:Cube = new Cube(materialsList, size, size, size);
				
				cube.x = size * (i % count) - (size * count / 2);
				cube.z = size * int((i / count));
				scene.addChild(cube);
				cubeList.push(cube);
			}
			startRendering()
			addEventListener(MouseEvent.CLICK, onClick);
		}

		private function onClick(evt:MouseEvent):void
		{
			for(var i:int = 0; i < count * count; i++){
				Tweener.addTween(cubeList[i], 
				{y:cubeList[i].y - size, time:1, delay:i * 0.2, transition:"easeOutBounce"});
			}
		}
		
		private var cameraSpeed:Number = 10;
		private var cameraRange:Number = 200;
		override protected function onRenderTick(event:Event=null):void
		{
			if(camera.x > cameraRange || camera.x < -cameraRange){
				cameraSpeed *= -1;
			}
			camera.x += cameraSpeed;
			super.onRenderTick(event);
		}
	}
}