home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / compiler / sample7.bas < prev    next >
BASIC Source File  |  1993-11-14  |  4KB  |  216 lines

  1.  
  2.  
  3. rem
  4. rem This program demonstrates some simple graphics techniques
  5. rem
  6. rem This program runs under DOS or Windows
  7. rem
  8. rem
  9.  
  10.  
  11.   rem
  12.   rem place to store graphics figures with GET statement
  13.   rem
  14.  
  15.   dim figure(100)
  16.  
  17.  
  18.   rem
  19.   rem go into graphics mode
  20.   rem
  21.  
  22.   seterrlevel 5
  23.   err=0
  24.   screen 12
  25.   if err>0 then
  26.     screen 2
  27.     if err>0 then
  28.       print "Graphics mode not available."
  29.     end if
  30.   end if
  31.   seterrlevel 7
  32.  
  33.  
  34.   rem
  35.   rem Set some variables
  36.   rem
  37.  
  38.    firstbit=1
  39.    charxsize=font(7)
  40.    charysize=font(1)
  41.  
  42.    topy=system(2)
  43.    topx=system(1)
  44.  
  45.    topcolor=15
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.   rem
  53.   REM
  54.   REM LAYOUT SCREEN
  55.   REM
  56.   CLS
  57.  
  58.   line (0,0)-(topx-1,charysize*5+2),4,bf
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.          rem
  66.          rem circle demo
  67.          rem
  68.  
  69.          gosub cleararea
  70.          x=topx/2
  71.          y=(topy+(charysize*6))/2
  72.          circle (x,y),topx/6,topcolor
  73.          gosub delay
  74.          paint (x,y),1,topcolor
  75.  
  76.  
  77.  
  78.  
  79.          rem
  80.          rem square demo
  81.          rem
  82.  
  83.          gosub cleararea
  84.          for i%=1 to 10
  85.             x1=int(200*rnd)
  86.             x1=x1+topx/2-100
  87.             y1=int(100*rnd)
  88.             y1=y1+(topy+(charysize*6))/2-50
  89.             x2=int(200*rnd)
  90.             x2=x2+topx/2-100
  91.             y2=int(100*rnd)
  92.             y2=y2+(topy+(charysize*6))/2-50
  93.             c=int(15*rnd)
  94.             if i%=3 or i%=5 then
  95.               line (x1,y1)-(x2,y2),c,BF
  96.             else
  97.               line (x1,y1)-(x2,y2),c,B
  98.             end if
  99.          next i%
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.          rem
  107.          rem pie demo
  108.          rem It is the CIRCLE command that supports drawing of pie shaped areas
  109.          rem
  110.  
  111.          gosub cleararea
  112.          x=topx/2
  113.          y=(topy+(charysize*6))/2
  114.          circle (x,y),topx/6,topcolor,-1,-3
  115.          gosub delay
  116.          paint (x-4,y-4),1,topcolor
  117.          gosub delay
  118.          circle (x,y),topx/6,topcolor,-3,-5
  119.          gosub delay
  120.          paint (x-12,y+2),4,topcolor
  121.          gosub delay
  122.          circle (x,y),topx/6,topcolor,-5,-1
  123.          gosub delay
  124.          paint (x+12,y+5),2,topcolor
  125.  
  126.  
  127.  
  128.          rem
  129.          rem line demo
  130.          rem
  131.  
  132.          gosub cleararea
  133.          for i%=1 to 300
  134.             x1=int(200*rnd)
  135.             x1=x1+topx/2-100
  136.             y1=int(100*rnd)
  137.             y1=y1+(topy+(charysize*6))/2-50
  138.             x2=int(200*rnd)
  139.             x2=x2+topx/2-100
  140.             y2=int(100*rnd)
  141.             y2=y2+(topy+(charysize*6))/2-50
  142.             c=int(15*rnd)
  143.             line (x1,y1)-(x2,y2),c
  144.          next i%
  145.  
  146.  
  147.  
  148.  
  149.          rem
  150.          rem dot demo
  151.          rem
  152.  
  153.          gosub cleararea
  154.          for i%=1 to 300
  155.             x=int(200*rnd)
  156.             x=x+topx/2-100
  157.             y=int(100*rnd)
  158.             y=y+(topy+(charysize*6))/2-50
  159.             c=int(15*rnd)
  160.             pset (x,y),c
  161.          next i%
  162.  
  163.  
  164.          rem
  165.          rem motion demo
  166.          rem
  167.          gosub cleararea
  168.          x=topx/2
  169.          y=(topy+(charysize*6))/2
  170.          circle (x,y),10,topcolor
  171.          circle (x,y),4,topcolor-1
  172.          get (x-10,y-10)-(x+10,y+10),figure(0)
  173.          gosub cleararea
  174.          for ix=0 to topx step 10
  175.            line (ix,charysize*7)-(ix,topy),topcolor
  176.          next ix
  177.          oldix=9999
  178.          for ix=0 to topx-20 step 2
  179.            put (ix,y),figure(0),XOR
  180.            if oldix<9999 then
  181.              put (oldix,y),figure,XOR
  182.            end if
  183.            oldix=ix
  184.            for i=1 to 30:next i
  185.          next ix
  186.  
  187. cls
  188. stop
  189.  
  190.  
  191.  
  192.  
  193. rem
  194. rem delay 1/2 second
  195. rem
  196.  
  197. delay:
  198.      t=timer
  199. delay5:
  200.      if timer-t<.5 then goto delay5
  201.      return
  202.  
  203.  
  204.  
  205.  
  206. rem
  207. rem erase display area
  208. rem
  209.  
  210. cleararea:
  211.  
  212.      by=charysize*6
  213.      line (0,by)-(topx,topy),0,bf
  214.      return
  215.  
  216.