Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Lifebar Program
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Danjen




PostPosted: Fri Mar 07, 2008 11:20 pm   Post subject: Lifebar Program

Just some useless "lifebar" program I cooked up. Feel free to use it in whatever you want. I tried to make it as flexible as possible, but you might still find a way to 'break' it. Confused

Syntax is:

code:

x1_ ,y1_,x2_,y2_ -> Coordinates on screen. Same as a box.
BorderThk_ -> How thick the border around the inside is. Set to -1 to remove the border.
BackColor_ -> Color underneath the life bar. Set to -1 to ignore the backcolor, making it transparent.
TrimColor_ -> Color of the border.
Value1_, Value2_ -> The two values you are comparing. Program will convert it to a percentage (v1 / v2)
Col1_,Col2_ -> The color (with RGBColor values) it will start at and fade to.


Turing:

type RGBColor:
    record
        r,g,b:real
    end record

proc DrawBar (x1_, y1_, x2_, y2_, BorderThk_, BackColor_, TrimColor_, Value1_, Value2_ : int, Col1_, Col2_ : RGBColor)
    const percent : real := Value1_ / Value2_
    const width : real := abs ((x2_ - 2 - BorderThk_) - (x1_ + 2 + BorderThk_))
    var FinalColor : int
    var ColFactor : RGBColor
    ColFactor.r := ((Col2_.r - Col1_.r) / 100)
    ColFactor.g := ((Col2_.g - Col1_.g) / 100)
    ColFactor.b := ((Col2_.b - Col1_.b) / 100)

    if BackColor_ not= -1 then
        Draw.FillBox (x1_, y1_, x2_, y2_, BackColor_)
    end if

    for i : 1 .. BorderThk_ %%Draws the border between the black outlines.
        Draw.Box (x1_ + i, y1_ + i, x2_ - i, y2_ - i, TrimColor_)
    end for
    Draw.Box (x1_, y1_, x2_, y2_, black) %%Outermost black line.
    Draw.Box (x1_ + BorderThk_ + 1, y1_ + BorderThk_ + 1, x2_ - BorderThk_ - 1, y2_ - BorderThk_ - 1, black) %%Innermost black line.

    if Value1_ > 0 then %%The inner fill bar color.
        FinalColor := RGB.AddColor (
            Col2_.r - (percent * 100 * (percent * ColFactor.r)),
            Col2_.g - (percent * 100 * (percent * ColFactor.g)),
            Col2_.b - (percent * 100 * (percent * ColFactor.b)))
        Draw.FillBox (
            x1_ + BorderThk_ + 2,
            y1_ + BorderThk_ + 2,
            x1_ + BorderThk_ + 2 + floor (min (percent, 1) * width),
            y2_ - BorderThk_ - 2,
            FinalColor)
    end if
end DrawBar


And, an example:

Turing:

View.Set ("offscreenonly")
var col1, col2 : RGBColor
col1.r := 0
col1.g := 1
col1.b := 0
col2.r := 0
col2.g := 1
col2.b := 0
for i : 0 .. 100
    cls
    DrawBar (200, 200, 310, 220, 4, blue, grey, i, 100, col1, col2)
    View.Update ()
    delay (20)
end for

Sponsor
Sponsor
Sponsor
sponsor
BigBear




PostPosted: Sat Mar 08, 2008 7:38 pm   Post subject: Re: Lifebar Program

Just wondering why did you create a new type and have to specify three different values? Why not have it like blue and grey?
Danjen




PostPosted: Tue Mar 11, 2008 8:58 pm   Post subject: Re: Lifebar Program

Well, I figured that having three closely related, mutually required variables merited their own type. *shrug*
BigBear




PostPosted: Tue Mar 11, 2008 9:16 pm   Post subject: Re: Lifebar Program

I like your program a lot more than your example shows. Also the new type can be used to make secondary colours like yellow. I can see myself using it. Great Job.
A.J




PostPosted: Thu Mar 13, 2008 12:52 pm   Post subject: Re: Lifebar Program

pretty cool program!!!
thnx!

A.J
Kharybdis




PostPosted: Wed Mar 26, 2008 12:12 pm   Post subject: Re: Lifebar Program

Good job on the life bar program. ITs cool..
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: