unit URealMovie; interface uses math,flash8; const Pi = 3.14159265359; type Tpoint=record x,y:number; end; TArrayofPoint = array of TPoint; RealMovie = class(MovieClip) graph_width,graph_height:integer; xmin, xmax, ymin ,ymax , xsize ,ysize , Gx, Gy ,xo ,yo: number; Procedure RMoveTo(x,y:number); Procedure RMoveTo2(pt:TPoint); Procedure RLineTo(x,y:number); Procedure RLineTo2(pt:TPoint); Procedure RLine(x1,y1,x2,y2:number); procedure RLine2(pt1,pt2:Tpoint); Procedure RPolyline(courbe:array of TPoint); Procedure Rrectangle(x1,y1,x2,y2:number); Procedure Rrectangle2(pt1,pt2:TPoint); procedure RRoundrect(x,y,w,h,radius:number); Procedure RCircle(Cx,Cy,Radius:number); Procedure RCurveTo(x1,y1,x2,y2:number); procedure RArrow(x1,y1,x2,y2:number;col,penw:integer); //flèche procedure RArrow2(Fx,Fy,norme,alpha:number;col,penw:integer);//en coords polaires /alpha en ° procedure Rdisquegradue(xc,yc,R,L:number;n:integer); function Rrotationarraypoint(xc,yc,theta:number;figure:array of Tpoint):TarrayofPoint; procedure RTextout(x,y,width,height,Depth:number;font:TextFormat;text:String); procedure Rdisquegradtextout(xc,yc,R:number;n:integer;font:TextFormat;text:array of String); procedure setSize(w, h: Integer; x1, y1, x2, y2: Number); end; function IntToStr2(i: Integer): string; function pt(x,y:number):TPoint; function FloattostrF(num:number;digit:integer):String; function sqr(n:number):number; implementation // Méthodes de dessin de Realmovie function sqr(n:number):number; begin result:=n*n; end; function IntToStr2(i: Integer): string; begin Result := IntToStr(i); if i < 10 then Result := '0' + Result; end; function pt(x,y:number):TPoint; begin result.x:=x; result.y:=y; end; function FloattostrF(num:number;digit:integer):String; var int:integer; frac,frac1,frac2,newnum:number; begin int:=trunc(num); frac:=num-int; frac1:=trunc(pow(10,digit)*frac)/pow(10,digit); frac2:= trunc(pow(10,digit+1)*frac)/pow(10,digit+1); if (frac2-frac1)*pow(10,digit+1)>=5 then newnum:=int+frac1+pow(10,-digit) else newnum:=int+frac1; result:=floattostr(newnum); end; procedure RealMovie.RRoundrect(x,y,w,h,radius:number); var r,b,xe,ye,we,he:number; begin xe:=xo+x*Gx; ye:=yo-y*Gy; we:=w*Gx; he:=h*Gy; r := xe + we; b := ye + he; moveTo(xe+radius, ye); lineTo(r-radius, ye); CurveTo(r, ye, r, ye+radius); lineTo(r, ye+he-radius); CurveTo(r, b, r-radius, b); lineTo(xe+radius, b); CurveTo(xe, b, xe, b-radius); lineTo(xe, ye+radius); CurveTo(xe, ye, xe+radius, ye); end; Procedure RealMovie.RMoveTo(x,y:number); begin Moveto(xo+x*Gx,yo-y*Gy); end; Procedure RealMovie.RMoveTo2(pt:TPoint); begin Moveto(xo+pt.x*Gx,yo-pt.y*Gy); end; Procedure RealMovie.RLineTo(x,y:number); begin Lineto(xo+x*Gx,yo-y*Gy); end; Procedure RealMovie.RLineTo2(pt:TPoint); begin Lineto(xo+pt.x*Gx,yo-pt.y*Gy); end; Procedure RealMovie.RLine(x1,y1,x2,y2:number); begin RMoveto(x1,y1); RLineto(x2,y2); end; procedure RealMovie.RLine2(pt1,pt2:Tpoint); begin RLine(pt1.x,pt1.y,pt2.x,pt2.y); end; Procedure RealMovie.RPolyline(courbe:array of TPoint); var i:integer; begin RMoveto2(courbe[0]); for i:=1 to high(courbe) do Rlineto2(courbe[i]); end; Procedure RealMovie.Rrectangle(x1,y1,x2,y2:number); begin RMoveto(x1,y1); RLineTo(x2,y1); RLineto(x2,y2); RLineto(x1,y2); RLineto(x1,y1); end; Procedure RealMovie.Rrectangle2(pt1,pt2:TPoint); begin RMoveto2(pt1); RLineTo(pt2.x,pt1.y); RLineto2(pt2); RLineto(pt1.x,pt2.y); RLineto2(pt1); end; Procedure RealMovie.Rcircle(Cx,Cy,Radius:number); //si orthonormé var a,b,R: number; begin R:=radius*Gx; Cx:=xo+Cx*Gx; Cy:=yo-Cy*Gy; a:= R * 0.414213562; b:= R * 0.707106781; moveTo(Cx+R,Cy); CurveTo(Cx+ R, Cy+-a, Cx+b,Cy -b); CurveTo(Cx+ a,Cy-R,Cx,Cy -r); CurveTo(Cx-a,Cy -R,Cx-b,Cy -b); CurveTo(Cx-R, Cy-a,Cx-R,Cy); CurveTo(Cx-R,Cy+a,Cx-b,Cy+b); CurveTo(Cx-a,Cy +R,Cx,Cy+r); CurveTo(Cx+a,Cy +R,Cx+b,Cy+b); CurveTo(Cx+R,Cy+a,Cx+R,Cy); end; Procedure RealMovie.RArrow(x1,y1,x2,y2:number;col,penw:integer);//flèche var i:integer; Norme,cX,cY: number; ALength,AWidth:number; //longueur et largeur de la pointe Arrow:array of TPoint; begin ALength:=10; AWidth:=7; x1:=xo+x1*Gx; x2:=xo+x2*Gx; y1:=yo-y1*Gy; y2:=yo-y2*Gy; Norme:=SQRT((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); if Norme=0 then Exit; cX:=(x2-x1)/Norme; cY:=(y2-y1)/Norme; Arrow[0]:=pt(x2,y2); Arrow[1]:=pt(x2-cX*ALength+cY*AWidth,y2-cY*ALength-cX*AWidth); Arrow[2]:=pt(x2-cX*ALength-cY*AWidth,y2-cY*ALength+cX*AWidth); Arrow[3]:=pt(x2,y2); Linestyle(penw,col); BeginFill(col); Moveto(x1,y1); Lineto(x2,y2); Moveto(arrow[0].x,arrow[0].y); for i:=1 to 3 do lineto(arrow[i].x,arrow[i].y); Endfill(); end; procedure RealMovie.RArrow2(Fx,Fy,norme,alpha:number;col,penw:integer);//Flèche en coords polaires var theta: number; L,L1: number; xf1,yf1 :number; xf2,yf2 :number; x,y : number; begin alpha:=pi*alpha/180; x:=norme*cos(alpha); y:=norme*sin(alpha); if x<>0.0 then theta:=atan2(y,x) else theta:=0; L:=sqrt((x*x)+(y*y))/10; L1:=L/2; xf1:=-L*cos(theta)-L1*sin(theta); xf2:=-L*cos(theta)+L1*sin(theta); yf1:=-L*sin(theta)+L1*cos(theta); yf2:=-L*sin(theta)-L1*cos(theta); linestyle(penw,col); RLine(Fx,Fy,Fx+x,Fy+y); RLine(x+Fx,y+Fy,x+Fx+xf1,y+Fy+yf1); RLine(x+Fx,y+Fy,x+Fx+xf2,y+Fy+yf2); end; procedure RealMovie.RCurveto(x1,y1,x2,y2:number); begin curveto(xo+x1*Gx,yo-y1*Gy,xo+x2*Gx,yo-y2*Gy); end; procedure RealMovie.Rdisquegradue(xc,yc,R,L:number;n:integer); var phi:number; i:integer; pt1,pt2:Tpoint; begin phi:=2*pi/n; for i:=0 to n do begin pt1:=pt(xc+(R-L)*cos(i*phi),yc+(R-L)*sin(i*phi)); pt2:=pt(xc+R*cos(i*phi),yc+R*sin(i*phi)); RLine2(pt1,pt2); end; end; function RealMovie.Rrotationarraypoint(xc,yc,theta:number;figure:array of Tpoint):TarrayofPoint; var i:integer; Rayon,phi:array of number; O:TPoint; ptarray:array of Tpoint; begin O:=pt(xo+Gx*xc,yo-Gy*yc); i := 4; for i:=low(figure) to high(figure) do begin ptarray[i]:=pt(xo+Gx*figure[i].x,yo-Gy*figure[i].y); if ptarray[i].x-O.x<>0 then phi[i]:=atan2(ptarray[i].y-O.y,ptarray[i].x-O.x) else phi[i]:=-pi/2; Rayon[i]:=round(sqrt(sqr(ptarray[i].x-O.x)+sqr(ptarray[i].y-O.y))); ptarray[i].x:=O.x+Rayon[i]*cos(theta+phi[i]); ptarray[i].y:=O.y+Rayon[i]*sin(theta+phi[i]); result[i]:=pt(ptarray[i].x,ptarray[i].y); end; end; procedure RealMovie.RTextout(x,y,width,height,Depth:number;font:TextFormat;text:String); var Field:TextField; begin Field:=TextField.Create(self,'',Depth,xo+Gx*(x),yo-Gy*(y),width,height); Field.setNewTextFormat(font); Field.text:=text; end; procedure RealMovie.Rdisquegradtextout(xc,yc,R:number;n:integer;font:TextFormat;text:array of String); var i:integer; x,y,phi:number; begin phi:=2*Pi/n; for i:=1 to n do begin x:=xc+R*cos(pi/2-i*phi); y:=yc+R*sin(pi/2-i*phi); RTextout(x,y,25,20,i,font,text[i]); end; end; procedure RealMovie.setSize(w, h: Integer; x1, y1, x2, y2: Number); begin graph_width:=w; graph_height:=h; xmin := x1; xmax := x2; ymin := y1; ymax := y2; xsize:= xmax - xmin; ysize:= ymax - ymin; Gx := graph_width / xsize; Gy := graph_height/ ysize; xo :=-xmin * Gx; yo := ymax * Gy; end; //fin méthodes realmovie end.