PDA

View Full Version : fabText(); Never use boring monochrome text again!



Citrus
04-07-2015, 03:16 PM
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:
http://i.imgur.com/K7loQFU.png

It's a modified version of drawText() with a few additional parameters to input.

Here is what you need to give it:
(txt: string; pnt: TPoint; font: string; color: TColor; shiftPerc: extended; leftToRight, shadow, random: boolean);

where txt, pnt, font, color, and shadow are the same as in drawText(), and leftToRight and random are new.
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:
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):
http://i.imgur.com/ikQZjrb.png

with random set to false:
http://i.imgur.com/h4Pixji.png

To get started, head on over here (http://www.colorhexa.com/web-safe-colors) 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:
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.

Citrus
04-07-2015, 03:32 PM
KeepBotting
bonsai
and maybe Taric?

Ian
04-07-2015, 03:40 PM
Looks nice :)

KeepBotting
04-07-2015, 03:52 PM
Awesome, rep+

Turpinator
04-07-2015, 04:01 PM
function hueHueHUE()
sat sat sat.
got me. nice.

Renzanity
04-07-2015, 04:05 PM
Def a rep+

Citrus
04-07-2015, 04:08 PM
function hueHueHUE() got me. nice.

http://i3.kym-cdn.com/photos/images/original/000/490/470/5b8.gif
http://i.imgur.com/DZMYgNA.jpg

Citrus
04-07-2015, 04:34 PM
just updated code and attachment

Flight
04-07-2015, 05:11 PM
Haha that's a unique idea and you put it together nicely. Good job pal.

Citrus
04-07-2015, 07:21 PM
So, uhh, quick question. I'm calling fabText() 5 times in succession to display my progress report, but if randomCol then h := random(100); is giving me the same "random" number all 5 times. Why? I'm guessing it's too fast or something? If I add a small wait it fixes it but I feel like I shouldn't have to do that.

Taric
04-07-2015, 07:47 PM
So, uhh, quick question. I'm calling fabText() 5 times in succession to display my progress report, but if randomCol then h := random(100); is giving me the same "random" number all 5 times. Why? I'm guessing it's too fast or something? If I add a small wait it fixes it but I feel like I shouldn't have to do that.

randomRange(0,100);
Should give you a random number each time...

Totally putting this in my smelting script when I get back from the Recruiters Office today. #Sexy (https://villavu.com/forum/usertag.php?do=list&action=hash&hash=Sexy) #Iwantyourbabiesinsideofme (https://villavu.com/forum/usertag.php?do=list&action=hash&hash=Iwantyourbabiesinsideofme)

Citrus
04-07-2015, 07:58 PM
Totally putting this in my smelting script when I get back from the Recruiters Office today.

I had a feeling you would like it.


randomRange(0,100);
Should give you a random number each time...

It's pretty inconsistent. Sometimes all 5 numbers are different, sometimes they're all the same, sometimes they're doubled up. I added a 10-15 ms wait to the procedure and it seems to be fixed.

KeepBotting
04-07-2015, 08:17 PM
I had a feeling you would like it.



It's pretty inconsistent. Sometimes all 5 numbers are different, sometimes they're all the same, sometimes they're doubled up. I added a 10-15 ms wait to the procedure and it seems to be fixed.

Shot in the dark here but you could try calling randomize(); before you generate your random number

Citrus
04-07-2015, 08:21 PM
Shot in the dark here but you could try calling randomize(); before you generate your random number

Yeah I tried that but it didn't seem to help.

KeepBotting
04-07-2015, 08:34 PM
Yeah I tried that but it didn't seem to help.

*shrug*

program new;
var
i, j:integer;

begin
for i := 0 to 49 do
begin
num := random(10);
writeLn(j);
end;
end.

That generates 50 numbers, different one each time & no wait in between, try using it like that

bonsai
04-07-2015, 09:09 PM
Awesome release! I have a soft spot for silly code that does entertaining things.

I almost feel like Taric is the only one who should be able to use something this fabulous.

Can you explain stupidsort? Seems like you're sorting the X value after sorting the X value?


... giving me the same "random" number all 5 times. Why? I'm guessing it's too fast or something? If I add a small wait it fixes it but I feel like I shouldn't have to do that.


*shrug*
program broken;

That generates 50 numbers, different one each time & no wait in between, try using it like that

I suspect that was a phone post. The writeln would cause a delay too.

This one runs fine, though. evilcitrus: if you writeln your 'h' value you will see it changing.

What is probably happening is you are painting all 5 of them so fast to smartimage that it doesn't even update any of them except the last one. The delay you're needing is the time in between smartimage paints.

program new;
var
i :integer;
tia: TIntegerArray;

begin
setLength(tia, 50);
for i := 0 to 49 do
begin
tia[i] := random(10);
end;
writeln(tia);
end.


Compiled successfully in 562 ms.
[4, 7, 6, 1, 8, 9, 9, 0, 0, 9, 4, 5, 8, 7, 3, 3, 8, 2, 2, 1, 3, 7, 0, 7, 5, 8, 0, 0, 6, 4, 6, 9, 2, 3, 3, 7, 4, 1, 7, 0, 4, 1, 7, 4, 5, 8, 3, 2, 6, 0]

Citrus
04-07-2015, 09:26 PM
Can you explain stupidsort? Seems like you're sorting the X value after sorting the X value?

It groups the TPoints from the tpa into columns (same X value) and makes each column a separate tpa in an atpa. Maybe there's a better way to do that, but I was just making it up as I went along.


if you writeln your 'h' value you will see it changing

I did that and was getting things like
37
37
61
61
5

Taric
04-08-2015, 01:54 AM
10/10 Would take to my mothers wedding.

http://i.imgur.com/smCD4sv.png?1

Threshold
04-10-2015, 03:42 PM
Definitely going to try and use this next month when I work on scripting lol. Probably makes it 3x more fun.

Citrus
05-09-2015, 08:49 PM
Slight update for anyone who cares.