Post by tenochtitlanuk on Jun 25, 2021 16:18:04 GMT -5
A quick demo of how easy it is to get continuous ranges of colours by specifying HSV ( hue, saturation, value) rather than RGB. Hues 0 to 359 go through red-yellow-green-cyan -blue-magenta. Saturations 0 to 0.99 fade the colours towards white. Value 0 to 0.99 reduce them towards black. See Wikipedia.
' filled curve
nomainwin
global hw, hdc, pi, re, gr, bl, col$
pi =4 *atn( 1)
'Cx =251: Cy =251 ' centre to fill from
WindowWidth =540: WindowHeight =565
open "Filled graphic shapes" for graphics_nsb as #wg
hw =hwnd( #wg)
calldll #user32, "GetDC", hw as ulong, hdc as ulong
#wg "trapclose quit"
#wg "home ; size 3 ; down ; fill darkblue ; up"
iMax =20
result = mkdir( "temp")
for s =0 to 0.99 step 0.05 ' repeat for values of saturation
for i =0 to 20 step 0.02 ' circle through all values of hue
scan
call hsv2rgb int( 360 *i /iMax), s, 0.99 ' hue 0-360, saturation 0-1, value 0-1: sets global re, gr, bl, col$'
Cx =265 +int( 230 *sin( i /iMax *pi *2))
Cy =270 +int( 230 *cos( i /iMax *pi *2))
#wg "color "; re; " "; gr; " "; bl
#wg "up ; goto "; 265; " "; 270
#wg "backcolor "; re; " "; gr; " "; bl
'#wg "down ; circlefilled "; 110
#wg "down ; goto "; Cx; " "; Cy
targetcolor =bl *2^16 +gr *2^8 +re' this is also the colour of the outline to fill out TO.
calldll #gdi32, "ExtFloodFill", hdc as ulong, Cx as long, Cy as long, targetcolor as long, _FLOODFILLBORDER as long, result as long
next i
#wg "getbmp scr 1 1 531 542"
bmpsave "scr", "temp/" +right$( "0000" +str$( int( s *1000)), 4) +".bmp"
next s
wait
sub delay t
timer t, [o]
wait
[o]
timer 0
end sub
sub hsv2rgb h, s, v ' hue 0-360, saturation 0-1, value 0-1
c =v *s ' chroma
h =h
x =c *( 1 -abs( ( ( h /60) mod 2) -1))
m =v -c ' matching adjustment
select case
case h < 60
r = c: g = x: b = 0
case h <120
r = x: g = c: b = 0
case h <180
r = 0: g = c: b = x
case h <240
r = 0: g = x: b = c
case h <300
r = x: g = 0: b = c
case else
r = c: g = 0: b = x
end select
re = abs( int( 256 *( r + m)))
gr = abs( int( 256 *( g + m)))
bl = abs( int( 256 *( b + m)))
col$ =right$( " " +str$( re), 3) +" " +right$( " " +str$( gr), 3) +" " +right$( " " +str$( bl), 3)
end sub
sub quit h$
calldll #user32, "ReleaseDC", hw as ulong, hdc as ulong, ret as void 'release the DC
close #wg
end
end sub