circuit teken prog

Algemene discussies en vragen omtrent Liberty BASIC programma's. Stuur zoveel mogelijk delen van listings (snippets) in als je hulp wilt.

Moderators: anthonio, Abcott

circuit teken prog

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

dit is n poging n circuit teken pogje te maken

instukties :
- pak n node uit t menu
- plak het in t veld
- herhaal todat je r genoeg hebt
- teken de verbindingen met line

error :
- de open file menu optie doet nix
- de line menu optie tekent nix

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global nodemax , nodemem , ioline , iline , oline , oldnode , file$ , winx , winy
winx = WindowWidth
winy = WindowHeight
nodemax = 10
dim nd$( nodemax )
global state , nodetel , nodeselected$ , beginlinex , beginliney
global nothing , drawand , drawor , drawnot , drawxor , beginline , endline
drawand = 2
drawor = 3
drawnot = 4
drawxor = 5
beginline = 6
endline = 7
oline = 32
iline = 64
oldnode = -1
menu #m , "file" _
        , "new"     , [new] _
        , "open..."    , [new] _
        , "save as..." , [save_as] _
        , "save"    , [save] _
      ,|, "exit"    , [quit]
menu #m , "node" _
        , "and"  , [and] _
        , "or"   , [or] _
        , "not"  , [not] _
        , "xor"  , [xor] _
        , "line" , [line]
nomainwin
open "cirket draw 1.0" for graphics as #m
  #m "trapclose [quit]"
  #m "backcolor yellow"
  #m "when leftButtonDown [leftButton]"
  #m "when rightButtonDown [rightButton]"
wait
[leftButton]
  x = MouseX
  y = MouseY
  select case state
    case beginline
      beginlinex = x
      beginliney = y
      nodenr = nodenr( x , y )
      if nodenr <> -1 then
        state = endline
        nodemem = nodenr
      else
        oldnode = nodenr
      end if
    case endline
      #m "line " ; beginlinex ; " " ; beginliney ; " " ; x ; " " ; y
      nodenr = nodenr( x , y )
      if nodenr <> -1 then
        ''todo : link nodenr whit oldnode
      else
        #m "goto " ; x ; " " ; y
        #m "down"
        #m "circlefilled 10"
        #m "up"
        state = beginline
      end if
    case drawand , drawor , drawnot , drawxor
      if nodetel < nodemax and nodeselected$ <> "" then
        n$ = node$( MouseX , MouseY , nodeselected$ , -1 , -1 )
        nd$( nodetel ) = n$
        nodetel = nodetel + 1
      else
        notice chr$( 13 ) + "NO MORE NODES !!"
      end if
      call draw n$
    case else
      notice "No node-type selection error !!"
  end select

wait
[rightButton]
  x = MouseX
  y = MouseY
  n = nodenr( x , y )
  if n <> -1 then
    notice chr$( 13 ) + "You selected node " ; n ; " ." _
    + chr$( 13 ) + "Node type : " ; nop$( nd$(  n ) ) ; " ."
  end if
wait
function nodenr( x , y )
  fount = -1
  for i = 0 to nodetel
    if x > nx( nd$( i ) ) - 10 _
    and x < nx( nd$( i ) ) + 50 _
    and y > ny( nd$( i ) ) - 15 _
    and y < ny( nd$( i ) ) + 50 then
      fount = i
    end if
  next i
  nodenr = fount
end function
function port$( x , y )
  n = nodenr( x , y )
  uit$ = str$( n )
  if n <> -1 then
    nx = nx( nd$( n ) )
    ny = ny( nd$( n ) )
    if in( x , y , nx - 10 , ny - 15 , nx + 10 , ny + 10 ) then
      uit$ = "green"
    end if
    if nop$( nd$( n ) ) <> "not" then
      if in( x , y , nx - 10 , ny + 30 , nx + 10 , ny + 50 ) then
        uit$ = "blue"
      end if
    end if
    if in( x , y , nx + 30 , ny + 15 , nx + 50 , ny + 35 ) then
      uit$ = "red"
    end if
  else
    uit$ = "no node"
  end if
  port$ = uit$
end function
function in( x , y , x1 , y1 , x2 , y2 )
  in = x1 < x and x < x2 and y1 < y and y < y2
end function
function node$( x , y , op$ , green , blue )
  node$ = op$ + " " ; x ; " " ; y ; " " ; green ; " " ; blue
end function
sub draw n$
  x = nx( n$ )
  y = ny( n$ )
  call drawrect x - 10 , y - 15 , x + 50 , y + 50 , "yellow"
  call drawrect x - 10 , y - 15 , x + 10 , y + 10 , "green"
  if nop$( n$ ) <> "not" then
    call drawrect x - 10 , y + 30 , x + 10 , y + 50 , "blue"
  end if
  call drawrect x + 30 , y + 15 , x + 50 , y + 35 , "red"
  #m "backcolor yellow"
  #m "goto " ; x ; " " ; y + 8
  #m "down"
  #m "\\ " ; nop$( n$ )
  #m "up"
end sub
sub drawrect x1 , y1 , x2 , y2 , kl$
  #m "backcolor " ; kl$
  #m "goto "; x1 ; " " ; y1
  #m "down"
  #m "boxfilled " ; x2 ; " " ; y2
  #m "up"
end sub
function nop$( n$ )
  nop$ = word$( n$ , 1 )
end function
function nx( n$ )
  nx = val( word$( n$ , 2 ) )
end function
function ny( n$ )
  ny = val( word$( n$ , 3 ) )
end function
function ngreen( n$ )
  ngreen = val( word$( n$ , 4 ) )
end function
function nblue( n$ )
  nblue = val( word$( n$ , 5 ) )
end function
[new]
  #m "fill white"
  for i = 0 to nodemax
    nd$( i ) = ""
  next i
  nodetel = 0
  file$ = ""
wait
[open]
  filedialog "load cirket" , "*.txt" , file$
  if file$ <> "" then
    open file$ for input as #in
      i = 0
      while not( eof( #in ) ) and i <= nodemax
        input #in , nd$( i )
        i = i + 1
      wend
    close #in
    loadbmp "cirket" , left$( file$ , len( file$ ) - 4 ) ; ".bmp"
    #m "background cirket"
  end if
wait
[save_as]
  filedialog "save cirket" , "*.txt" , file$
[save]
  if file$ <> "" then
    open file$ for output as #out
      for i = 0 to nodemax
        print #out , nd$( i )
      next i
    close #out
    #m "getbmp cirket 0 0 " ; winx ; " " ; winy
''    bmpsave left$( file$ , len( file$ ) - 4 ) ; ".bmp"
  end if
wait
[quit]
  close #m
end
[and]
  nodeselected$ = "and"
  state = drawand
wait
[or]
  nodeselected$ = "or"
  state = drawor
wait
[not]
  nodeselected$ = "not"
  state = drawnot
wait
[xor]
  nodeselected$ = "xor"
  state = drawxor
wait
[line]
  state = beginline + ioline
wait
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Keer terug naar Liberty BASIC Code

Wie is er online

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

cron