Post by crazynate on May 19, 2010 21:43:53 GMT -5
I'm currently working on improving my Art Studio Basic program and i made this simple program that can convert hexadecimal colors to RGB and vice versa.
dim hexcode$,rgb(2)
dim hexadecimal$(15)
hexadecimal$(0) = "0"
hexadecimal$(1) = "1"
hexadecimal$(2) = "2"
hexadecimal$(3) = "3"
hexadecimal$(4) = "4"
hexadecimal$(5) = "5"
hexadecimal$(6) = "6"
hexadecimal$(7) = "7"
hexadecimal$(8) = "8"
hexadecimal$(9) = "9"
hexadecimal$(10) = "a"
hexadecimal$(11) = "b"
hexadecimal$(12) = "c"
hexadecimal$(13) = "d"
hexadecimal$(14) = "e"
hexadecimal$(15) = "f"
dim red,green,blue
dim hexcolor(5),rgbcolor(5)
dim sprite
dim i,h
printr "hex to rgb"
input "hex code: ",hexcode$
for i=0 to 5
for h=0 to 15
if lcase$(mid$(hexcode$,i+1,1))=hexadecimal$(h) then
hexcolor(i)=h
endif
next
next
rgb(0)=(hexcolor(0)*pow(16,1))+(hexcolor(1)*pow(16,0))
rgb(1)=(hexcolor(2)*pow(16,1))+(hexcolor(3)*pow(16,0))
rgb(2)=(hexcolor(4)*pow(16,1))+(hexcolor(5)*pow(16,0))
printr "red: "+rgb(0)
printr "green: "+rgb(1)
printr "blue: "+rgb(2)
sprite=newsprite(loadtex(""))
sprsetsize(64,64)
sprsetpos(windowwidth()/2,48)
sprsetcolor(rgb(0)/255.0,rgb(1)/255.0,rgb(2)/255.0)
printr"------------------------------------"
printr "rgb to hex"
input "red: ",rgb(0)
input "green: ",rgb(1)
input "blue: ",rgb(2)
hexcolor(0) = rgb(0)/16
hexcolor(1) = (rgb(0)%16)
hexcolor(2) = rgb(1)/16
hexcolor(3) = (rgb(1)%16)
hexcolor(4) = rgb(2)/16
hexcolor(5) = (rgb(2)%16)
hexcode$ = ""
for i=0 to 5
for h=0 to 15
if hexcolor(i)=h then
hexcode$=hexcode$+hexadecimal$(h)
endif
next
next
printr hexcode$
sprite=newsprite(loadtex(""))
sprsetsize(64,64)
sprsetpos(windowwidth()/2,160)
sprsetcolor(rgb(0)/255.0,rgb(1)/255.0,rgb(2)/255.0)