@Quadrazar
I haven't tried your dll yet but I will shortly.
Ok so I finnaly got on topic now. Been working on a function to swap a color to another and alow it to cycle through the color spectrum. It kinda works and I ran into a few problems.
First of all it's a bit unsightly, I'm sure there are better ways to do this but I cannot figure it out.
Secondly the function works when the color values are more variant (255,100,0) but when it's something closer like rgb(255,255,0) it has problems.
Use Left and Right to change colors.
Another note, I am not looking for a color transition as that does not do well when I'm trying to conver a whole gradient of red into blue.
sync on
sync rate 0
REM Set Base Color
base = rgb(255,0,0)
REM Draw First Box on Screen
Hue = 0
color = ColorSwap(base,Hue)
ink color,0
box 100,100,200,200
do
REM Left
if leftkey() = 1
if keyL = 0
Hue = Hue - 1
color = ColorSwap(base,Hue)
ink color,0
box 100,100,200,200
endif
keyL = 0
else
keyL = 0
endif
REM Right
if rightkey() = 1
if keyR = 0
Hue = Hue + 1
color = ColorSwap(base,Hue)
ink color,0
box 100,100,200,200
endif
KeyR = 0
else
KeyR = 0
endif
REM Out of bounce Check
if Hue < 0 then Hue = 600
if Hue > 600 then Hue = 0
REM Sync
sync
loop
Function ColorSwap(color,Hue)
r = rgbr(color)
g = rgbg(color)
b = rgbb(color)
ir = r
ig = g
ib = b
REM R -> Y +G
if Hue => 0 and Hue =< 99
r = ir
g = ig - (ig-ir)/100.0*Hue
b = ib
endif
REM Y -> G -R
if Hue => 100 and Hue =< 199
r = ir - (ir-ig)/100.0*(Hue-100)
g = ir
b = ib
endif
REM G -> C +B
if Hue => 200 and Hue =< 299
r = ig
g = ir
b = ib - (ib-ir)/100.0*(Hue-200)
endif
REM C -> B -G
if Hue => 300 and Hue =< 399
r = ig
g = ir - (ir-ig)/100.0*(Hue-300)
b = ir
endif
REM B -> M +R
if Hue => 400 and Hue =< 499
r = ig - (ig-ir)/100.0*(Hue-400)
g = ig
b = ir
endif
REM M -> R -B
if Hue => 500 and Hue =< 599
r = ir
g = ig
b = ir - (ir-ib)/100.0*(Hue-500)
endif
REM Text to Screen
cls
ink rgb(255,255,255),0
text 0,0,str$(r)
text 0,15,str$(g)
text 0,30,str$(b)
text 0,45,str$(Hue)
color = rgb(r,g,b)
EndFunction color
[edit]
Actually I'm not very experienced in using dll.
[edit]
After playing around with the color settings in Photoshop an idea hit me, I notice that there was a constant high and low that does not change, if I can set the color back into the red state I can find the hue value and continue from there. I'm not good at explaining but the code now works with any color combination!
The only problem left is to optimaize it. I had to use a goto because there was a subroutine inside that function.
[edit]
Scratch that last one, it wasn't accurate because it used a percentage of 100, this updated one uses 255 and should work better.
sync on
sync rate 0
REM Set Base Color
color = rgb(255,100,0)
REM Draw First Box on Screen
color = ColorSwap(color,0)
ink color,0
box 100,100,200,200
do
REM Left
if leftkey() = 1
if keyL = 0
color = ColorSwap(color,-10)
ink color,0
box 100,100,200,200
endif
keyL = 0
else
keyL = 0
endif
REM Right
if rightkey() = 1
if keyR = 0
color = ColorSwap(color,10)
ink color,0
box 100,100,200,200
endif
KeyR = 0
else
KeyR = 0
endif
REM Sync
sync
loop
Function ColorSwap(color,IncValue)
br = rgbr(color)
bg = rgbg(color)
bb = rgbb(color)
r = br
g = bg
b = bb
REM Getting Low
Low = 255
if r < Low then Low = r
if g < Low then Low = g
if b < Low then Low = b
REM Getting High
High = 0
if r > High then High = r
if g > High then High = g
if b > High then High = b
REM Neutralizing Color
r = high
g = low
b = low
ir = r
ig = g
ib = b
REM Finding Hue
for HueLP = 0 to 255*6
Hue = HueLP
gosub HueCheck
if r = br and g = bg and b = bb then HueLP = 255*6
next HueLP
Hue = Hue + IncValue
REM Out of bounce Check
if Hue < 0 then Hue = 255*6
if Hue => 255*6 then Hue = 0
gosub HueCheck
REM Text to Screen
cls
ink rgb(255,255,255),0
text 0,15*0,str$(r)+" - "+str$(br)
text 0,15*1,str$(g)+" - "+str$(bg)
text 0,15*2,str$(b)+" - "+str$(bb)
text 0,15*4,"Hue: "+str$(Hue) +" - " + str$(HueLP)
text 0,15*6,str$(high)
text 0,15*7,str$(low)
color = rgb(r,g,b)
goto esc
HueCheck:
REM R -> Y +G
if Hue => 0 and Hue < 255
r = ir
g = ig - (ig-ir)/255.0*Hue
b = ib
endif
REM Y -> G -R
if Hue => 255 and Hue < 255*2
r = ir - (ir-ig)/255.0*(Hue-255)
g = ir
b = ib
endif
REM G -> C +B
if Hue => 255*2 and Hue < 255*3
r = ig
g = ir
b = ib - (ib-ir)/255.0*(Hue-255*2)
endif
REM C -> B -G
if Hue => 255*3 and Hue < 255*4
r = ig
g = ir - (ir-ig)/255.0*(Hue-255*3)
b = ir
endif
REM B -> M +R
if Hue => 255*4 and Hue < 255*5
r = ig - (ig-ir)/255.0*(Hue-255*4)
g = ig
b = ir
endif
REM M -> R -B
if Hue => 255*5 and Hue < 255*6
r = ir
g = ig
b = ir - (ir-ib)/255.0*(Hue-255*5)
endif
return
esc:
EndFunction color
[edit]
Made a few changes, It seems the last one didn't work with all color combination as well. Found that the High and Low values are very important. This update works better but the whole process is still rather slow.
set display mode 640,480,32
sync on
sync rate 0
REM Set Base Color
color = rgb(200,200,0)
REM Draw First Box on Screen
color = ColorSwap(color,0)
ink color,0
box 100,100,200,200
set text opaque
do
REM Left
if leftkey() = 1
if keyL = 0
color = ColorSwap(color,-1)
ink color,0
box 100,100,200,200
endif
keyL = 0
else
keyL = 0
endif
REM Right
if rightkey() = 1
if keyR = 0
color = ColorSwap(color,1)
ink color,0
box 100,100,200,200
endif
KeyR = 0
else
KeyR = 0
endif
REM Sync
sync
loop
Function ColorSwap(color,IncValue)
br = rgbr(color)
bg = rgbg(color)
bb = rgbb(color)
r = br
g = bg
b = bb
REM Getting Low
Low = 255
if r < Low then Low = r
if g < Low then Low = g
if b < Low then Low = b
REM Getting High
High = 0
if r > High then High = r
if g > High then High = g
if b > High then High = b
REM Neutralizing Color
r = high
g = low
b = low
ir = r
ig = g
ib = b
REM Finding Hue
for HueLP = 0 to High*6
Hue = HueLP
gosub HueCheck
if r = br and g = bg and b = bb then HueLP = High*6
next HueLP
Hue = Hue + IncValue
REM Out of bounce Check
if IncValue < 0 and Hue =< 0 then Hue = High*6-1
if IncValue > 0 and Hue => High*6 then Hue = 0
gosub HueCheck
REM Text to Screen
cls
ink rgb(255,255,255),0
text 0,15*0,str$(r)+" - "+str$(br)
text 0,15*1,str$(g)+" - "+str$(bg)
text 0,15*2,str$(b)+" - "+str$(bb)
text 0,15*4,"Hue: "+str$(Hue) +" - " + str$(HueLP)
text 0,15*6,str$(high)
text 0,15*7,str$(low)
color = rgb(r,g,b)
goto esc
HueCheck:
REM R -> Y +G
if Hue => 0 and Hue < High
r = High
g = Low - (Low-High)/High*Hue
b = Low
endif
REM Y -> G -R
if Hue => High and Hue < High*2
r = High - (High-Low)/High*(Hue-High)
g = High
b = Low
endif
REM G -> C +B
if Hue => High*2 and Hue < High*3
r = Low
g = High
b = Low - (Low-High)/High*(Hue-High*2)
endif
REM C -> B -G
if Hue => High*3 and Hue < High*4
r = Low
g = High - (High-Low)/High*(Hue-High*3)
b = High
endif
REM B -> M +R
if Hue => High*4 and Hue < High*5
r = Low - (Low-High)/High*(Hue-High*4)
g = Low
b = High
endif
REM M -> R -B
if Hue => High*5 and Hue < High*6
r = High
g = Low
b = High - (High-Low)/High*(Hue-High*5)
endif
return
esc:
EndFunction color