sync on
set display mode 1024,768,32
 
dim CANVAS_WIDTH(1)
dim CANVAS_HEIGHT(1)
dim CURRENT_COLOR(0)
dim DRAWING_ON(0)
dim OLD_X(0)
dim OLD_Y(0)
dim RED(6)
dim GREEN(6)
dim BLUE(6)
 
CANVAS_WIDTH(0)=256
CANVAS_HEIGHT(0)=256
 
make_rgb_box()
make_canvas()
 
 
do
   update_screen()
   if mouseclick()=1 then  check_controls()
   update_canvas()
   clean_up()
 
 
   sync
loop
 
 
`FUNCTIONS
 
function update_screen()
   cls
   paste image 2,0,650
   paste image 1,5,700
   paste image 100,CANVAS_WIDTH(1),CANVAS_HEIGHT(1)
 
   draw_sliders()
endfunction
 
function make_rgb_box()
ink rgb(255,255,255),0
   box 8,8,267,67
   for a = 0 to 255
      ink rgb(a,0,0),0
      line 10+a,10,10+a,25
 
      ink rgb(0,a,0),0
      line 10+a,30,10+a,45
 
      ink rgb(0,0,a),0
      line 10+a,50,10+a,65
 
   next a
   get image 1,8,8,267,67
 
   cls
   ink rgb(255,255,255),0
   box 0,0,35,39
   ink rgb(130,130,130),0
   box 2,2,33,37
   get image 3,0,0,35,39
 
   box 2,650,1000,760
   get image 2,2,650,1000,760
 
 
endfunction
 
 function check_controls()
   mx=mousex()
   my=mousey()
   if mx>=7 and mx<=262 and my>=702 and my<=759
      if my>=702 and my<=717 then RED(CURRENT_COLOR(0))=mx-7
      if my>=722 and my<=737 then GREEN(CURRENT_COLOR(0))=mx-7
      if my>=742 and my<=757 then BLUE(CURRENT_COLOR(0))=mx-7
   endif
   if mx>=5 and mx<=240 and my>=660 and my<=690
      lx=(mx-5)/35
      CURRENT_COLOR(0)=lx
   endif
   if mx>=CANVAS_WIDTH(1) and MX<=CANVAS_WIDTH(1)+CANVAS_WIDTH(0)
      if my>=CANVAS_HEIGHT(1) and my<=CANVAS_HEIGHT(1)+CANVAS_HEIGHT(0)
         ink rgb(RED(CURRENT_COLOR(0)),GREEN(CURRENT_COLOR(0)),BLUE(CURRENT_COLOR(0))),0
         if DRAWING_ON(0)=0
            dot mx,my
            DRAWING_ON(0)=1
            OLD_X(0)=mx:OLD_Y(0)=my
         else
            line OLD_X(0),OLD_Y(0),mx,my
            OLD_X(0)=mx:OLD_Y(0)=my
         endif
 
      endif
   endif
endfunction
 
 function draw_sliders()
   ink rgb(255,255,0),0
   line 7+RED(CURRENT_COLOR(0)),702,7+RED(CURRENT_COLOR(0)),717:text 275,701,str$(RED(CURRENT_COLOR(0)))
   line 7+GREEN(CURRENT_COLOR(0)),722,7+GREEN(CURRENT_COLOR(0)),737:text 275,721,str$(GREEN(CURRENT_COLOR(0)))
   line 7+BLUE(CURRENT_COLOR(0)),742,7+BLUE(CURRENT_COLOR(0)),757:text 275,741,str$(BLUE(CURRENT_COLOR(0)))
   for a = 0 to 6
      if a=CURRENT_COLOR(0) then paste image 3,a*35,656
      ink rgb(RED(a),GREEN(a),BLUE(a)),0:box 5+a*35,660,a*5+(a+1)*30,690
   next a
endfunction
 
function make_canvas()
   ink rgb(255,255,255),0
   box 1,1,CANVAS_WIDTH(0),CANVAS_HEIGHT(0)
   get image 100,1,1,CANVAS_WIDTH(0),CANVAS_HEIGHT(0)
   CANVAS_WIDTH(1)=(screen width()-CANVAS_WIDTH(0))/2
   CANVAS_HEIGHT(1)=(650-CANVAS_HEIGHT(0))/2
endfunction
 
function update_canvas()
   get image 100,CANVAS_WIDTH(1),CANVAS_HEIGHT(1),CANVAS_WIDTH(1)+CANVAS_WIDTH(0),CANVAS_HEIGHT(1)+CANVAS_HEIGHT(0)
endfunction
 
function clean_up()
   mx=mousex():my=mousey()
   if mouseclick()<>1 then DRAWING_ON(0)=0
   if mx<CANVAS_WIDTH(1) or mx>CANVAS_WIDTH(1)+CANVAS_WIDTH(0) or my<CANVAS_HEIGHT(1) or my>CANVAS_HEIGHT(1)+CANVAS_HEIGHT(0) then DRAWING_ON(0)=0
endfunction