flash on 2013-7-2
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ur0E
*/
package {
import flash.text.TextField;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
deb = new TextField();
deb.mouseEnabled = false;
deb.width = 320;
deb.height = 240;
addChild(deb);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var deb:TextField;
public var ang2:Number = 1;
public var ang:Number = 0;
public var cx:Number = 200;
public var cy:Number = 200;
public var arm1:xRect = new xRect();
public var arm2:xRect = new xRect();
public var arm3:xRect = new xRect();
public var barm1:xRect = new xRect();
public var barm2:xRect = new xRect();
public var barm3:xRect = new xRect();
public var hip:xRect = new xRect();
public var leg1:xRect = new xRect();
public var leg2:xRect = new xRect();
public var leg3:xRect = new xRect();
public var bleg1:xRect = new xRect();
public var bleg2:xRect = new xRect();
public var bleg3:xRect = new xRect();
public var head:xRect = new xRect();
public function onEnter(e:Event):void
{
graphics.clear();
graphics.lineStyle(2, 0);
var xang:Number;
// ang2 += 0.4;
//cx = 200 + Math.sin(ang2)*64;
cx += ang2;
if (cx > 250) { ang2 = -1;}
if (cx < 150) {ang2 = 1;}
ang += 0.1;
xang = Math.cos(ang) * Math.sin(ang);
cy = 100 + Math.sin(Math.abs(xang)*-2)*48;
head.ty = cy - 30 + Math.abs(xang)*24;
head.tx = cx+10;
graphics.drawCircle(head.tx, head.ty, 16);
graphics.drawCircle(cx, cy, 8);
graphics.moveTo(cx,cy);
graphics.lineTo(head.tx, head.ty);
//deb.text = "xang " +xang; // + "\n a3 tx " + arm3.tx + "\n ty " + arm3.ty;
deb.text = "xang " +xang + " \n sin " + Math.sin(ang);
arm1.tx = cx + Math.sin(xang*3.14)*-32;
arm1.ty = cy + Math.cos(xang*3.14)*8;
arm1.tang = xang*2;
moveRect(arm2, arm1);
arm2.cy = 32;
arm2.ang = xang;
arm3.cx = 32;
moveRect(arm3, arm2);
graphics.beginFill(0, 1);
graphics.drawCircle(arm1.tx, arm1.ty, 8);
graphics.endFill();
graphics.beginFill(0, 1);
graphics.drawCircle(arm2.tx, arm2.ty, 8);
graphics.endFill();
graphics.beginFill(0, 1);
graphics.drawCircle(arm3.tx, arm3.ty, 8);
graphics.endFill();
barm1.tx = cx + Math.sin(xang*3.14)*28; //32;
barm1.ty = cy + Math.cos(xang*3.14)*8;
barm1.tang = xang*-2;
moveRect(barm2, barm1);
barm2.cy = 32;
barm2.ang = -xang;
barm3.cx = 32;
moveRect(barm3, barm2);
graphics.drawCircle(barm1.tx, barm1.ty, 7);
graphics.drawCircle(barm2.tx, barm2.ty, 7);
graphics.drawCircle(barm3.tx, barm3.ty, 7);
graphics.moveTo(cx, cy);
graphics.lineTo(barm1.tx, barm1.ty);
graphics.moveTo(cx, cy);
graphics.lineTo(arm1.tx, arm1.ty);
hip.tx = cx - 20;
hip.ty = cy + 50;
graphics.drawCircle(hip.tx, hip.ty, 8);
graphics.moveTo(cx, cy);
graphics.lineTo(hip.tx, hip.ty);
leg1.tx = hip.tx + Math.sin(xang*3.14)*-21; //24;
leg1.ty = hip.ty + Math.cos(xang*3.14)*8;
leg1.tang = xang*2;
moveRect(leg2, leg1);
leg2.cy = 32;
leg2.ang = xang + 1;
leg3.cy = 32;
moveRect(leg3, leg2);
bleg1.tx = hip.tx + Math.sin(xang*3.14)*24;
bleg1.ty = hip.ty + Math.cos(xang*3.14)*8;
bleg1.tang = -xang*2;
moveRect(bleg2, bleg1);
bleg2.cy = 32;
bleg2.ang = -xang + 1;
bleg3.cy = 32;
moveRect(bleg3, bleg2);
graphics.beginFill(0,1);
graphics.drawCircle(bleg1.tx, bleg1.ty, 8);
graphics.endFill();
graphics.beginFill(0,1);
graphics.drawCircle(bleg2.tx, bleg2.ty, 8);
graphics.endFill();
graphics.beginFill(0,1);
graphics.drawCircle(bleg3.tx, bleg3.ty, 8);
graphics.endFill();
graphics.drawCircle(leg1.tx, leg1.ty, 7);
graphics.drawCircle(leg2.tx, leg2.ty, 7);
graphics.drawCircle(leg3.tx, leg3.ty, 7);
graphics.moveTo(hip.tx, hip.ty);
graphics.lineTo(bleg1.tx, bleg1.ty);
graphics.moveTo(hip.tx, hip.ty);
graphics.lineTo(leg1.tx, leg1.ty);
graphics.moveTo(hip.tx-32, 220);
graphics.lineTo(hip.tx+32, 220);
}//onenter
public function moveRect(a:xRect, p:xRect):void
{
var rx:Number;
var ry:Number;
var an:Number;
an = p.tang;
rx = a.cx * Math.cos(an) - a.cy * Math.sin(an);
ry = a.cx * Math.sin(an) + a.cy * Math.cos(an);
a.tx = p.tx + rx;
a.ty = p.ty + ry;
a.tang = a.ang + p.tang;
}//movepar
}//classend
}
internal class xRect
{
public var cx:Number = 0;
public var cy:Number = 0;
public var ang:Number = 0;
public var rad:Number = 8;
public var tx:Number = 0;
public var ty:Number = 0;
public var tang:Number = 0;
}//xrect