SRL Archive - Other Scripts

Gradients, Gradients, gr4d13nts!! pl0x!


shaunthasheep

2007-07-22 12:58:18

omfg g1v3 m3 s0m3 n00b po1nts plxxz!

Anyways, I had no internet and was bored, so I made a CreateGradient function, no internet = 100% my work pl0x. My head hurts after making it though. Anyways, here it is!


program Gradients;
var
testarray : TIntegerArray;
i, g, a : integer;
handle : TCanvas;

function CreateGradient(StartColor, EndColor, width : integer) : TIntegerArray;
var
r1, g1, b1 : integer;
r2, g2, b2 : integer;
r, g, b : extended;
rchange, gchange, bchange : extended;
ii : integer;
begin
ColorToRGB(StartColor, r1, g1, b1);
ColorToRGB(EndColor, r2, g2, b2);
r := round(r1);
g := round(g1);
b := round(b1);
rchange := (r2 - r1) / width;
gchange := (g2 - g1) / width;
bchange := (b2 - b1) / width;
SetArrayLength(result, width);
for ii := 1 to width do
begin
result[ii - 1] := RGBToColor(Round(r), Round(g), Round(b));
r := r + rchange;
g := g + gchange;
b := b + bchange;
end;
end;

function CreateMultipleColorGradient(colors : TIntegerArray; width : integer) : TIntegerArray;
var
ii, aa, gg, qq : integer;
bb : TIntegerArray;
begin
if GetArrayLength(colors) = 0 then Exit;
if GetArrayLength(colors) = 1 then
begin
SetArrayLength(result, 1);
result[0] := colors[0];
Exit;
end;
for ii := 0 to GetArrayLength(colors) - 2 do
begin
if ii >= 1 then
aa := 2
else
aa := 0;
//aa is so theres no double lines (of the same color)
//i don't think it really worked
gg := GetArrayLength(result);
bb := CreateGradient(colors[ii], colors[ii + 1], width / GetArrayLength(colors) + aa);
SetArrayLength(result, GetArrayLength(result) + GetArrayLength(bb) - aa)
for qq := aa to GetArrayLength(bb) - 1 do
result[qq + gg - aa] := bb[qq];
end;
end;

begin
//the function is not slow, it depends how you draw it onto your canvas.
testarray := CreateGradient(0, 16691276, 100);
//CreateGradient(color1, color2, width);
//testarray := CreateMultipleColorGradient([clblack,clred,clwhite], 30);

DisplayDebugImgWindow(GetArrayLength(testarray) - 1, GetArrayLength(testarray) - 1);
g := GetArrayLength(testarray) - 1;
handle := GetDebugCanvas;
for i := 0 to g do
begin
handle.Pen.Color := testarray[i];
handle.MoveTo(i, 1);
handle.LineTo(i, g);
end;
end.

GoF

2007-07-22 13:37:36

My head hurts after reading it… :(

mastaraymond

2007-07-22 14:24:18

COOOL! Lets hope i understand it :p. I was thinking of this, while i started making my movie, never got it real :p.
Huh?

r := round(r1);
g := round(g1);
b := round(b1);
That doesn't make sense :rolleyes:.

r1, g1, b1 : integer;
Huh, seems like CreateMultipleColorGradient isn't working properly, is it?
I still like it:p. Only, 1 thingy, why you call your canvas "handle" that doesn't make sens ^^.
 TheCanvas :TCanvas;
TheCanvas := TCanvas.Create;
TheCanvas.handle := GetDebugCanvas.handle
:p
Good job m8 :).