Sver
Full Member
Posts: 145
|
Post by Sver on Sept 16, 2020 1:59:44 GMT -5
Getpixel produce a longcolor Convert longcolor to RGB
Make a filter with hue
Value x to x is red, ,....... See HSL colors
hue=hue(0,0,254)
print hue
wait
function hue(red,green,blue)
r=red/255
g=green/255
b=blue/255
if r>=g and r>=b then
min=min(g,b)
hue=(g-b)/(r-min)*60
if hue<0 then hue=hue+360
end if
if g>=r and g>=b then
min=min(r,b)
hue=(2+(b-r)/(g-min))*60
if hue<0 then hue=hue+360
end if
if b>=r and b>=g then
min=min(r,g)
hue=(4+(r-g)/(b-min))*60
if hue<0 then hue=hue+360
end if
end function
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Sept 16, 2020 9:17:03 GMT -5
Little bug in de first code. When red, green and blue are the same (grey), it produce a division by zero.
hue=hue(255,255,255) print hue wait
function hue(red,green,blue) r=red/255 g=green/255 b=blue/255
min=min(g,b) if r>=g and r>=b and r<>min then hue=(g-b)/(r-min)*60 if hue<0 then hue=hue+360 end if
min=min(r,b) if g>=r and g>=b and g<>min then hue=(2+(b-r)/(g-min))*60 if hue<0 then hue=hue+360 end if
min=min(r,g) if b>=r and b>=g and b<>min then hue=(4+(r-g)/(b-min))*60 if hue<0 then hue=hue+360 end if
end function
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Sept 16, 2020 9:38:53 GMT -5
RGB light
light=light(5,25,25) print light wait
function light(red,green,blue) if red>=green and red>= blue then max=red if green>=red and green>=blue then max=green if blue>=red and blue>=green then max=blue
if red<=green and red<=blue then min=red if green<=red and green<=blue then min=green if blue<=red and blue<=green then min=blue
light=(max+min)/2 light=light/2.55 end function
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Sept 16, 2020 9:42:10 GMT -5
rgb Saturation makes HSL complete
sat=sat(220,156,46) print sat wait
function sat(red,green,blue) if red>=green and red>= blue then max=red if green>=red and green>=blue then max=green if blue>=red and blue>=green then max=blue
if red<=green and red<=blue then min=red if green<=red and green<=blue then min=green if blue<=red and blue<=green then min=blue
if max-min=0 then sat=0
else
max=max/255 min=min/255
l=(max+min)/2
if l<0.5 then sat=((max-min)/(max+min))*100 else sat=(max-min)/(2-max-min)*100 end if end if
end function
|
|
|
Post by tsh73 on Sept 16, 2020 12:46:33 GMT -5
FYI
if red>=green and red>= blue then max=red if green>=red and green>=blue then max=green if blue>=red and blue>=green then max=blue
amounts to
max=max(red, max(green, blue))
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Sept 16, 2020 12:56:32 GMT -5
FYI if red>=green and red>= blue then max=red if green>=red and green>=blue then max=green if blue>=red and blue>=green then max=blue
amounts to max=max(red, max(green, blue)) Thanks, easy. Tried: max=max(red, green, blue)
|
|