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
|
program niveau_de_gris;
{$FRAME_WIDTH 520}
{$FRAME_HEIGHT 366}
{$FRAME_RATE 32}
{$BACKGROUND $FFFFFF}
{$JPEG nom 'voeux2012.jpg'}
uses
Flash8,UCursor;
const
frame_width=520;
frame_height=366 ;
type
image = class(Movieclip)
mybmp : BitmapData;
Field:TextField;
Font:TextFormat;
constructor Create;
procedure onKeyDown;
Procedure onMouseMove;
end;
var cur:TCursor;
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):integer;
begin
result:=65536*R+256*V+B;
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;
constructor Image.Create;
begin
inherited Create(nil,'mymovieclip',1);
mybmp := loadBitmap('nom');
attachBitmap(mybmp,1,'',false);
Font:=TextFormat.Create( 'Arial',16,$000000,True,False,False,'center');
cur:=TCursor.create(self);
Key.Addlistener(self);
field:=TextField.Create(self,'codeRGB',getNextHighestDepth(),0,0,200,40);
field.selectable:=false;
field.setNewTextFormat(Font);
end;
Procedure Image.onMouseMove;
var R,V,B:integer;
rgb:number;
begin
rgb:=mybmp.GetPixel(_xmouse,_ymouse);
R:=GetRValue(floor(rgb));
V:=GetGValue(floor(rgb));
B:=GetBValue(floor(rgb));
Field.text:='( '+inttostr3(R)+' , '+inttostr3(V)+' , '+inttostr3(B)+' )';
Field._x:=_xmouse-60;
Field._y:=_ymouse-30;
end;
procedure Image.onKeyDown;
var i,j:integer;
col:number;
R,V,B,moy:integer;
begin
For i:=0 to 520 do for j:=0 to 366 do
begin
col:=mybmp.GetPixel(i,j);
R:=GetRValue(floor(col));
V:=GetGValue(floor(col));
B:=GetBValue(floor(col));
moy:=Floor((R+V+B)/3);
mybmp.SetPixel( i,j,RGB(moy,moy,moy) );
end;
mybmp.draw(mybmp);
end;
begin
Image.create;
stage.scaleMode :='noScale';
end. |
Partager