# A dancing bone villain.

Source: Internet
Author: User

Not long ago, in a book about Matlab to see an example, with a drawing function to draw a villain.

The effect is as follows:

Just like the following:

Since this villain can draw out, then whether to let him move, I think this is obviously no problem, as long as the various parts of the body to decompose open on it.
There are only two components of this villain, one is a circle, the other is a line.
The code is as follows:

Class Skelectoncircle
{
private Var x:number=0;
private Var y:number=0;
private Var r:number=0;
private Var linestylenum:number=0x3399ff;

Static private Var mid:number=0;
private Var Mmcholder:movieclip;

Public Function skelectoncircle (inx:number,iny:number,inr:number,instyle:number)
{
Init (Inx,iny,inr,instyle);
}

Public function init (inx:number,iny:number,inr:number,instyle:number): Void
{
Reset (Inx,iny,inr,instyle);

Mmcholder=_root.createemptymovieclip ("__skeletonc__" +mid,_root.getnexthighestdepth ());
mid++;
}

Public function Reset (inx:number,iny:number,inr:number,instyle:number): Void
{
X=inx;
Y=iny;
R=inr;

if (instyle!=null| | instyle!=undefined) linestylenum=0x3399ff;
else Linestylenum=instyle;
}

Public Function Draw (): Void
{
Draw a cicle:
Mmcholder.linestyle (1,linestylenum,100);
Beginfill (0X6666FF);
Move to the circle ' s center.
Mmcholder.moveto (X+r,y);

var fi:number=0;
var cx:number=0;
var cy:number=0;
var detafi:number=0.1;

while (fi<=2*math.pi+0.2)
{
Cx=x+r*math.cos (FI);
Cy=y+r*math.sin (FI);
Mmcholder.lineto (Cx,cy);
Fi+=detafi;
}
Endfill ();
}

Public Function Clean (): Void
{
Mmcholder.clear ();
}

Public Function toString (): String
{
var restring:string=new String ();

Restring=string ("x:" +string (x) + "Y:" +string (y) + "R:" +string (r) + "\ n");

return restring;
}

Public Function Finallize (): Void
{
Mmcholder.removemovieclip ();
Mmcholder=null;
Delete this;
}
}

Class Skelectonline
{
private Var x1:number=0;
private Var y1:number=0;

private Var x2:number=0;
private Var y2:number=0;

private Var linestylenum:number=0x3399ff;

Static private Var mid:number=0;
private Var Mmcholder:movieclip;

Static private Var Thisp:object;

Public Function skelectoncircle (inx1:number,iny1:number,inx2:number,iny2:number,instyle:number)
{
Init (Inx1,iny1,inx2,iny2,instyle);
}

Public function init (inx1:number,iny1:number,inx2:number,iny2:number,instyle:number): Void
{
Reset (Inx1,iny1,inx2,iny2,instyle);

Mmcholder=_root.createemptymovieclip ("__skeletonl__" +mid,_root.getnexthighestdepth ());
mid++;

Thisp=this;
}

Public function Reset (inx1:number,iny1:number,inx2:number,iny2:number,instyle:number): Void
{
X1=INX1;
Y1=iny1;

X2=INX2;
Y2=iny2;

if (instyle!=null| | instyle!=undefined) linestylenum=0x3399ff;
else Linestylenum=instyle;
}

Public Function Draw (): Void
{
Draw a line:
Mmcholder.linestyle (1,linestylenum,100);
Mmcholder.moveto (X1,Y1);
Mmcholder.lineto (X2,Y2);

}

Public Function Clean (): Void
{
Mmcholder.clear ();
}

Public Function toString (): String
{
var restring:string=new String ();
Restring=string ("x1:" +string (x1) + "Y1:" +string (y1) + "X2:" +string (x2) + "y2:" +string (y2) + "\ n");
return restring;
}

Public Function Finallize (): Void
{
Mmcholder.removemovieclip ();
Mmcholder=null;
Delete this;
}
}

Next, we define a small human, a total of 11 parts, specifically what you look at the know:

Class Skelectonperson
{

public Var mleftshoulder:skelectonline;
public Var mrightshoulder:skelectonline;

public Var mupbody:skelectonline;
public Var mdownbody:skelectonline;

public Var mlefthand:skelectonline;
public Var mrighthand:skelectonline;

public Var mleftthigh:skelectonline;
public Var mrightthigh:skelectonline;

public Var mleftleg:skelectonline;
public Var mrightleg:skelectonline;

Public Function Skelectonperson ()
{
Mleftshoulder=new Skelectonline ();
Mrightshoulder=new Skelectonline ();
Mupbody=new Skelectonline ();
Mdownbody=new Skelectonline ();
Mlefthand=new Skelectonline ();
Mrighthand=new Skelectonline ();
Mleftthigh=new Skelectonline ();
Mrightthigh=new Skelectonline ();
Mleftleg=new Skelectonline ();
Mrightleg=new Skelectonline ();
}

Public Function Draw (): Void
{
Mleftshoulder.draw ();
Mrightshoulder.draw ();
Mupbody.draw ();
Mdownbody.draw ();
Mlefthand.draw ();
Mrighthand.draw ();
Mleftthigh.draw ();
Mrightthigh.draw ();
Mleftleg.draw ();
Mrightleg.draw ();
}

Public Function Clean (): Void
{
Mleftshoulder.clean ();
Mrightshoulder.clean ();
Mupbody.clean ();
Mdownbody.clean ();
Mlefthand.clean ();
Mrighthand.clean ();
Mleftthigh.clean ();
Mrightthigh.clean ();
Mleftleg.clean ();
Mrightleg.clean ();
}
}

And then you assemble the parts of the villain:

var testperson:skelectonperson=new skelectonperson ();
TestPerson.mLeftShoulder.init (140,80,180,80);
TestPerson.mRightShoulder.init (180,80,220,80);
TestPerson.mLeftHand.init (110,40,140,80);
TestPerson.mRightHand.init (250,40,220,80);
TestPerson.mUpBody.init (180,50,180,80);
TestPerson.mDownBody.init (180,80,180,120);
TestPerson.mLeftThigh.init (180,120,150,150);
TestPerson.mRightThigh.init (180,120,210,150);
TestPerson.mLeftLeg.init (150,150,150,200);
TestPerson.mRightLeg.init (210,150,210,200);

Finally, let's end the experiment with a little man's hand in a waving motion 1:
I feel the most headaches in this experiment is the flash tangent angle of the calculation of the way, engaged in a half-day is OK, hehe ~ ~:)
Calling segment Code

Testperson.draw ();

/*----Test 1:data init.----* *
Handlen=math.sqrt ((110-140) * (110-140) + (40-80) * (40-80));
Left hand data.
x0[0]=110;
y0[0]=40;
Left Hand axes Center
x1[0]=140;
y1[0]=80;

Right hand data.
x0[1]=250;
y0[1]=40;
Right hand axes Center
x1[1]=220;
y1[1]=80;

Fi0=eatan2 (X0[0]-x1[0],y0[0]-y1[0]);
Fi1=eatan2 (x0[1]-x1[1],y0[1]-y1[1]);

detafi0=0.05;
detafi1=-0.05;

SetInterval (handmove,200);
/*---End of TEST 1---* *

Main motion function:
Skelecton person Test1:
function Handmove ()
{
Left hand move.
if (fi0>=-2*math.pi/3| | FI0&LT;=-5*MATH.PI/6)
Detafi0*=-1;

X0[0]=x1[0]+_root.handlen*math.cos (FI0);
Y0[0]=y1[0]+_root.handlen*math.sin (FI0);

_root.testperson.mlefthand.reset (X0[0],y0[0],x1[0],y1[0]);

_root.testperson.mlefthand.clean ();
_root.testperson.mlefthand.draw ();
Fi0+=detafi0;

Right hand move
if (fi1>=-math.pi/6| | FI1&LT;=-MATH.PI/3)
Detafi1*=-1;

X0[1]=x1[1]+_root.handlen*math.cos (FI1);
Y0[1]=y1[1]+_root.handlen*math.sin (FI1);

_root.testperson.mrighthand.reset (x0[1],y0[1],x1[1],y1[1]);

_root.testperson.mrighthand.clean ();
_root.testperson.mrighthand.draw ();
FI1+=DETAFI1;

}

Testperson.draw ();

/*----Test 1:data init.----* *
Handlen=math.sqrt ((110-140) * (110-140) + (40-80) * (40-80));
Left hand data.
x0[0]=110;
y0[0]=40;
Left Hand axes Center
x1[0]=140;
y1[0]=80;

Right hand data.
x0[1]=250;
y0[1]=40;
Right hand axes Center
x1[1]=220;
y1[1]=80;

Fi0=eatan2 (X0[0]-x1[0],y0[0]-y1[0]);
Fi1=eatan2 (x0[1]-x1[1],y0[1]-y1[1]);

detafi0=0.05;
detafi1=-0.05;

SetInterval (handmove,200);
/*---End of TEST 1---* *

Main motion function:
Skelecton person Test1:
function Handmove ()
{
Left hand move.
if (fi0>=-2*math.pi/3| | FI0&LT;=-5*MATH.PI/6)
Detafi0*=-1;

X0[0]=x1[0]+_root.handlen*math.cos (FI0);
Y0[0]=y1[0]+_root.handlen*math.sin (FI0);

_root.testperson.mlefthand.reset (X0[0],y0[0],x1[0],y1[0]);

_root.testperson.mlefthand.clean ();
_root.testperson.mlefthand.draw ();
Fi0+=detafi0;

Right hand move
if (fi1>=-math.pi/6| | FI1&LT;=-MATH.PI/3)
Detafi1*=-1;

X0[1]=x1[1]+_root.handlen*math.cos (FI1);
Y0[1]=y1[1]+_root.handlen*math.sin (FI1);

_root.testperson.mrighthand.reset (x0[1],y0[1],x1[1],y1[1]);

_root.testperson.mrighthand.clean ();
_root.testperson.mrighthand.draw ();
FI1+=DETAFI1;

}

Testperson.draw ();

/*----Test 1:data init.----* *
Handlen=math.sqrt ((110-140) * (110-140) + (40-80) * (40-80));
Left hand data.
x0[0]=110;
y0[0]=40;
Left Hand axes Center
x1[0]=140;
y1[0]=80;

Right hand data.
x0[1]=250;
y0[1]=40;
Right hand axes Center
x1[1]=220;
y1[1]=80;

Fi0=eatan2 (X0[0]-x1[0],y0[0]-y1[0]);
Fi1=eatan2 (x0[1]-x1[1],y0[1]-y1[1]);

detafi0=0.05;
detafi1=-0.05;

SetInterval (handmove,200);
/*---End of TEST 1---* *

Main motion function:
Skelecton person Test1:
function Handmove ()
{
Left hand move.
if (fi0>=-2*math.pi/3| | FI0&LT;=-5*MATH.PI/6)
Detafi0*=-1;

X0[0]=x1[0]+_root.handlen*math.cos (FI0);
Y0[0]=y1[0]+_root.handlen*math.sin (FI0);

_root.testperson.mlefthand.reset (X0[0],y0[0],x1[0],y1[0]);

_root.testperson.mlefthand.clean ();
_root.testperson.mlefthand.draw ();
Fi0+=detafi0;

Right hand move
if (fi1>=-math.pi/6| | FI1&LT;=-MATH.PI/3)
Detafi1*=-1;

X0[1]=x1[1]+_root.handlen*math.cos (FI1);
Y0[1]=y1[1]+_root.handlen*math.sin (FI1);

_root.testperson.mrighthand.reset (x0[1],y0[1],x1[1],y1[1]);

_root.testperson.mrighthand.clean ();
_root.testperson.mrighthand.draw ();
FI1+=DETAFI1;

}

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.