内積
MainStage
♥0 |
Line 84 |
Modified 2010-08-21 04:30:48 |
MIT License
archived:2017-03-20 16:06:33
ActionScript3 source code
/**
* Copyright hashito ( http://wonderfl.net/user/hashito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ovw6
*/
// forked from hashito's 文字集まる修正
// MainStage
package {
import flash.display.Sprite;
[SWF(frameRate=60,width=456,height=456)]
public class MainStage extends Sprite {
public function MainStage(){
addChild(new Main());
}
}
}
import flash.display.*;
import flash.filters.BlurFilter;
import flash.geom.Point;
import flash.geom.ColorTransform;
import flash.events.*;
import flash.utils.Timer;
import flash.text.TextField;
import flash.text.TextFormat;
import net.hires.debug.Stats;
// debug
class debug{public static var out:TextField=new TextField();}
/*t.hashito*/
class MF{
public static function AFFORD (x:Number,aim:Number,a:Number):Boolean{return (x<=(a+aim))&&(x>=(a-aim));}
public static function RAN (n:Number=1):Number{return (Math.random()*n);}
public static function ISPM (n:Number):Number{if(n<0){return -1;}else if(n>0){return 1;}return 0;}
public static function MAX (n:Number,max:Number):Number{return (n>max)?max:n;}
public static function MIN (n:Number,min:Number):Number{return (n<min)?min:n;}
public static function LIMIT (n:Number,max:Number,min:Number):Number{if(n>max){return max;}else if(n<min){return min;}else{return n};}
public static function RAD_ANG(n:Number):Number{return n*180/Math.PI}
public static function ANG_RAD(n:Number):Number{return n*Math.PI/180 }
public static function LATCH(v:Boolean,s:Boolean,r:Boolean):Boolean{if(s)v=true;if(r)v=false;return v;}
public static function ONE_SHOT_ON(v:Boolean,o:Boolean):Boolean{var r:Boolean = (v==(!o));o=v;return r;}
public static function DOT2(x1:Number,y1:Number,x2:Number,y2:Number):Number{return x1 * x2 + y1 * y2; }//内積
}
class Main extends Sprite{
public const H:Number = 456,W:Number = 456;
public var mx:Number = 0,my:Number = 0;
public var ksp:Boolean = false;
public var la:Shape = new Shape(),la1x:Number,la1y:Number,la2x:Number,la2y:Number;
public var lb:Shape = new Shape(),lb1x:Number,lb1y:Number,lb2x:Number,lb2y:Number;
public var cross:Shape = new Shape();
public var selectball:Shape = new Shape();
public var select:int = 0;
public const SELMAX:int = 4;
// constructor
public function Main() {addEventListener(Event.ADDED_TO_STAGE, init);}
// init
public function init(e:*):void{
// debug
debug.out.autoSize=flash.text.TextFieldAutoSize.LEFT;
debug.out.x=W/2;
debug.out.y=H/2;
addChild(debug.out);
la1x = H/4*3;
la1y = H/2;
la2x = W/2;
la2y = H/2;
lb1x = H/4*3;
lb1y = H/2;
lb2x = W/2;
lb2y = H/2;
//line init
addChild(la);
addChild(lb);
// cross init
cross.graphics.beginFill(0x000000);
cross.graphics.drawCircle(0,0,3);
addChild(cross);
// selectball init
selectball.graphics.beginFill(0x00ffff);
selectball.graphics.drawCircle(0,0,3);
addChild(selectball);
addEventListener(Event.ENTER_FRAME ,ef);
var s:Stats = new Stats();
addChild(s);
}
public function ef(e:Event=null):void{
la1x=mouseX;
la1y=mouseY;
selectball.x=mx;
selectball.y=my;
la.graphics.clear();
la.graphics.lineStyle(2,0xff0000);
la.graphics.moveTo(la1x,la1y);
la.graphics.lineTo(la2x,la2y);
lb.graphics.clear();
lb.graphics.lineStyle(2,0xffff00);
lb.graphics.moveTo(lb1x,lb1y);
lb.graphics.lineTo(lb2x,lb2y);
debug.out.text =""+MF.DOT2(la1x-W/2,la1y-H/2,lb1x-W/2,lb1y-H/2);
//debug.out.text="x="+t.bits[0].x+" y="+t.bits[0].y+" vx="+t.bits[0].vx+" vy="+t.bits[0].vy+" ax="+t.bits[0].ax+" ay="+t.bits[0].ay;
}
}