SRL Archive - SRL Archives

ColorToRGB(color : integer);


pwnaz0r

2007-04-03 00:20:41

Well we dont have one of these and i thought it would be helpful to have for autocoloring.


function ColorToRGB(color : integer) : string;
var
red, blue, green : integer;
begin
red := (Color mod 256);
green := ((Color / 256) mod 256);
blue := ((Color / 256) / 256);
result := ('Red : '+ IntToStr(Red) +', Green : '+ IntToStr(Green)+', Blue : '+ IntToStr(Blue));
Writeln(result);
end;

 
function GetRanges(colorarray : array of integer) : string;
var
qwerty12, ffgf, hhhh, hhhhh : integer;
iColor1, iColor2, maxdiff1, maxdiff2 : extended;
begin
qwerty12 := (GetArrayLength(colorarray) - 1);
for ffgf := 0 to qwerty12 do
begin
hhhh := hhhh + 1;
hhhhh := hhhh + 1;
If(ffgf = (qwerty12 - 1)) then break;
iColor1 := abs(colorarray[hhhh]);
iColor2 := abs(colorarray[hhhhh]);

If(iColor1 = iColor2)then maxdiff1 := 0;
If(iColor1 > iColor2)then maxdiff1 := iColor1 - iColor2;
If(iColor2 > iColor1)then maxdiff1 := iColor2 - iColor1;

If(maxdiff1 < maxdiff2)then maxdiff1 := maxdiff2;
end;
result := 'Max Difference is '+ IntToStr(ExtToInt(maxdiff1));
writeln(result);
end;

Boreas

2007-04-03 06:58:56

I posted one of these months ago, and it's going to be in Divi. Also, you need to make it return the answer for it to be useful, not just write it. Good effort though.

pwnaz0r

2007-04-03 14:59:08

I do. Red := bla. Blue := bla. Green := bla. It stores to those variables…

Dark_Sniper

2007-04-03 15:48:41

yes but those vars are not global…

more like this :p
(didn't have the best idea on returning the values though…)

Function ColorToRGB(color : integer): String;
var
red, blue, green : integer;
begin
red := (Color mod 256);
green := ((Color / 256) mod 256);
blue := ((Color / 256) / 256);
Result:=''+ IntToStr(Red) +', '+ IntToStr(Green)+', '+ IntToStr(Blue);
end;

Secet

2007-04-03 15:57:27

Could someone explain what do we do with RGB value?

Pentti

2007-04-03 16:01:12

or:
Function ColorToR(Color:integer):Integer;
begin
Result:=Color mod 256;
end;

Function ColorToG(Color:integer):Integer;
begin
Result:=Color/256 mod 256;
end;

Function ColorToB(Color:integer):Integer;
begin
Result:=Color/256/256;
end;

var
Color:Integer;

begin
Color:=210139;
Writeln('R: '+inttostr(ColorToR(Color))+', G: '+inttostr(ColorToG(Color))+', B: '+inttostr(ColorToB(Color)))
end.
:D

Boreas

2007-04-03 17:07:15

From: Secet
Could someone explain what do we do with RGB value?


program ladder;

const
floorcolor=6776943;


function HowManyAround(HalfWidth,ParX,ParY,TheColor:integer;WhichCanvas:tcanvas):integer;
var MyX,MyY,MyColor,TmpResult:integer;
begin
for MyY:=ParY-(HalfWidth) to ParY+(HalfWidth) do
begin
for MyX:=ParX-(HalfWidth) to ParX+(HalfWidth) do
begin
MyColor:=WhichCanvas.pixels[MyX,MyY];
if MyColor=TheColor then
TmpResult:=TmpResult+1;
end;
end;
result:=TmpResult;
end;



function GetLadderColor(TheFloorColor:integer):integer;
var
TmpBmp,MyX,MyY:integer;
MyColor,TmpInt: integer;
MyCanvas:tcanvas;
TmpBool:boolean;

begin
TmpBmp:= BitmapFromString(100,90,'');
MyCanvas:=GetBitmapCanvas(TmpBmp)

CopyCanvas(GetClientCanvas,MyCanvas,598,39,698,129,0,0,100,90)
for MyY:=0 to 99 do
begin
for MyX:=0 to 89 do
begin
MyColor:= MyCanvas.pixels[MyX,MyY];
if not(MyColor=78673)then
if ((MyColor/256) / 256) <20 then
begin
if ((MyColor/256) mod 256) <65 then
begin
if ((MyColor/256) mod 256) >15 then
begin
if (MyColor mod 256) < 105 then
begin
if (MyColor mod 256) > 60 then
begin
TmpInt:=HowManyAround(4,MyX,MyY,TheFloorColor,MyCanvas);
if TmpInt>30 then
begin
if TmpInt<100 then
TmpBool:=true;
end;

end;
end;
end;
end;
end;
if TmpBool then break;
end;
if TmpBool then break;
end;
if TmpBool then result:=MyColor;
end;
var TheLadderColor,t:integer;
begin
t:=getsystemtime;
TheLadderColor:=GetLadderColor(FloorColor);
writeln(inttostr(TheLadderColor));
writeln(inttostr(getsystemtime-t)+'ms');
end.

I will explain more uses once Divi comes out.

pwnaz0r

2007-04-03 17:22:52

O ic make it return a result :D… as in a function :p

Boreas

2007-04-03 17:48:18

You can also use a type.

type rgbcolor= record
Red,Blue,Green:integer;
end;

function rgb2color(rgb:rgbcolor):integer;
begin
result:=(((rgb.blue*256)+rgb.green)*256)+rgb.red
end;


function color2rgb(color:integer):rgbcolor;
begin
result.red:=(Color mod 256);
result.green:= ((Color / 256) mod 256);
result.blue:=((Color / 256) / 256);
end;

var
MyRGBColor:rgbcolor;
MySCARColor:integer;

begin
MyRGBColor:=color2rgb(66536);
Writeln('R: '+inttostr(MyRGBColor.red)+', G: '+inttostr(MyRGBColor.green)+', B: '+inttostr(MyRGBColor.blue))


MySCARColor:=rgb2color(MyRGBColor);
writeln(inttostr(MySCARColor));
end.

Dark_Sniper

2007-04-03 19:07:19

ya.. im not big with type….

danrox2004

2007-04-03 19:42:09

Or return the values in variables they specify:

function ColorToRGB(color: integer; var red, green, blue: integer) : string;
begin
red := (Color mod 256);
green := ((Color / 256) mod 256);
blue := ((Color / 256) / 256);
result := ('Red : '+ IntToStr(Red) +', Green : '+ IntToStr(Green)+', Blue : '+ IntToStr(Blue));
Writeln(result);
end;