forked from: forked from: Let's rendezvous
クリックしたら集まるよ
// forked from satomin02's forked from: Let's rendezvous
// forked from Kay's Let's rendezvous
/*
* クリックしたら集まるよ
*/
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Matrix;
import flash.geom.Matrix3D;
import flash.geom.Vector3D;
import flash.geom.Utils3D;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(width="400", height="400", backgroundColor="0xffddff")]
public class Take03 extends Sprite {
private const SW:Number = stage.stageWidth;
private const SH:Number = stage.stageHeight;
private var world:Sprite = new Sprite();
private var worldMatrix:Matrix3D = new Matrix3D();
private var dotP:Vector.<Vector3D> = new Vector.<Vector3D>();
private const dotRadius:Number = 2.5;
private var rendezvousRatio:Number = 1;
private var rendezvousPlace:Vector3D;
private var rendezvousFlag:Boolean = false;
public function Take03():void {
world = new Sprite;
world.x = SW/2;
world.y = SH/2;
addChild(world);
// 到達位置を決める
var textformat:TextFormat = new TextFormat();
textformat.bold = true;
textformat.font = "Arial Black";
textformat.size = 80;
var textfield:TextField = new TextField();
textfield.defaultTextFormat = textformat;
textfield.autoSize = "left";
textfield.text = "wonderfl";
var bitmapdata:BitmapData = new BitmapData(textfield.width,textfield.height,true,0x000000);
var matrix:Matrix = new Matrix();
bitmapdata.draw(textfield,matrix);
for (var nY:uint = 0; nY <= bitmapdata.height; nY+=(dotRadius*2)) {
for (var nX:uint = 0; nX<= bitmapdata.width; nX+=(dotRadius*2)) {
if (bitmapdata.hitTest(new Point(0,0), 0x00, new Point(nX, nY))) {
var pos:Vector3D = new Vector3D(nX-bitmapdata.width/2, nY-bitmapdata.height/2, 0);
dotP.push(pos);
var dot:Dot = new Dot();
dot.x = dot.home.x = Math.random()*SW-SW/2;
dot.y = dot.home.y = Math.random()*SH-SH/2;
dot.z = dot.home.z = Math.random()*SW-SW/2;
world.addChild(dot);
}
}
}
addEventListener(Event.ENTER_FRAME, sRotate);
stage.addEventListener(MouseEvent.CLICK, xRendezvous);
}
private function sRotate(e:Event):void {
if (rendezvousFlag == true) {
// 集合
if (rendezvousRatio <= 0) {
rendezvousRatio = 0;
rendezvousFlag = false;
}
rendezvousRatio-=0.02;
} else if (rendezvousRatio < 1) {
// 解散
rendezvousRatio+=0.02;
}
worldMatrix.appendRotation(0.2, Vector3D.X_AXIS);
worldMatrix.appendRotation(0.4, Vector3D.Z_AXIS);
for (var i:uint=0; i < world.numChildren; i++) {
var dot:Object = world.getChildAt(i);
var vec:Vector3D = Utils3D.projectVector(worldMatrix, dot.home);
if (rendezvousRatio < 1) {
if (rendezvousFlag == true) {
// この部分が非常にいけてない
dot.x = (rendezvousPlace.x+dotP[i].x)*(1-rendezvousRatio) + (dot.x*rendezvousRatio);
dot.y = (rendezvousPlace.y+dotP[i].y)*(1-rendezvousRatio) + (dot.y*rendezvousRatio);
dot.z = (rendezvousPlace.z+dotP[i].z)*(1-rendezvousRatio) + (dot.z*rendezvousRatio);
} else {
dot.x = 2+vec.x - (vec.x - dot.x)*(1-rendezvousRatio);
dot.y = vec.y - (vec.y - dot.y)*(1-rendezvousRatio);
dot.z = vec.z - (vec.z - dot.z)*(1-rendezvousRatio);
}
} else {
dot.x = vec.x;
dot.y = vec.y;
dot.z = vec.z;
}
}
}
private function xRendezvous(e:MouseEvent):void {
if (rendezvousFlag == false) {
rendezvousRatio = 1;
rendezvousFlag = true;
rendezvousPlace = new Vector3D(mouseX-SW/2,mouseY-SH/2,Math.abs(mouseX-SW/2)*1.5);
}
}
}
}
import flash.display.Shape;
import flash.geom.Vector3D;
import flash.geom.Matrix3D;
class Dot extends Shape {
public var home:Vector3D = new Vector3D(1,1,1);
public function Dot():void {
graphics.beginFill(0xff0000);
graphics.drawCircle(0,0,2);
graphics.endFill();
}
}