En regardant ton défi, j'ai découvert encore un bug sur le with...
Pour le défi, je ne suis pas sur la bonne piste, j'en suis conscient...
L'objet camera est à regarder de près !... ou bitmapdata avec FloodFill mais je ne pense pas, le remplissage serait plus complet...
ci-joint pour le bug : (désolé, j'utilise URealmovie et UColor, c'était pour regarder vite fait)
program PLight;
{$FRAME_WIDTH 1000}
{$FRAME_HEIGHT 520}
{$FRAME_RATE 12}
{$BACKGROUND $000000}
uses
Flash8,URealmovie,UColor;
Type
Light=class(movieclip)
x,y:number;
Procedure circle(Cx,Cy,Radius:number);
procedure draw;
constructor create(parent:movieclip;depth:number);
End;
espace=class(Realmovie)
projo:Light;
constructor Create;
procedure onMouseMove;
end;
Procedure Light.circle(Cx,Cy,Radius:number);
var a,b,R: number;
begin
R:=Radius;
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;
constructor Light.Create(parent:movieclip;depth:number);
begin
inherited Create(parent,'light',depth);
end;
procedure Light.Draw;
var m:Matrix;
begin
m:=matrix.create();
m.createbox(1,1,0,x,y);
begingradientfill('radial',[$FFFFFF,$000000],[100,100],[15,100],m);
circle(x,y,150);
endFill();
end;
Constructor espace.Create;
begin
inherited Create(_root,'espace',1);
setsize(1000,520,-10,-10,10,10);
linestyle(3,clred);
Rline(4,4,8,4);
projo:=Light.create(_root,0);
mouse.hide;
end;
//procedure espace.onMouseMove; ici, ça ne marche pas
//begin
// with projo do
// begin
// clear;
// x:=_xmouse;
// y:=_ymouse;
// draw;
// end;
//end;
procedure espace.onMouseMove;
begin
projo.clear;
projo.x:=_xmouse;
projo.y:=_ymouse;
projo.draw;
end;
begin
espace.create;
end.
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;
function RPoint(x,y:number):TPoint;
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 IntToStr3(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;
function IntToStr3(i: Integer): string;
begin
Result := IntToStr(i);
if (i<100) and (i<>0) and (i>=10) then Result:='0'+Result else if (i<10) and (i<>0) then Result:='00'+Result else if i =0 then Result :='000';
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);
for i:=1 to high(courbe) do Rlineto2(courbe);
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:=pt(x2,y2);
Arrow:=pt(x2-cX*ALength+cY*AWidth,y2-cY*ALength-cX*AWidth);
Arrow:=pt(x2-cX*ALength-cY*AWidth,y2-cY*ALength+cX*AWidth);
Arrow:=pt(x2,y2);
Linestyle(penw,col);
BeginFill(col);
Moveto(x1,y1);
Lineto(x2,y2);
Moveto(arrow.x,arrow.y);
for i:=1 to 3 do lineto(arrow.x,arrow.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:=pt(xo+Gx*figure.x,yo-Gy*figure.y);
if ptarray.x-O.x<>0 then phi:=atan2(ptarray.y-O.y,ptarray.x-O.x) else phi:=-pi/2;
Rayon:=round(sqrt(sqr(ptarray.x-O.x)+sqr(ptarray.y-O.y)));
ptarray.x:=O.x+Rayon*cos(theta+phi);
ptarray.y:=O.y+Rayon*sin(theta+phi);
result:=pt(ptarray.x,ptarray.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);
end;
end;
Function RealMovie.RPoint(x,y:number):TPoint;
begin
result.x:=xo+x*Gx;
result.y:=yo-y*Gy;
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.
unit UColor;
interface
uses Flash8;
const
clBlack=$000000;
clWhite=$ffffff;
clYellow=$ffff00;
clfuchsia=$FF00FF;
claqua=$00FFFF;
clorange=$FFA500;
clBlue=$0000ff;
clGreen=$008000;
clRed=$FF0000;
cllime=$00FF00;
clsilver=$C0C0C0;
clGray=$808080;
clGold=$FFD700;
cldarkturquoise=$00CED1;
claliceblue=$F0F8FF;
clazure=$F0FFFF;
clbrown=$A52A2A;
clcadetblue=$5F9EA0;
clcoral=$FF7F50;
cllightskyblue=$87CEFA;
clmediumspringgreen=$00FA9A;
clmediumturquoise=$48D1CC;
clmediumaquamarine=$66CDAA;
clmediumblue=$0000CD;
clmediumorchid=$BA55D3;
clmediumpurple=$9370DB;
clmediumseagreen=$3CB371;
clmediumslateblue=$7B68EE;
clnavajowhite=$FFDEAD;
clnavy=$000080;
clorchid=$DA70D6;
clpowderblue=$B0E0E6;
clpalegoldenrod=$EEE8AA;
clpalegreen=$98FB98;
clpaleturquoise=$AFEEEE;
clspringgreen=$00FF7F;
cltomato=$FF6347;
clyellowgreen=$9ACD32;
clwheat=$F5DEB3;
clslategray=$708090;
clturquoise=$40E0D0;
clsalmon=$FA8072;
clsandybrown=$F4A460;
clseagreen=$2E8B57;
Function GetRvalue(coul:integer):integer;
Function GetGvalue(coul:integer):integer;
Function GetBvalue(coul:integer):integer;
Function RGB(R,V,B:integer):number;
implementation
Function GetBvalue(coul:integer):integer;
begin
result :=coul mod 256;
end;
Function GetGvalue(coul:integer):integer;
begin
result :=floor((Coul mod 65536)/256);
end;
Function GetRvalue(coul:integer):integer;
begin
result :=Floor(Coul/65536);
end;
Function RGB(R,V,B:integer):number;
begin
result:=65536*R+256*V+B;
end;
end.
0 |
0 |