Had this sitting on my harddrive, thought I would upload it. Maybe someone can use it?
[img]
remstart
==================================================
Project: HSL HealthBar Demo
Created: April 28, 2013
Version: 1.0.0
By: WickedX Software Design
Description: HSL HealthBar demo
run in a 800x600 resolution
==================================================
remend
rem ***** Start Main Source *****
` declare variables
health as integer
` initialize variables
health = 100
` set display mode and turn vsync on
set display mode 800, 600, screen depth(), 1
` load images
load image "FPSCScreen.bmp", 1, 1
load image "frame.png", 2, 1
` turn sync on and set sync sleep flag
sync on
sync sleep 1
` main loop
do
paste image 1, 0, 0
set cursor 0, 0
ink -1, 0
print "Use left and right arrow keys to lower and raise health."
center text 400, 32, "FPS: "+str$(screen fps())
health = health+rightkey()*(health<100)-leftkey()*(health>0)
HealthBar(2, 4, 570, health)
` update display
sync
loop
` end main loop
end
rem ***** End Main Source *****
rem ***** Start Functions *****
function HealthBar(imgNum as integer, xpos as integer, ypos as integer, percent as integer)
local Colour as dword
local hue as integer
hue = percent*80.0/100.0
Colour = HSLtoRGB(hue, 240, 120)
paste image imgNum, xpos, ypos, 1
inc xpos, 5
inc ypos, 5
ink Colour, 0
box xpos, ypos, xpos+percent, ypos+16
endfunction
` this function converts HSL/HSB (Hue, Saturation, Lightness/Hue, Saturation, Brightness) to a RGB color
function HSLtoRGB(hue as integer, sat as integer, lum as integer)
local R as integer
local G as integer
local B as integer
local Magic1 as integer
local Magic2 as integer
local Colour as dword
if sat=0
R = (lum*255)/240
G = (lum*255)/240
B = (lum*255)/240
else
if lum<=240/2
Magic2 = (lum*(240+sat)+(240/2))/240
else
Magic2 = lum+sat-((lum*sat)+(240/2))/240
endif
Magic1 = 2*lum-Magic2
R = (HueToRGB(Magic1, Magic2, hue+(240/3))*255+(240/2))/240
G = (HueToRGB(Magic1, Magic2, hue)*255+(240/2))/240
B = (HueToRGB(Magic1, Magic2, hue-(240/3))*255+(240/2))/240
endif
colour = rgb(R, G, B)
endfunction colour
` utility routine for HSLtoRGB
function HUEtoRGB(n1 as integer, n2 as integer, hue as integer)
local Value as integer
if hue<0 then inc hue, 240
if hue>240 then dec hue, 240
if hue<240/6
Value = (n1+(((n2-n1)*hue+(240/12))/(240/6)))
exitfunction Value
endif
if hue<240/2
Value = n2
exitfunction Value
endif
if hue<((240*2)/3)
Value = (n1+(((n2-n1)*(((240*2)/3)-hue)+(240/12))/(240/6)))
else
Value = n1
endif
endfunction Value
rem ***** End Functions *****
Complete project attached.