PDA

View Full Version : Colors Writeln'er.



mastaraymond
10-19-2007, 05:16 PM
Really easy, but when you need to debug colors its always annoying to make a simple writeln'er. Thats why i made this very simple "script", but handy..
Change the colors in Init to whatever you want to debug..:

program New;
//By Mastaraymond
//0 = Min
//1 = Max
var
I,II : integer;
RGBColor : Array[1..3] of Integer;
RGB : Array[0..1] of Array[1..3] of Integer;
XYZColor, HSLColor : Array[1..3] of Extended;
HSL,XYZ : Array[0..1] of Array[1..3] of Extended;
Colors : TIntegerArray;
Strings : Array[0..9] of String;
Procedure Init;
begin;
Colors := [6396770,5749833,7122792,10408078,5681475,5674327];
end;
begin
Init;
For I:= 1 to 3 do
begin;
Writeln('');
RGB[0][I] := 255;
HSL[0][I] := 255; //Max is 240?
XYZ[0][I] := 255; //Max is ...?
end;
Strings[1] := 'R: ';
Strings[0] := ' ';
Strings[2] := 'G: ';
Strings[3] := 'B: ';
Strings[4] := 'H: ';
Strings[5] := 'S: ';
Strings[6] := 'L: ';
Strings[7] := 'X: ';
Strings[8] := 'Y: ';
Strings[9] := 'Z: ';
For I:= 0 to High(Colors) do
begin;
Strings[0] := Strings[0] + Padr('Color: '+inttostr(Colors[I]),16) +' | ';
ColortoRGB(Colors[I],RGBColor[1],RGBColor[2],RGBColor[3]);
ColortoHSL(Colors[I],HSLColor[1],HSLColor[2],HSLColor[3]);
ColortoXYZ(Colors[I],XYZColor[1],XYZColor[2],XYZColor[3]);
For II:= 1 to 3 do
begin;
RGB[0][II] := Min(RGBColor[II],RGB[0][II]);
RGB[1][II] := Max(RGBColor[II],RGB[1][II]);
HSL[0][II] := MinE(HSLColor[II],HSL[0][II]);
HSL[1][II] := MaxE(HSLColor[II],HSL[1][II]);
XYZ[0][II] := MinE(XYZColor[II],XYZ[0][II]);
XYZ[1][II] := MaxE(XYZColor[II],XYZ[1][II]);
end;
For II := 1 to 3 do
Strings[II] := Strings[II] +Padr(IntToStr (RGBColor[II]),16) +' | ';
For II := 4 to 6 do
Strings[II] := Strings[II] +Padr(FloatToStr(HSLColor[II-3]),16) +' | ';
For II := 7 to 9 do
Strings[II] := Strings[II] +Padr(FloatToStr(XYZColor[II-6]),16) +' | ';
end;
For I:= 0 to 9 do
Delete(Strings[I],Length(Strings[I])-2,3);
For I:= 0 to 9 do
begin;
if (I = 1) or (I = 4)or (I = 7) then Writeln('');
Writeln(Strings[I]);
end;
Writeln('');
Writeln('Highest RGB values = R: '+ Padr(FloatToStr(RGB[1][1]),3) + ' | ' +'G: '+ Padr(FloatToStr(RGB[1][2]),3) + ' | ' +'B: '+ Padr(FloatToStr(RGB[1][3]),3) );
Writeln('Lowest RGB values = R: '+ Padr(FloatToStr(RGB[0][1]),3) + ' | ' +'G: '+ Padr(FloatToStr(RGB[0][2]),3) + ' | ' +'B: '+ Padr(FloatToStr(RGB[0][3]),3) );
Writeln('Differ RGB values = R: '+ Padr(IntToStr(RGB[1][1] - RGB[0][1]),3) + ' | G: '+ Padr(inttostr(RGB[1][2] - RGB[0][2]) ,3) + ' | B: '+Padr(inttostr(RGB[1][3] - RGB[0][3]),3));
Writeln('Middle RGB values = R: '+ Padr(IntToStr((RGB[1][1] + RGB[0][1]) div 2),3) + ' | G: '+ Padr(inttostr((RGB[1][2] + RGB[0][2]) div 2),3) + ' | B: '+Padr(inttostr((RGB[1][3] + RGB[0][3]) div 2),3));
Writeln('Middle RGB color = ' + IntToStr(RGBToColor((RGB[1][1] + RGB[0][1]) div 2,(RGB[1][2] + RGB[0][2]) div 2,(RGB[1][3] + RGB[0][3]) div 2)));
Writeln('');
Writeln('Highest HSL values = H: '+ Padr(FloatToStr(HSL[1][1]),16) + ' | ' +'S: '+ Padr(FloatToStr(HSL[1][2]),16) + ' | ' +'L: '+ Padr(FloatToStr(HSL[1][3]),16) );
Writeln('Lowest HSL values = H: '+ Padr(FloatToStr(HSL[0][1]),16) + ' | ' +'S: '+ Padr(FloatToStr(HSL[0][2]),16) + ' | ' +'L: '+ Padr(FloatToStr(HSL[0][3]),16) );
Writeln('Differ HSL values = H: '+ Padr(FloatToStr(HSL[1][1] - HSL[0][1]),16) + ' | S: '+ Padr(FloatToStr(HSL[1][2] - HSL[0][2]) ,16) + ' | L: '+Padr(FloatToStr(HSL[1][3] - HSL[0][3]),16));
Writeln('Middle HSL values = H: '+ FloatToStr((HSL[1][1] + HSL[0][1]) div 2) + ' | S: '+ FloatToStr((HSL[1][2] + HSL[0][2]) div 2) + ' | L: '+FloatToStr((HSL[1][3] + HSL[0][3]) div 2));
Writeln('Middle HSL color = ' + IntToStr(HSLToColor((HSL[1][1] + HSL[0][1]) div 2,(HSL[1][2] + HSL[0][2]) div 2,(HSL[1][3] + HSL[0][3]) div 2)));
Writeln('');
Writeln('Highest XYZ values = X: '+ Padr(FloatToStr(XYZ[1][1]),16) + ' | ' +'Y: '+ Padr(FloatToStr(XYZ[1][2]),16) + ' | ' +'Z: '+ Padr(FloatToStr(XYZ[1][3]),16) );
Writeln('Lowest XYZ values = X: '+ Padr(FloatToStr(XYZ[0][1]),16) + ' | ' +'Y: '+ Padr(FloatToStr(XYZ[0][2]),16) + ' | ' +'Z: '+ Padr(FloatToStr(XYZ[0][3]),16) );
Writeln('Differ XYZ values = X: '+ Padr(FloatToStr(XYZ[1][1] - XYZ[0][1]),16) + ' | Y: '+ Padr(FloatToStr(XYZ[1][2] - XYZ[0][2]) ,16) + ' | Z: '+Padr(FloatToStr(XYZ[1][3] - XYZ[0][3]),16));
Writeln('Middle XYZ values = X: '+ FloatToStr((XYZ[1][1] + XYZ[0][1]) div 2) + ' | Y: '+ FloatToStr((XYZ[1][2] + XYZ[0][2]) div 2) + ' | Z: '+FloatToStr((XYZ[1][3] + XYZ[0][3]) div 2));
Writeln('Middle XYZ color = ' + IntToStr(XYZToColor((XYZ[1][1] + XYZ[0][1]) div 2,(XYZ[1][2] + XYZ[0][2]) div 2,(XYZ[1][3] + XYZ[0][3]) div 2)));
WritelN('');
end.

~Raymond

n3ss3s
10-19-2007, 05:21 PM
Hehe, gj, though writing one takes less time than surfing to srl and finding this topic =/


Public Test Corner Post your procedures and functions here
... I'd prefer the Ol' snippets section xD

mastaraymond
10-19-2007, 05:24 PM
Hehe, gj, though writing one takes less time than surfing to srl and finding this topic =/

... I'd prefer the Ol' snippets section xD
Yeah to bad they removed it.. Oh btw.. It doesn't take less time... I always hate to make a writelner... So this time I decided to make a good one :rolleyes:.

n3ss3s
10-19-2007, 05:26 PM
Oh, you are talking about "writelner" - I thought you ment open new tab, make h, s, l extendeds, and do ColorToHSL(Color, H, S, L); Writeln(FloatToStr(H) + ' ' etc.. :D

mastaraymond
10-19-2007, 06:08 PM
'Updated'.. It now calculates the highest value of each and the lowest value. Then it calculates the color that would be between those 2 values....

~Raymond

Sp0rky
10-19-2007, 06:10 PM
Haha, I thought this topic mean you'd created a function to Writeln in different colors! I was like :o

mastaraymond
10-19-2007, 06:15 PM
Haha, I thought this topic mean you'd created a function to Writeln in different colors! I was like :o
If you know a better title ^^.:rolleyes:

n3ss3s
10-19-2007, 06:37 PM
This is how I get the middle of some colors:


Function GetCC: Integer; // Very useful for getting middle of light and dark
Var
HSL: Array of Array of Extended;
Var
H, S, L: Extended;
Var
Colors: TIntegerArray;
Var
C: Integer;
Begin
Colors := [3032389, 2110002];
SetArrayLength(HSL, 2);
SetArrayLength(HSL[0], 3);
SetArrayLength(HSL[1], 3);
For C := 0 To 1 Do
Begin
ColorToHSL(Colors[c], HSL[c][0], HSL[c][1], HSL[c][2]);
End;
H := HSL[1][0] - ((HSL[1][0] - HSL[0][0])/4);
S := HSL[1][1] - ((HSL[1][1] - HSL[0][1])/4);
L := HSL[1][2] - ((HSL[1][2] - HSL[0][2])/2);
Result := HSLToColor(H, S, L);
End;


Current colors ther are light and dark colors of coal.

mastaraymond
10-19-2007, 06:56 PM
This is how I get the middle of some colors:


Function GetCC: Integer; // Very useful for getting middle of light and dark
Var
HSL: Array of Array of Extended;
Var
H, S, L: Extended;
Var
Colors: TIntegerArray;
Var
C: Integer;
Begin
Colors := [3032389, 2110002];
SetArrayLength(HSL, 2);
SetArrayLength(HSL[0], 3);
SetArrayLength(HSL[1], 3);
For C := 0 To 1 Do
Begin
ColorToHSL(Colors[c], HSL[c][0], HSL[c][1], HSL[c][2]);
End;
H := HSL[1][0] - ((HSL[1][0] - HSL[0][0])/4);
S := HSL[1][1] - ((HSL[1][1] - HSL[0][1])/4);
L := HSL[1][2] - ((HSL[1][2] - HSL[0][2])/2);
Result := HSLToColor(H, S, L);
End;


Current colors ther are light and dark colors of coal.
Its not the 'real' middle^^. So its adjusted to dark and light? Its really color depending if im right :rolleyes:.
Anyway 'updated'.

n3ss3s
10-20-2007, 01:27 PM
The snippet I posted gets the approximately "middle" looking color, I tried with lesser demon and compared with eye, same with coal, and with ~10 tol everything is fine ;)

Bobarkinator
10-20-2007, 03:45 PM
Nice little snippet

mastaraymond
10-20-2007, 07:46 PM
Nice little snippet

Thx :).:spot:

Hugolord
10-20-2007, 08:20 PM
Haha, I thought this topic mean you'd created a function to Writeln in different colors! I was like :o

lol sme here

Santa_Clause
10-20-2007, 11:45 PM
Good job Raymond...even though I have no idea what it does :p

mastaraymond
10-20-2007, 11:57 PM
Good job Raymond...even though I have no idea what it does :p It gives you some information about colors ^^.

Example:

Differ HSL values = H: 0,101011991500854 | S: 2,00589895248413 | L: 4,50980365276337

Middle HSL color = 1784651

The Differ is the value between the highest and the lowest.. So if i use the middle color, you must divide the differs. Max +Min div 2 = Middle.. ^^.
When we divided them we can use them as modifiers, in colortolerancespeed(2);
I would use : SetColorspeed2Modifiers(0.006,0.11); And as tol 3...
Because: 0.006 * 10 = 0.06, 0.06 * 2 = 0.12. (Higher then the differ).
0.11 * 10 = 1.1, 1.1 * 2 = 2.2. (Higher then the differ).
The tol because
3*2 = 6 (Higher then the differ).

Ok, this is a explanation of nothing.. Nobody would probably get it, but i tried ^^.

~Raymond