SRL Archive - SRL Snippets

percentBar()


Citrus

2015-06-17 16:45:59


Not sure how/if anyone will use this, but here it is.

p is the percent (0-100) and box is the area that the bar will fill. Keep box fairly small or it will slow your script down.

procedure TMufasaBitmap.percentBar(p: integer; box: TBox);
var
x2, i, j, a, b, len: integer;
h1, h2, step, deg: extended;
aH: TExtendedArray;
col: TColor;
box2: TBox;
m: TPoint;
tpa: TPointArray;
atpa: T2DPointArray;
hit: boolean;
begin
p := min(p, 100);
x2 := box.getWidth()*p div 100;
box2 := box;
box2.x2 := x2;
tpa := box2.createTPA();
if length(tpa) < 1 then exit();

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;

h1 := 0;
h2 := p/3;

len := length(atpa);
if len = 1 then exit();
deg := abs(h1-h2);
step := deg/(len-1);
for i := 0 to (len-1) do
aH.append(h1+(i*step));

for i := 0 to high(atpa) do
begin
col := hslToColor(aH[i], 100, 50);
self.drawTPA(atpa[i], col);
end;

m := box.getMiddle();
m.x := max(0, m.x-8);
m.y := max(0, m.y-5);
self.drawText(intToStr(p)+'%', m, upchars, true, TColor($ff6699));
end;
it isn't efficient at all but I'm too lazy to fix it

Clarity

2015-06-17 17:02:17

Pretty cool, particularly the changing colors! +Rep

srlMW

2015-06-17 21:26:38

Nice work man, I can see this being used a lot for visual display!

Lucidity

2015-06-20 08:46:15

This is neat, but I don't really see a use for it on RS, usually if there's a percentage involved on rs there's an interface displaying, but I like how the colours change, pretty neat!

Citrus

2015-06-20 14:17:21

From: Bly
This is neat, but I don't really see a use for it on RS, usually if there's a percentage involved on rs there's an interface displaying, but I like how the colours change, pretty neat!


I made it for the color picking phase of my combat script. But yeah, I agree that there aren't many places it would be used.