sync on
 
r=255
g=0
b=0
rpoint=0
gpoint=0
bpoint=0
 
clear_screen:
 
cls
 
linebox(130,60,620,460,255,255,255)
 
ink rgb(255,255,255),0
set cursor 130,0
print "Click to draw."
set cursor 130,20
print "Spaceto clear screen."
do
 
	if mouseclick()=1 and fird=0
		oldx=mousex()
		oldy=mousey()
		fird=1
	endif
 
	if spacekey()=1 then goto clear_screen
 
	if mouseclick()=1 and mousewithin(130,60,620,460)
		ink rgb(r,g,b),0
		line oldx, oldy,mousex(),mousey()
		oldx=mousex()
		oldy=mousey()
	else
		fird=0
	endif
 
	gosub makecolourbox
	gosub makeslider
	gosub makecurrentcolour
	gosub handleslider
	gosub handlecurrentcolour
 
	sync
 
Loop
 
makecolourbox:
 
	for bx=1 to 255 step 4
		for by=1 to 255 step 4
			ink rgb(r,bx,by),0
			dot bx/4+10,by/4+10
		next by
	next bx
	linebox(9,9,74,74,255,255,255)
 
return
 
makeslider:
 
	for i=1 to 255 step 4
		ink rgb(i,0,0),0
		line i/4+10,85,i/4+10,95
	next i
	linebox(9,84,74,96,255,255,255)
 
	linebox(r/4+10-2,83,r/4+10+2,97,155,155,155)
 
return
 
makecurrentcolour:
 
	ink rgb(r,g,b),0
	box 10,105,40,125
	linebox(9,104,41,126,255,255,255)
	ink rgb(rpoint,gpoint,bpoint),0
	box 44,105,74,125
	linebox(44,104,75,126,255,255,255)
 
return
 
handleslider:
	if mousewithin(10,85,73,95)=1 and mouseclick()=1 then r=(mousex()-10)*4
return
 
handlecurrentcolour:
 
	if mousewithin(10,10,(255/4)+10,(255/4)+10)=1
		if mouseclick()=1
			temp=point(mousex(),mousey())
			g=rgbg(temp)
			b=rgbb(temp)
		endif
		temp=point(mousex(),mousey())
		rpoint=r
		gpoint=rgbg(temp)
		bpoint=rgbb(temp)
	endif
 
return
 
function linebox(x1,y1,x2,y2,r,g,b)
 
	ink rgb(r,g,b),0
	line x1,y1,x1,y2
	line x1,y2,x2,y2
	line x2,y2,x2,y1
	line x2,y1,x1,y1
 
endfunction
 
function mousewithin(x1,y1,x2,y2)
  if mousex()>x1 and mousex()<x2 and mousey()>y1 and mousey()<y2 then exitfunction 1
endfunction 0