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: 2D Ribbon to mouse _ based on mouse click location

import jp.hara.fakeribbon.RibbonBody;
import jp.hara.fakeribbon.Ribbon_b;
クリックでリボン発生。
リボンをきれいに作るのが苦手なことで定評のある・・
Get Adobe Flash player
by sketchbookgames 15 May 2009
/**
 * Copyright sketchbookgames ( http://wonderfl.net/user/sketchbookgames )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/obrX
 */

// forked from HaraMakoto's 2D Ribbon
package {
	import caurina.transitions.Tweener;
	import caurina.transitions.properties.CurveModifiers;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	//import jp.hara.fakeribbon.RibbonBody;
	//import jp.hara.fakeribbon.Ribbon_b;
	
        //クリックでリボン発生。
        //リボンをきれいに作るのが苦手なことで定評のある・・
        
	[SWF(width="465", height="465", backgroundColor="0xCCCCCC", frameRate="40")]
	
	public class curveModifyTest extends Sprite
	{
		private var mainPointer:Sprite = new Sprite();
		
		private var startPnt:Point = new Point(50,50);
		private var endPnt:Point = new Point(400,400);
		private var pointsNum:int = 5;
		private var flgnum:int = 0;
		
		private var mcArray:Array;
		
		//リボン系
		private var ribbonArray:Array;
		private var rb:RibbonBody;
		
		public function curveModifyTest()
		{
			
			mainPointer.graphics.beginFill(0xFFFFFF);
			mainPointer.graphics.drawCircle(0,0,4);
			mainPointer.graphics.endFill();
			
			
			addChild(mainPointer);
			
			CurveModifiers.init();
			
			/*Tweener.addTween( mainPointer, {x:endPnt.x, y:endPnt.y,
				_bezier:[ {x:120, y:300}, {x:200, y:100}, {x:30, y:400}, {x:220, y:210}, {x:10, y:300}],
			 time:4, transition:"easeOutQuint"});
			 */
			 makePoints();
			 
			 addEventListener(Event.ADDED_TO_STAGE, addStageHandler);
		}
		
		private function addStageHandler(e:Event):void
		{
			stage.addEventListener(MouseEvent.CLICK, stageClick);
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
			
		}
		private function stageClick(e:MouseEvent):void
		{
			if(flgnum==0) {
    endPnt.x = mouseX
                                endPnt.y = mouseY
				startToGoal();
                                
				flgnum = 1;
			} else if(flgnum==1) {
    startPnt.x = mouseX
                                startPnt.y = mouseY
				GoalToStart();
				flgnum = 0;
                                
			}
		}
		private function enterFrameHandler(e:Event):void
		{
			for(var i:int=0; i<pointsNum; i++) {
				ribbonArray[i].makeMove(mcArray[i].x, mcArray[i].y);
			}
		}
			
		private function makePoints():void
		{
			mcArray = new Array(pointsNum);
			ribbonArray = new Array(pointsNum);
			
			for(var i:int=0; i<pointsNum; i++) {
				var PtMC:Sprite = new Sprite();
				addChild(PtMC);
				PtMC.graphics.beginFill(0xFFFFFF);
				PtMC.graphics.drawCircle(0,0,4);
				PtMC.graphics.endFill();
				mcArray[i] = PtMC;
				
				var rbb:RibbonBody = new RibbonBody();
				addChild(rbb);
				ribbonArray[i] = rbb;
			}
		}
		
		private function startToGoal():void
		{
			 // don't take a capture
                         Wonderfl.disable_capture();
             
             
                         // take a capture after 2 sec
                         Wonderfl.capture_delay( 1 );
                        for(var i:int=0; i<pointsNum; i++) {
				var pt1:Point = new Point(400*Math.random(),400*Math.random());
				var pt2:Point = new Point(400*Math.random(),400*Math.random());
				var pt3:Point = new Point(400*Math.random(),400*Math.random());
				var pt4:Point = new Point(400*Math.random(),400*Math.random());
				var pt5:Point = new Point(400*Math.random(),400*Math.random());
				
				Tweener.addTween( mcArray[i], {x:endPnt.x, y:endPnt.y,
				_bezier:[ {x:pt1.x, y:pt1.y}, {x:pt2.x, y:pt2.y}, {x:pt3.x, y:pt3.y}, {x:pt4.x, y:pt4.y}, {x:pt5.x, y:pt5.y}],
			 	time:1+1*Math.random(), transition:"linear"});
			}
		}
		
		
		
		private function GoalToStart():void
		{
			for(var i:int=0; i<pointsNum; i++) {
				var pt1:Point = new Point(400*Math.random(),400*Math.random());
				var pt2:Point = new Point(400*Math.random(),400*Math.random());
				var pt3:Point = new Point(400*Math.random(),400*Math.random());
				var pt4:Point = new Point(400*Math.random(),400*Math.random());
				var pt5:Point = new Point(400*Math.random(),400*Math.random());
				
				Tweener.addTween( mcArray[i], {x:startPnt.x, y:startPnt.y,
				_bezier:[ {x:pt1.x, y:pt1.y}, {x:pt2.x, y:pt2.y}, {x:pt3.x, y:pt3.y}, {x:pt4.x, y:pt4.y}, {x:pt5.x, y:pt5.y}],
			 	time:2, transition:"linear", delay:0.5*Math.random()});
			}
		}
	}
}
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	
class RibbonBody extends Sprite
{
		protected var posArray:Array;
		protected var posNum:int = 30;
		
		public function RibbonBody()
		{
			posArray = new Array(posNum);
			for(var i:int=0; i<posNum; i++) {
				posArray[i]= new pointerclass();
				posArray[i].fx=0;posArray[i].fy=0;
			}
			//addEventListener(Event.ADDED_TO_STAGE, addStageHandler);
		}
		
		private function addStageHandler(e:Event):void
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
		}
		
		public function makeMove(nx:Number, ny:Number):void
		{
			chase(nx, ny);
			draw();
		}
		private function mouseMoveHandler(e:MouseEvent):void
		{
			chase(mouseX, mouseY);
			draw();
		}
		
		private function chase(px:Number, py:Number):void
		{
			for(var i:int=0; i<posNum-1; i++) {
				posArray[i].fx = posArray[i+1].fx;
				posArray[i].fy = posArray[i+1].fy;
			}
			posArray[posNum-1].fx = px;
			posArray[posNum-1].fy = py;
		}
		private function draw():void
		{
			this.graphics.clear();
			this.graphics.beginFill(0x000000);
			this.graphics.lineStyle(1,0x000000);
			this.graphics.moveTo(posArray[0].fx, posArray[0].fy);
			for(var i:int=0; i<posNum; i++) {
				//this.graphics.lineTo(posArray[i].fx, posArray[i].fy);
				if(i==0) {
					//posArray[0].culcThic(posArray[posNum-1].fx, posArray[posNum-1].fy, posArray[posNum-1].R);
				}
				if(i>0){posArray[i].culcThic(posArray[i-1].fx, posArray[i-1].fy, posArray[i-1].R);
					//this.graphics.moveTo(posArray[i-1].fx, posArray[i-1].fy); //ひとつ前に位置だけ移動
					
					//lineTO
					this.graphics.lineTo(posArray[i].pt1x, posArray[i].pt1y);
					
					//curveTo
					/*var halfX:Number = posArray[i-1].pt1x + ( posArray[i].pt1x - posArray[i-1].pt1x ) / 2;
					var halfY:Number = posArray[i-1].pt1y + ( posArray[i].pt1y - posArray[i-1].pt1y ) / 2;
					this.graphics.curveTo(halfX, halfY, posArray[i].pt1x, posArray[i].pt1y);
					*/
					//this.graphics.lineStyle(posArray[i].R*0.5,0xffffff);
					//this.graphics.lineTo(posArray[i].fx, posArray[i].fy);
				}
				//this.graphics.lineTo(posArray[i].pt1x, posArray[i].pt1y);
			}
			
			for(i=posNum-1; i>0; i--) {
				this.graphics.lineTo(posArray[i].pt2x, posArray[i].pt2y);
			}
			this.graphics.endFill();
		}
	}



class pointerclass {
	public var fx:Number,fy:Number;
	public var pt1x:Number, pt1y:Number;
	public var pt2x:Number, pt2y:Number;
	public var R:Number=2;
	private var _pi:Number;
	public function pointerclass() {
		_pi = Math.PI;	
	}
	public function culcThic(px:Number,py:Number,pR:Number):void{
		var dx:Number = px - fx;
		var dy:Number = py - fy;
		var distance:Number = Math.sqrt(dx*dx+dy*dy);
		pR += 0.1 * (distance -pR);
		R = pR*0.6;
		
		var rnum:Number = Math.atan2(px-fx,py-fy);
		
		var myR:Number = -rnum*180/_pi;
		var myR2:Number = myR+180;
		
		pt1x = fx + R*Math.cos(myR*_pi/180); pt1y = fy + R*Math.sin(myR*_pi/180);
		pt2x = fx + R*Math.cos(myR2*_pi/180); pt2y = fy + R*Math.sin(myR2*_pi/180);
		
	}
}