Color selector with simulaneous operating sliders
Posted: Tue May 07, 2013 1:31 pm
gosub init_prog
loop1:
if ind(1)>=0 then r=ind(1)/100
if ind(2)>=0 then g=ind(2)/100
if ind(3)>=0 then b=ind(3)/100
fill color r,0,0
fill rect x(1)+2,yo-158 to x(1)+78,yo-62
fill color 0,g,0
fill rect x(2)+2,yo-158 to x(2)+78,yo-62
fill color 0,0,b
fill rect x(3)+2,yo-158 to x(3)+78,yo-62
fill color r,g,b
fill rect 100,10 to 640,200
loop2:
for k=0 to 2
xt=touch_x(k) ! yt=touch_y(k)
for i=1 to 3
if xt>=0 then ind(i)=slider(tit$(i),x(i),400,440,xt,yt,0)
next i
next k
goto loop1
end
init_prog:
option base 1
dim tit$(3)
dim k$(3),x(3),ind(3)
for i=1 to 3 ! read k$(i),tit$(i),x(i) ! next i
data "R","red",100, "G","green",330, "B","blue",560
xo=100 ! dx=230 ! yo=400 ! dy=30
ind(1)=9 ! ind(2)=9 ! ind(3)=9
graphics
draw color 0,0,0 ! fill color .8,.8,.8
graphics clear .8,.8,.8
draw size 4
draw rect 98,8 to 642,202
draw font size 32
draw color 1,0,0
draw text "R" at x(1)+30,yo-40
draw color 0,1,0
draw text "G" at x(2)+30,yo-40
draw color 0,0,1
draw text "B" at x(3)+30,yo-40
draw color 0,0,0
for j=1 to 3
draw rect x(j),yo-160 to x(j)+80,yo-60
slider(tit$(j),x(j),400,440,0,0,1)
next j
return
def slider (tit$,xt,yt,hgt,xtouch,ytouch,ind)
xb=xt+70 ! if hgt<120 then hgt=120 ! yb=yt+hgt+70 ! dy=hgt/10
if ind=-1 then
fill rect xt-2,yt-2 to xb+2,yb+2 ! return
end if
if ind=1 then
draw size 3 ! draw font size 14
draw rect xt,yt to xb,yb
draw line xt,yt+20 to xb,yt+20
draw text tit$ at xt+(70-8*len(tit$))/2,yb-20
ys=yb-30
else
if xtouch<xt or xtouch>xb or ytouch<yt or ytouch>yb then
slider=-1
return
end if
ys=ytouch
if ys<yt+40 then ys=yt+40 ! if ys>yb-30 then ys=yb-30
end if
draw size 2
graphics lock
fill color .8,.8,.8 ! draw font size 14
fill rect xt+2,yt+33 to xb-2,yb-25
draw rect xt+28,yt+40 to xt+32,yb-30
y=yb-30+dy
for i=0 to 100 step 10
y=y-dy ! i$=i
draw line xt+24,y to xt+36,y
draw text i$ at xt+40,y-9
next i
fill color 0,0,.6
fill rect xt+6,ys-4 to xt+54,ys+4 ! fill color .8,.8,.8
tt=(yb-ys-30)*100/(yb-yt-70)
fill rect xt+8,yt+2 to xb-2,yt+15
draw text n2a$(tt,5,1) at xt+8,yt
graphics unlock
draw font size 20
slider=tt
end def
def n2a$(num,lang,dec)
b$=" "
fac=10^dec
num$=int(fac*num+.5)/fac
tot=lang-len(num$)
if tot<1 then tot=1
a$=substr$(b$,1,tot) & num$
n2a$=a$
end def
loop1:
if ind(1)>=0 then r=ind(1)/100
if ind(2)>=0 then g=ind(2)/100
if ind(3)>=0 then b=ind(3)/100
fill color r,0,0
fill rect x(1)+2,yo-158 to x(1)+78,yo-62
fill color 0,g,0
fill rect x(2)+2,yo-158 to x(2)+78,yo-62
fill color 0,0,b
fill rect x(3)+2,yo-158 to x(3)+78,yo-62
fill color r,g,b
fill rect 100,10 to 640,200
loop2:
for k=0 to 2
xt=touch_x(k) ! yt=touch_y(k)
for i=1 to 3
if xt>=0 then ind(i)=slider(tit$(i),x(i),400,440,xt,yt,0)
next i
next k
goto loop1
end
init_prog:
option base 1
dim tit$(3)
dim k$(3),x(3),ind(3)
for i=1 to 3 ! read k$(i),tit$(i),x(i) ! next i
data "R","red",100, "G","green",330, "B","blue",560
xo=100 ! dx=230 ! yo=400 ! dy=30
ind(1)=9 ! ind(2)=9 ! ind(3)=9
graphics
draw color 0,0,0 ! fill color .8,.8,.8
graphics clear .8,.8,.8
draw size 4
draw rect 98,8 to 642,202
draw font size 32
draw color 1,0,0
draw text "R" at x(1)+30,yo-40
draw color 0,1,0
draw text "G" at x(2)+30,yo-40
draw color 0,0,1
draw text "B" at x(3)+30,yo-40
draw color 0,0,0
for j=1 to 3
draw rect x(j),yo-160 to x(j)+80,yo-60
slider(tit$(j),x(j),400,440,0,0,1)
next j
return
def slider (tit$,xt,yt,hgt,xtouch,ytouch,ind)
xb=xt+70 ! if hgt<120 then hgt=120 ! yb=yt+hgt+70 ! dy=hgt/10
if ind=-1 then
fill rect xt-2,yt-2 to xb+2,yb+2 ! return
end if
if ind=1 then
draw size 3 ! draw font size 14
draw rect xt,yt to xb,yb
draw line xt,yt+20 to xb,yt+20
draw text tit$ at xt+(70-8*len(tit$))/2,yb-20
ys=yb-30
else
if xtouch<xt or xtouch>xb or ytouch<yt or ytouch>yb then
slider=-1
return
end if
ys=ytouch
if ys<yt+40 then ys=yt+40 ! if ys>yb-30 then ys=yb-30
end if
draw size 2
graphics lock
fill color .8,.8,.8 ! draw font size 14
fill rect xt+2,yt+33 to xb-2,yb-25
draw rect xt+28,yt+40 to xt+32,yb-30
y=yb-30+dy
for i=0 to 100 step 10
y=y-dy ! i$=i
draw line xt+24,y to xt+36,y
draw text i$ at xt+40,y-9
next i
fill color 0,0,.6
fill rect xt+6,ys-4 to xt+54,ys+4 ! fill color .8,.8,.8
tt=(yb-ys-30)*100/(yb-yt-70)
fill rect xt+8,yt+2 to xb-2,yt+15
draw text n2a$(tt,5,1) at xt+8,yt
graphics unlock
draw font size 20
slider=tt
end def
def n2a$(num,lang,dec)
b$=" "
fac=10^dec
num$=int(fac*num+.5)/fac
tot=lang-len(num$)
if tot<1 then tot=1
a$=substr$(b$,1,tot) & num$
n2a$=a$
end def