Results 1 to 5 of 5

Thread: percentBar()

  1. #1
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default percentBar()



    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.
    Simba Code:
    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

  2. #2
    Join Date
    Dec 2011
    Posts
    2,147
    Mentioned
    221 Post(s)
    Quoted
    1068 Post(s)

  3. #3
    Join Date
    Apr 2015
    Location
    FireFox
    Posts
    528
    Mentioned
    10 Post(s)
    Quoted
    227 Post(s)

    Default

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

  4. #4
    Join Date
    Jun 2014
    Posts
    463
    Mentioned
    27 Post(s)
    Quoted
    229 Post(s)

    Default

    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!
    Tsunami

  5. #5
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by Bly View Post
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •