EDIT(5/9/2015): condensed everything into a single procedure. added shiftPerc variable.
I was bored yesterday so I started messing around the the colors on my progress reports. This is the result...
fabText
What does it do? It makes your text fabulous of course!
like this:
It's a modified version of drawText() with a few additional parameters to input.
Here is what you need to give it:
where txt, pnt, font, color, and shadow are the same as in drawText(), and leftToRight and random are new.Simba Code:(txt: string; pnt: TPoint; font: string; color: TColor; shiftPerc: extended; leftToRight, shadow, random: boolean);
leftToRight just determines the direction of the hue shift (true=ROYGBIV, false=VIBGYOR).
shiftPerc determines how much the hue is shifted. 50 --> full rainbow. I almost always use 5.
random sets the starting hue to a random value.
The picture above has all 3 booleans set to true:
Simba Code:smartImage.fabText('bars: ' + intToStr(loadCount*28), point(mainscreen.x1+1, mainscreen.y1+15), loginchars, col, true, true, true);
If you can't handle the full rainbow, don't worry! The hue can be shifted by any amount with shiftPerc
Here is an example that shifts random colors between their corresponding analogous colors (30 deg hue shift):
with random set to false:
To get started, head on over here and pick a starting color.
Note: the hex values need to be reversed for some reason. I wanted to use 99ffff, but to get that color I had to use TColor($ffff99). Maybe someone else can explain this.
I recommend picking something with high saturation and lightness. All of the pictures above are at 100% saturation and 80% lightness.
Here is the code:
Simba Code:procedure TMufasaBitmap.fabText(txt: string; pnt: TPoint; font: string; color: TColor; shiftPerc: extended; leftToRight, shadow, random: boolean);
var
i, j, a, b, len: integer;
step, deg, h, s, l: extended;
aH: TExtendedArray;
tpa, tpaShadow, temp: TPointArray;
atpa: T2DPointArray;
rainbow: TColorArray;
hit: boolean;
begin
tpa := tpaFromText(txt, font);
offsetTPA(tpa, pnt);
tpaShadow := copyTPA(tpa);
offsetTPA(tpaShadow, point(1, 1));
self.drawTPA(tpaShadow, __SHADOW_COLOR);
a := tpa.getBounds.x1;
b := tpa.getBounds.x2+1;
tpa.sortByXValue(true);
setLength(atpa, (b-a));
for j := a to b do
begin
hit := false;
for i := 0 to high(tpa) do
begin
if j = tpa[i].x then
begin
atpa[j-a].append(tpa[i]);
hit := true;
end
else if hit then break;
end;
end;
colorToHSL(color, h, s, l);
if random then h := random(100);
len := length(atpa);
if len < 1 then exit();
deg := shiftPerc;
if len = 2 then aH := [h-deg, h+deg];
if len = 3 then aH := [h-deg, h, h+deg];
if len < 4 then exit();
step := (deg/((len-((len mod 2)+2))/2));
for i := 0 to (len-1) do
begin
if leftToRight then
aH.append((h-deg)+(i*step))
else
aH.append((h+deg)-(i*step));
end;
setLength(rainbow, (high(aH)+1));
for i := 0 to high(aH) do
rainbow[i] := hslToColor(aH[i], s, l);
for i := 0 to high(atpa) do
self.drawTPA(atpa[i], rainbow[i]);
end;
Feel free to use and modify this as you wish.