flash on 2013-11-22
♥0 |
Line 53 |
Modified 2013-11-22 23:43:31 |
MIT License
archived:2017-03-30 11:54:38
ActionScript3 source code
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/mjBu
*/
package {
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public var deb:TextField;
public function FlashTest() {
deb = new TextField();
deb.mouseEnabled = false;
deb.width = 320;
deb.height = 240;
addChild(deb);
//ok so this is an experiment
//to cancel out some of the velocity (nx,ny)
//based on the gravity vector (kx, ky)
//i was actually just messing around
//but i think i still used vector projection unknowingly
// anyway, it seems to work at least
graphics.clear();
graphics.lineStyle(2,0);
var a:Number;
var nx:Number;
var ny:Number;
var cx:Number;
var cy:Number;
var kx:Number;
var ky:Number;
cx = 200;
cy = 200;
a = 0.6;
nx = Math.cos(a);
ny = Math.sin(a);
nx *= 3;
ny *= 3;
var ga:Number;
ga = 1.57; //down (y+)
//ga = 3.84;
//ga = 0
//ga = 1.57+0.6;
//kx = 0;
//ky = 1;
kx = Math.cos(ga);
ky = Math.sin(ga);
//origin
graphics.drawCircle(cx,cy,16);
//original velocity in black
graphics.moveTo(cx, cy);
graphics.lineTo(cx+nx*64,cy+ny*64);
//gravity (direction) in light blue
graphics.lineStyle(2, 0xFF,0.3);
graphics.moveTo(cx,cy);
graphics.lineTo(cx+kx*64,cy+ky*64);
kx = -kx;
ky = -ky;
//opposite of gravity (direction) in blue
graphics.lineStyle(2, 0xFF);
graphics.moveTo(cx,cy);
graphics.lineTo(cx+kx*64,cy+ky*64);
var d:Number;
d = kx*nx + ky*ny;
deb.text = " " + d + " " + kx*d + " " + ky*d;
nx -= kx*d;
ny -= ky*d;
//final velocity in red
graphics.lineStyle(2, 0xFF0000);
graphics.moveTo(cx, cy);
graphics.lineTo(cx+nx*64,cy+ny*64);
}//ctor
}//classend
}