title "3"
width 300,320
//摜
buffer 2
picload "fruit.jpg"
gsel 0
gcopy 2,0,0,300,300
buffer 3,300,300
await 10
y = 0
while y<300
x = 0
while x<300
gsel 2
pget x,y
c = (ginfo_r+ginfo_g+ginfo_b)/3
gsel 3
color c,c,c
pset x,y
x+
wend
y+
wend
gsel 0
await 990
title "2"
buffer 4
gosub *l_color_board
gsel 0
await 1000
title "1"
await 1000
gcopy 3,0,0,300,300
title "F"

while
getkey key,1
if key = 1:gosub *l_click
gosub *l_draw
await 0
wend

stop

*l_draw
	redraw 0
	pos 0,300
	gcopy 4,0,0,300,24	
	color 0,0,0
	circle cursor-5,305,cursor+5,315
	redraw 1
	return

*l_color_board
	H = 0
	while H<300
	Hi = H/50
	f = 256*H/50-256*Hi
	if Hi = 0:color 255,f,0
	if Hi = 1:color 255-f,255,0
	if Hi = 2:color 0,255,f
	if Hi = 3:color 0,255-f,255
	if Hi = 4:color f,0,255
	if Hi = 5:color 255,0,255-f
	line H,0,H,24
	H+
	wend
	return

*l_click
	if mousey < 300{
		redraw 0
		c_x = mousex
		c_y = mousey
		y = c_y-10
		while y<=c_y+10
		x = c_x-10
		while x<=c_x+10
		if (x-c_x)*(x-c_x)+(y-c_y)*(y-c_y)<=100{
			gsel 2
			pget x,y
			r = ginfo_r
			g = ginfo_g
			b = ginfo_b
			if g >= b{
				if r >= g{
					max = r
					min = b
				}
				else{
					max = g
					if b>=r:min = r :else:min = b
				}
			}
			else{
				if r >= b{
					max = r
					min = g
				}
				else{
					max = b
					if g>=r:min = r :else:min = g
				}
			}
			V = max
			if max=0:S=0:else:S = 255*(max-min)/max
			gsel 0
			hsvcolor cursor*192/300,S,V
			pset x,y
		}
		x+
		wend
		y+
		wend
		redraw 1
	}
	else{
		cursor = mousex
	}
	return
	
/*
			Hi = H/60
			f = 0.0+H/60-Hi
			p = 1.0*V * (255-S)
			q = 1.0*V * (255-f*S/60)
			t = 1.0*V * (255-S*(1.0-f))
			if S = 0{
				color V,V,V
			}
			else{
				if Hi = 0:color V,t,p
				if Hi = 1:color q,V,p
				if Hi = 2:color p,V,t
				if Hi = 3:color p,q,V
				if Hi = 4:color t,p,V
				if Hi = 5:color V,p,q
			}*/