1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
|
program Graph;
uses
Flash8,Key,math;
{$BACKGROUND $ffffff}
{$FRAME_WIDTH 1000}
{$FRAME_HEIGHT 290}
{$FRAME_RATE 30}
const
graph_width=1000;
graph_height=250;
xmin = -12;
xmax = +12;
ymin = - 1;
ymax = + 5;
xsize= xmax - xmin;
ysize= ymax - ymin;
Gx = graph_width / xsize;
Gy = graph_height/ ysize;
xo =-xmin * Gx;
yo = ymax * Gy;
Pi = 3.141592654;
angle = Pi/180; //1° à chaque frame
phi = pi/2;//pour le décalage des rayons
type
TRpoint = external class(flash.geom.Point)
constructor Create(x, y: double);
property x: double;
property y: double;
end;
TTrackcur=class(MovieClip)
indice:integer;
xcur,ycur:array of Integer;
downcur:array of Boolean;
xmouse:array of integer;
trackmin,trackmax: array of Integer;
Position:array of Double;
constructor Create(AOWNER:Movieclip;Depth,number:integer;trmin,trmax:integer;posi:Double);
procedure doClick;
procedure doenterframe;
procedure domouseup;
end;
TTrackbar=class(MovieClip)
cur:array of TTrackcur;
procedure DrawTrackbar(BackColor,penColor,Width, Height: Integer);
constructor Create(AOWNER:Movieclip;Depth,number,trmin,trmax:integer;posi:Double);
end;
TButton=class(MovieClip)
Caption: TextField;
constructor Create(AOWNER:Movieclip);
procedure GetFont;
procedure DrawButton(BackColor, TopColor, BottomColor, Width, Height: Integer);
procedure DoClick;
end;
TLabel=class(TextField)
LbFont : TextFormat;
function FloattostrF(number:Double;digit:integer):String;
constructor Create(Parent:MovieClip; depth,left,top,width,height:integer);
end;
RealMovie = class(MovieClip)
Arrow: Array of TRPoint;
Procedure RMoveTo(x,y:double);
Procedure RLineTo(x,y:double);
Procedure RLine(x1,y1,x2,y2:double);
Procedure RPolyline;// pas de possibilité de mettre un array of TRpoint en paramètre
Procedure Rrectangle(x1,y1,x2,y2:double);
Procedure RCircle(Cx,Cy,Radius:double);
Procedure RCurveTo(x1,y1,x2,y2:double);
procedure RArrow(x1,y1,x2,y2:double;col,penw:integer); //flèche
procedure RArrow2(Fx,Fy,norme,alpha:double;col,penw:integer);//en coords polaires /alpha en °
end;
TGraphe = class(RealMovie)
permute: Boolean;
xcy, ycy : Double; //coords point cycloïde
xR,yR: Double; //coords. du centre de la roue
theta,dtheta: Double;//angle de rotation de la roue +incrément
Roue:RealMovie;
button: TButton;
ToolRayon,ToolSpeed:TLabel;
Trackbar,Trackbar2:TTrackbar;
constructor Create;
procedure GetPoint;
procedure onEnterFrame;
end;
var courbe:array of TRpoint;//Je suis obligé de déclarer le tableau ici et pas dans Realmovie car roue.courbe et bien, ça ne marche pas...
//le dimensionnement est inutile... donc je le laisse de côté.
tabmax:integer;// dimension de courbe
Font : TextFormat;
Bascule: Boolean;
h,w:integer; //taille du trackbar
c:array[1..2,1..2] of integer;//centre des arrondis de trackbar (dommage, on ne peut pas le déclarer en variable locale dans Drawtrackbar ! )
radius : Double; //rayon de la roue
graphe:Tgraphe;
// Méthodes de dessin de Realmovie
Procedure RealMovie.RMoveTo(x,y:double);
begin
Moveto(xo+x*Gx,yo-y*Gy);
end;
Procedure RealMovie.RLineTo(x,y:double);
begin
Lineto(xo+x*Gx,yo-y*Gy);
end;
Procedure RealMovie.RLine(x1,y1,x2,y2:double);
begin
RMoveto(x1,y1);
RLineto(x2,y2);
end;
Procedure RealMovie.RPolyline;
var i:integer;
begin
RMoveto(courbe[0].x,courbe[0].y);
for i:=1 to tabmax-1 do Rlineto(courbe[i].x,courbe[i].y);
end;
Procedure RealMovie.Rrectangle(x1,y1,x2,y2:double);
begin
RMoveto(x1,y1);
RLineTo(x2,y1);
RLineto(x2,y2);
RLineto(x1,y2);
RLineto(x1,y1);
end;
Procedure RealMovie.Rcircle(Cx,Cy,Radius:double); //si orthonormé
var a,b: Double;
R: Double;
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:double;col,penw:integer);//flèche
var i:integer;
Norme,cX,cY: double;
ALength,AWidth:double; //longueur et largeur de la pointe
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]:=TRPoint.create(x2,y2);
Arrow[1]:=TRPoint.create(x2-cX*ALength+cY*AWidth,y2-cY*ALength-cX*AWidth);
Arrow[2]:=TRPoint.create(x2-cX*ALength-cY*AWidth,y2-cY*ALength+cX*AWidth);
Arrow[3]:=TRPoint.create(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:double;col,penw:integer);//Flèche en coords polaires
var theta: Double;
L,L1: Double;
xf1,yf1 :Double;
xf2,yf2 :Double;
x,y : Double;
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:double);
begin
curveto(xo+x1*Gx,yo-y1*Gy,xo+x2*Gx,yo-y2*Gy);
end;
//fin méthodes realmovie
constructor TGraphe.Create;
var
i : Integer;
begin
inherited Create(nil, 'graphe', 0);
_x:=0;
_y:=0;
radius:=2;
//quadrillage
lineStyle(2, $000000);
for i := -12 to 12 do Rline(i,ymin,i,ymax);
for i := -1 to 5 do Rline(xmin,i,xmax,i);
lineStyle(1,$1BD2FF);
for i := -10 to 50 do Rline(xmin,i/10,xmax,i/10);
for i := -120 to 120 do Rline(i/10,ymin,i/10,ymax);
//repère
lineStyle(2, $000000);
Rline(xmin,0,xmax,0); //abscisse uniquement
//*********
Roue:=RealMovie.Create(nil, 'roue', 1);
xR:=xmin+radius;
yR:=radius;
xcy:=xmin;
ycy:=radius;
theta:=0;
permute:=false;
tabmax:=1;
dtheta:=angle;
courbe[0]:=TRPoint.Create(xcy,ycy);
//bouton marche/arrêt
Button:=TButton.Create(self);
Button._x:=0;
Button._y:=254;
//le trackbar pour le rayon de la roue
trackbar:=TTrackbar.Create(self,2,1,5,20,20); //parent;depth;n°de trackbar;min;max;position
trackbar._x:=115;
trackbar._y:=265;
trackbar2:=TTrackbar.Create(self,4,2,1,4,1);
trackbar2._x:=445;
trackbar2._y:=265;
//affichage de l'évolution des trackbars
ToolRayon:= TLabel.create(self,3,320,255,115,30);
ToolRayon.text:='Rayon :'+ToolRayon.floattostrF(radius,1);
ToolRayon.SetTextFormat(ToolRayon.lbFont);
ToolSpeed:=TLabel.Create(self,5,642,255,355,30);
ToolSpeed.text:=' vitesse angulaire (°/image) : '+ToolSpeed.floattostrF(dtheta*180/pi,2);
ToolSpeed.SetTextFormat(ToolSpeed.lbFont);
//trait pour simuler une toolbar
lineStyle(1,$000000);
moveto(0,290);
lineto(1000,290);
end;
procedure TGraphe.GetPoint;
begin
if bascule then //condition marche arrêt bouton
begin
inc(tabmax);
if not permute then theta:=theta+dtheta else theta:=theta - dtheta;//on tourne d'un degré à chaque frame
end;
//coords centre roue
xR:=xmin+radius+radius*theta;
yR:=radius;
//coords point cyclo
xcy:=xR+radius*cos(pi-theta);
ycy:=yR+radius*sin(pi-theta);
courbe[tabmax-1]:=TRPoint.Create(xcy,ycy);
end;
procedure TGraphe.onEnterFrame;
begin
Roue.clear; //On efface
//roue -cercle
Roue.linestyle(3,$000000);
Roue.RCircle(xR,yR,radius);
//rayons
Roue.linestyle(3,$ff0000);
Roue.Rline(xR,yR,xR+radius*cos(pi-theta),yR+radius*sin(pi-theta));
Roue.linestyle(3,$000000);
Roue.Rline(xR,yR,xR+radius*cos(pi-theta+phi),yR+radius*sin(pi-theta+phi));
Roue.Rline(xR,yR,xR+radius*cos(pi-theta+2*phi),yR+radius*sin(pi-theta+2*phi));
Roue.Rline(xR,yR,xR+radius*cos(pi-theta+3*phi),yR+radius*sin(pi-theta+3*phi));
Roue.linestyle(3,$000000);
Roue.Rline(xR,yR-0.35,xR,yR+0.35);
Roue.Rline(xR-0.35,yR,xR+0.35,yR); //manque with do begin end;...
//fin rayons+roue
if (xR<xmin+radius) or (xR>xmax-radius) then //condition aller et retour
Begin
permute:= not permute;
tabmax:=1;
if xR<xmin+radius then courbe[0]:=TRPoint.Create(xmin,ycy) else courbe[0]:=TRPoint.Create(xcy,ycy );
End;
GetPoint;
roue.lineStyle(2,$0000ff); //cycloïde
roue.Rpolyline;
end;
Constructor TButton.Create(AOWNER:Movieclip);
begin
inherited Create(AOWNER,'button',1);
GetFont;
Caption := TextField.Create(Self, '', 0, 0,8,100,35);
Caption.text:='Stop';
Caption.SetTextFormat(Font);
DrawButton($F0F0F0,$808080,008080,100, 35);
Bascule:=true;
onpress:=DoClick;
end;
Procedure TButton.DrawButton(BackColor, TopColor, BottomColor, Width, Height: Integer);
begin
beginFill(BackColor);
lineStyle(5, TopColor);
moveTo(0, Height);
lineTo(0, 0);
lineTo(Width, 0);
lineStyle(5, BottomColor);
lineTo(Width, Height);
lineTo(0, Height);
endFill;
end;
Procedure TButton.doClick;
begin
Bascule:=not Bascule;
if Bascule then Caption.text:='Stop' else Caption.text:='Anime';
Caption.SetTextFormat(Font);
end;
Procedure TButton.GetFont;
begin
Font := TextFormat.Create('Tahoma', 12);
Font.Align := 'center';
Font.Bold := True;
Font.Color := $000000;
end;
constructor TTrackbar.Create(AOWNER:Movieclip;Depth,number,trmin,trmax:integer;posi:Double);
begin
inherited Create(AOWNER,'trackbar',Depth);
DrawTrackBar($CCCBB4,$CCCBB4,175,12);
cur[number]:=TTrackcur.Create(self,number,number,trmin,trmax,posi);
end;
constructor TTrackcur.create(AOWNER:Movieclip;Depth,number:integer;trmin,trmax: integer;posi:Double);
var r:integer;
a,b:Double;
begin
inherited Create(AOWNER,'cur',Depth);
_x:=floor((posi-trmin)*w/(trmax-trmin));//position initiale du curseur
_y:=0;
indice:=number;
xcur[number]:=6;
ycur[number]:=6;
r:=floor(1.35*12);
a:= r * 0.414213562;
b:= r * 0.707106781;
linestyle(1,$5F9EA0);
beginFill($5F9EA0);
moveTo(r+xcur[number], ycur[number]);
curveTo( r+xcur[number],-a+ycur[number],+b+xcur[number], -b+ ycur[number]);
curveTo( a+xcur[number],-r+ycur[number],xcur[number], -r+ ycur[number]);
curveTo(-a+xcur[number],-r+ycur[number],-b+xcur[number], -b+ ycur[number]);
curveTo(-r+xcur[number],-a+ycur[number],-r+xcur[number], ycur[number]);
curveTo(-r+xcur[number],a+ycur[number],-b+xcur[number], b+ ycur[number]);
curveTo(-a+xcur[number],r+ycur[number],xcur[number], r+ ycur[number]);
curveTo( a+xcur[number],r+ycur[number],b+xcur[number],b+ ycur[number]);
curveTo( r+xcur[number],a+ycur[number],r+xcur[number],ycur[number]);
endfill();
downcur[number]:=false;
trackmin[number]:=trmin;
trackmax[number]:=trmax;
position[number]:=posi;
onPress:=doclick;
onEnterFrame:=doEnterFrame;
onmouseup:=domouseup;
end;
procedure TTrackbar.DrawTrackbar(BackColor,penColor,Width, Height: Integer);
var r: integer;//rayon des arrondis
a,b:Double;
i:integer;
begin
h:=height;
w:=width;
r:=h div 2;
c[1,1]:=r; //coords des deux arrondis
c[2,1]:=r;
c[1,2]:=w-r;
c[2,2]:=r;
//j'ai dessiné un rectangle plein+deux disques aux extrémités. il y a plus simple avec 2 curveto aux deux extrémités et remplir...
//je n'avais pas envie de me compliquer la vie...
beginFill(Backcolor);
linestyle(2,pencolor);
moveto(r,0);
lineto(w-r,0);
lineto(w-r,height);
lineto(r,height);
endFill(); //pour la superposition
a:= r * 0.414213562;
b:= r * 0.707106781;
beginFill(Backcolor);
for i:=1 to 2 do
begin
moveTo(r+c[1,i], c[2,i]);
curveTo( r+c[1,i], -a+ c[2,i], +b+c[1,i], -b+ c[2,i]);
curveTo( a+c[1,i], -r+ c[2,i], c[1,i], -r+ c[2,i]);
curveTo(-a+c[1,i], -r+ c[2,i], -b+c[1,i], -b+ c[2,i]);
curveTo(-r+c[1,i], -a+ c[2,i], -r+c[1,i], c[2,i]);
curveTo(-r+c[1,i], +a+ c[2,i], -b+c[1,i], +b+ c[2,i]);
curveTo(-a+c[1,i], r+ c[2,i], c[1,i], +r+ c[2,i]);
curveTo( a+c[1,i], +r+ c[2,i], b+c[1,i], +b+ c[2,i]);
curveTo( r+c[1,i], +a+ c[2,i], r+c[1,i], c[2,i]);
end;
endfill();
end;
procedure TTrackcur.doClick;
begin
downcur[indice]:=true;
xmouse[indice]:=_xmouse;
end;
procedure TTrackcur.doEnterframe;
begin
case indice of
1:begin
if (_x + _xmouse -xmouse[1]>w) or (_x + _xmouse -xmouse[1]<0) then exit; //pas génial pour gérer les extrémités...
if downcur[1] then
begin
_x:= _x + _xmouse -xmouse[1];
position[1]:=_x*(trackmax[1]-trackmin[1])/w+trackmin[1];//en double
radius:=position[1]/10; //rayon de le roue de 0.5 à 5 (min:5-max:20)
graphe.ToolRayon.text:='Rayon :'+graphe.ToolRayon.floattostrF(radius,1);
graphe.ToolRayon.SetTextFormat(graphe.ToolRayon.lbFont);
//retour au point de départ
tabmax:=0;
graphe.xR:=xmin+Radius;
graphe.theta:=0;
end;
end;
2: begin
if (_x + _xmouse -xmouse[2]>w) or (_x + _xmouse -xmouse[2]<0) then exit;
if downcur[2] then
begin
_x:= _x + _xmouse -xmouse[2];
position[2]:=_x*(trackmax[2]-trackmin[2])/w+trackmin[2] ;
graphe.dtheta:=position[2]*angle;
graphe.ToolSpeed.text:=' vitesse angulaire (°/image) : '+graphe.ToolSpeed.floattostrF(graphe.dtheta*180/pi,2);
graphe.ToolSpeed.SetTextFormat(graphe.ToolSpeed.lbFont);
end;
end;
// ....
// n: begin
// end;
end;//du case
end;
procedure TTrackcur.doMouseUp;
begin
downcur[indice]:=false;
end;
constructor TLabel.Create(Parent:MovieClip; depth,left,top,width,height:integer);
begin
inherited Create(parent,'label',depth,left,top,width,height);
LbFont := TextFormat.Create('Tahoma', 20);
LbFont.Align := 'left';
LbFont.Bold := True;
LbFont.Color := $000000;
end;
function TLabel.FloattostrF(number:Double;digit:integer):String;//digit:nb de chiffre après la virgule
var int:integer;
frac,frac1,frac2,newnumber:Double;
begin
int:=trunc(number);
frac:=number-int;
frac1:=trunc(pow(10,digit)*frac)/pow(10,digit);
frac2:= trunc(pow(10,digit+1)*frac)/pow(10,digit+1);
//arrondi à la décimale supérieure si >=5
if (frac2-frac1)*pow(10,digit+1)>=5 then newnumber:=int+frac1+pow(10,-digit) else newnumber:=int+frac1;
result:=floattostr(newnumber);
end;
begin
graphe:=TGraphe.Create;
end. |
Partager