button array

Geef hier je beste Liberty BASIC tips door. (Hier geen hulp vragen)

Moderators: anthonio, Abcott

button array

Berichtdoor bluatigro » wo mei 01, 2013 1:33 pm

dit is n manier om gekleurde en ronde of rechthoekige button array's te programmeren
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , rectmax , rondmax
winx = WindowWidth
winy = WindowHeight
rectmax = 7
rondmax = 7
clr$ = "black red green yellow blue pink cyan"
dim r$( rectmax ) , c$( rondmax )
i = 0
for i = 1 to 7
  r$( i ) = rect$( i * 50 , 50 , i * 50 + 40 , 90 , word$( clr$ , i ) )
  c$( i ) = rond$( i * 50 , 200 , 20 , word$( clr$ , i ) )
next i
nomainwin
open "rect & rond button array test" for graphics as #m
  #m "trapclose [quit]"
  #m "when leftButtonDown [leftButton]"
  #m "setfocus"
  for i = 1 to 7
    call drawrect r$( i )
    call drawrond c$( i )
  next i
wait
end
[leftButton]
  x = MouseX
  y = MouseY
  rno = rectno( x , y )
  if rno <> -1 then
    notice chr$( 13 ) + "You pressed rect button no : " ; rno ; " ." _
    + chr$( 13 ) + "Whits has a " ; rkl$( r$( rno ) ) ; " color ."
  end if
  cno = rondno( x , y )
  if cno <> -1 then
    notice chr$( 13 ) + "You pressed rond button no : " ; cno ; " ." _
    + chr$( 13 ) + "Whits has a " ; ckl$( c$( cno ) ) ; " color ."
  end if
wait
[quit]
  close #m
end
function rectno( x , y )
  uit = -1
  for i = 0 to rectmax
    if rx1( r$( i ) ) < x _
    and x < rx2( r$( i ) ) _
    and ry1( r$( i ) ) < y _
    and y < ry2( r$( i ) ) then
      uit = i
    end if
  next i
  rectno = uit
end function
function rect$( x1 , y1 , x2 , y2 , kl$ )
  if x1 > x2 then call swap x1 , x2
  if y1 > y2 then call swap y1 , y2
  rect$ = str$( x1 ) ; " " ; y1 ; " " ; x2 ; " " ; y2 ; " " ; kl$
end function
sub swap byref a , byref b
  h = a
  a = b
  b = h
end sub
function rx1( r$ )
  rx1 = val( word$( r$ , 1 ) )
end function
function ry1( r$ )
  ry1 = val( word$( r$ , 2 ) )
end function
function rx2( r$ )
  rx2 = val( word$( r$ , 3 ) )
end function
function ry2( r$ )
  ry2 = val( word$( r$ , 4 ) )
end function
function rkl$( r$ )
  rkl$ = word$( r$ , 5 )
end function
sub drawrect r$
  x1 = rx1( r$ )
  y1 = ry1( r$ )
  x2 = rx2( r$ )
  y2 = ry2( r$ )
  kl$ = rkl$( r$ )
  #m "backcolor " ; kl$
  #m "goto "; x1 ; " " ; y1
  #m "down"
  #m "boxfilled " ; x2 ;" "; y2
  #m "up"
end sub
function rond$( x , y , d , kl$ )
  rond$ = str$( x ) ; " " ; y ; " "; d ; " " ; kl$
end function
function rondno( x , y )
  uit = -1
  for i = 0 to rondmax
    if sqr( ( cx( c$( i ) ) - x ) ^ 2 + ( cy( c$( i ) ) - y ) ^ 2 ) < cd( c$( i ) ) then
      uit = i
    end if
  next i
  rondno = uit
end function
function cx( c$ )
  cx = val( word$( c$ , 1 ) )
end function
function cy( c$ )
  cy = val( word$( c$ , 2 ) )
end function
function cd( c$ )
  cd = val( word$( c$ , 3 ) )
end function
function ckl$( c$ )
  ckl$ = word$( c$ , 4 )
end function
sub drawrond c$
  x = cx( c$ )
  y = cy( c$ )
  d = cd( c$ )
  kl$ = ckl$( c$ )
  #m "goto " ; x ; " " ; y
  #m "down"
  #m "circlefilled " ; d
  #m "up"
end sub
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Keer terug naar Tips en informatie

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron