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
|
program Horloge;
{$FRAME_WIDTH 500}
{$FRAME_HEIGHT 500}
{$BACKGROUND $A6CAF0}
{$FRAME_RATE 32}
uses Flash8,math,date;
const
Pi = 3.14159265359; //inutile math.pi...
type
TArrayofPoint = array of Point;
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 RLineTo(x,y:number);
Procedure RLine(x1,y1,x2,y2:number);
procedure RLine2(pt1,pt2:point);
//Procedure RLineDashto(x1,y1,x2,y2:number);
Procedure RPolyline(courbe:array of Point);
Procedure Rrectangle(x1,y1,x2,y2:number);
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);
//procedure Rrotationarraypoint(xc,yc,theta:number;figure,result:array of point);
function Rrotationarraypoint(xc,yc,theta:number;figure:array of point):TarrayofPoint;
procedure RTextout(x,y,width,height,Depth:number;font:TextFormat;text:String);
procedure Rdisquegradtextout(xc,yc,R:number;n:integer;text:array of String);
procedure setSize(w, h: Integer; x1, y1, x2, y2: Number);
end;
TGraphe=class(RealMovie)
d: TDate;
Gaiguille,Paiguille:array of point;
heure: TextField;
espace:Realmovie; //pour faire des clear en cas d'animation
constructor Create;
procedure onEnterFrame;
end;
var MyFont,MyFont2:TextFormat;
mesheures:array of String;
Function sqr(n:Double):Double;
begin
result:=n*n;
end;
function IntToStr2(i: Integer): string;
begin
Result := IntToStr(i);
if i < 10 then
Result := '0' + Result;
end;
Function FloattostrF(num:Double;digit:integer):String;
var int:integer;
frac,frac1,frac2,newnum:Double;
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;
// Méthodes de dessin de Realmovie
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.RLineTo(x,y:number);
begin
Lineto(xo+x*Gx,yo-y*Gy);
end;
Procedure RealMovie.RLine(x1,y1,x2,y2:number);
begin
RMoveto(x1,y1);
RLineto(x2,y2);
end;
procedure RealMovie.RLine2(pt1,pt2:point);
begin
RLine(pt1.x,pt1.y,pt2.x,pt2.y);
end;
Procedure RealMovie.RPolyline(courbe:array of Point);
var i:integer;
begin
RMoveto(courbe[0].x,courbe[0].y);
// for i:=1 to high(courbe) do Rlineto(courbe[i].x,courbe[i].y); le high ne marche pas
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.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 Point;
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]:=Point.create(x2,y2);
Arrow[1]:=Point.create(x2-cX*ALength+cY*AWidth,y2-cY*ALength-cX*AWidth);
Arrow[2]:=Point.create(x2-cX*ALength-cY*AWidth,y2-cY*ALength+cX*AWidth);
Arrow[3]:=Point.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: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:point;
begin
phi:=2*pi/n;
for i:=0 to n do
begin
pt1:=point.create(xc+(R-L)*cos(i*phi),yc+(R-L)*sin(i*phi));
pt2:=point.create(xc+R*cos(i*phi),yc+R*sin(i*phi));
RLine2(pt1,pt2);
end;
end;
//Procedure RealMovie.Rrotationarraypoint(xc,yc,theta:number;figure,result:array of point);//obligé de faire une procedure et pas une function car le résultat doit être un array of point
//et ce n'est pas possible. j'ai tenté un type TArraypoint=array of point, ça passe mais j'avais besoin de high et low après et ça ne marche pas
function RealMovie.Rrotationarraypoint(xc,yc,theta:number;figure:array of point):TarrayofPoint;//obligé de faire une procedure et pas une function car le résultat doit être un array of point
//et ce n'est pas possible. j'ai tenté un type TArraypoint=array of point, ça passe mais j'avais besoin de high et low après et ça ne marche pas
var i:integer;
Rayon,phi:array of number;
O:point;
ptarray:array of point;
begin
O:=point.create(xo+Gx*xc,yo-Gy*yc);
i := 4;
for i:=low(figure) to high(figure) do
begin
ptarray[i]:=point.create(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]:=point.create(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;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,myfont,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
constructor TGraphe.Create;
var i:integer;
m:Matrix;
begin
inherited Create(nil,'horloge',1);
// inutile de faire cette partie à chaque fois
// on la place directement dans CE movieClip pour échaper au Clear de onEnterFrame
setSize(500,500,-50,-50,50,50); // nouvelle fonction pour éviter la redondance de code pour "espace" un peu plus bas
linestyle(5,$0000ff);
m:=matrix.create();
m.createbox(1,1,0,250,250);
RCircle(0,0,48.5);
begingradientfill('radial',[$0022FF,$0099ff],[100,100],[20,70],m);
RCircle(0,0,47);
endfill();
MyFont:=TextFormat.Create( 'Arial',16,$FFFBF0,True,False,False,'center');
MyFont2:=TextFormat.Create( 'Arial',22,$00FFFF,True,False,False,'center');
For i:=0 to 12 do mesheures[i]:=inttostr(i);
Rdisquegradtextout(0,0,35,12,mesheures);
RDisquegradue(0,0,45,5,12);
RDisquegradue(0,0,45,0.5,60);
// ---
// au lieu de calculer Depth, on récupère le prochain disponible
espace:=RealMovie.Create(SELF,'espace',getNextHighestDepth());
// espace._x:=0;
// espace._y:=0;
espace.setSize(500,500,-50,-50,50,50);
Gaiguille[0]:=point.create(0,0);
Gaiguille[1]:=point.create(-2,17.5);
Gaiguille[2]:=point.create(0,40);
Gaiguille[3]:=point.create(2,17.5);
Gaiguille[4]:=point.create(0,0);
Paiguille[0]:=point.create(0,0);
Paiguille[1]:=point.create(-2,10);
Paiguille[2]:=point.create(0,30);
Paiguille[3]:=point.create(2,10);
Paiguille[4]:=point.create(0,0);
end;
procedure TGraphe.onEnterFrame;
var i:integer;
fig:TArrayofPoint;
begin
d:=TDate.Create;
espace.clear;
// --> en plaçant chaque aiguille dans un MovieClip différent on pourrait les faire tourner avec "_rotation" sans les redessiner
//grande aiguille
fig := espace.Rrotationarraypoint(0,0,2*pi*(d.getMinutes+d.getSeconds/60)/60,Gaiguille);
espace.linestyle(1,$FFD700);
espace.beginfill($FFD700);
espace.moveto(Fig[0].x,Fig[0].y);
for i:=1 to 4 do espace.lineto(Fig[i].x,Fig[i].y);
endFill();
//petite aiguille
fig := espace.Rrotationarraypoint(0,0,2*pi*(d.getHours+d.getMinutes/60)/12,Paiguille);
beginFill($FFD700);
espace.moveto(Fig[0].x,Fig[0].y);
for i:=1 to 4 do espace.lineto(Fig[i].x,Fig[i].y);
espace.endfill();
//trotteuse
espace.linestyle(4,$FF4500);
espace.beginfill($FF4500);
espace.Rcircle(0,0,2);
espace.RLine(0,0,42*cos(-2*pi*d.getSeconds/60+pi/2),42*sin(-2*pi*d.getSeconds/60+pi/2));
espace.RLine(0,0,-7*cos(-2*pi*d.getSeconds/60+pi/2),-7*sin(-2*pi*d.getSeconds/60+pi/2));
endFill();
{
La fonction RTextOut() crée un TextField à la profondeur indiquée.
En appelant à nouveau RTextOut() on remplace le précédent TextField car il est à la même profondeur.
Il serait plus pertinant de simplement mettre à jour un TextField créé une fois pour toute.
En plaçant se texte sur Graphe et non sur espace, on peut le placer sous les aiguilles
les profondeurs de 1 à 12 sont occupées par les heures, 13 par espace, je prend 0 pour mettre en dessous des aiguilles
}
RTextout(-10.75,-28,250,30,0,myfont2,IntToStr2(d.getHours)+#32#58#32+IntToStr2(d.getMinutes)+#32#58#32+IntToStr2(d.getSeconds));
end;
begin
TGraphe.create;
stage.scaleMode :='noScale'; // pourquoi ?
end. |