home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / sourcecode / graphics / bresenham.amos / bresenham.amosSourceCode
AMOS Source Code  |  1991-07-30  |  2KB  |  131 lines

  1. '=============================================================== 
  2. '
  3. ' NAME: BRESENHAM.AMOS   
  4. ' TIME: 19:10
  5. ' DATE: 10/10/92 
  6. ' CODE: UNCLE SIME 
  7. ' NOTE: This is the standard technique used for plotting   
  8. '       lines between 2 points. To find out more get a 
  9. '       good book on graphics. Try compiling this as   
  10. '       it will give you a good idea how fast compiled           
  11. '       code is in comparison to interpreted code. Left  
  12. '       mouse button to quit.
  13. '        
  14. '
  15. ' THOUGHT FOT THE DAY: Anyone who cannot cope with mathematics 
  16. '                      is not fully human. At best he is a 
  17. '                      tolerable subhuman who has learned to 
  18. '                      wear shoes, bathe, and not make messes
  19. '                      in the house. 
  20. '
  21. '=============================================================== 
  22. '
  23. Close Workbench 
  24. Close Editor 
  25. Screen Close 0
  26. '
  27. Proc SETUP
  28. Proc MAIN
  29. End 
  30. '
  31. Procedure SETUP
  32. '
  33.   Screen Open 0,640,200,2,Hires
  34.   Flash Off 
  35.   Curs Off 
  36.   Hide On 
  37.   Cls 0
  38.   Palette $0,$FFF
  39.   Ink 1
  40.   Paper 0
  41. End Proc
  42. '
  43. Procedure MAIN
  44.   '
  45.   ' Setup required variables 
  46.   '
  47.   Repeat 
  48.     Cls 0
  49.     Locate 0,0
  50.     Input "ENTER X1 ";X1
  51.   Until X1>=0 and X1<=640
  52.   '
  53.   Repeat 
  54.     Cls 0
  55.     Locate 0,0
  56.     Input "ENTER Y1 ";Y1
  57.   Until Y1>=0 and Y1<=200
  58.   '
  59.   Repeat 
  60.     Cls 0
  61.     Locate 0,0
  62.     Input "ENTER X2 ";X2
  63.   Until X2>=0 and X2<=640
  64.   '
  65.   Repeat 
  66.     Cls 0
  67.     Locate 0,0
  68.     Input "ENTER Y2 ";Y2
  69.   Until Y2>=0 and Y2<=200
  70.   '
  71.   Cls 0
  72.   '
  73.   DX=(X2-X1)
  74.   DY=(Y2-Y1)
  75.   IX=Abs(DX)
  76.   IY=Abs(DY)
  77.   '
  78.   If DX>DY
  79.     _INC=DX
  80.   Else 
  81.     _INC=DY
  82.   End If 
  83.   '
  84.   _PLOTX=X1
  85.   _PLOTY=Y1
  86.   '
  87.   X=0 : Y=0 : _PLOT=False
  88.   '
  89.   ' The meat of the algorithm starts here  
  90.   '
  91.   Plot _PLOTX,_PLOTY
  92.   '
  93.   For LOP=0 To _INC
  94.     Add X,IX
  95.     Add Y,IY
  96.     _PLOT=False
  97.     '
  98.     If X>_INC
  99.       _PLOT=True
  100.       X=X-_INC
  101.       '  
  102.       If DX>0
  103.         Inc _PLOTX
  104.       Else 
  105.         Dec _PLOTX
  106.       End If 
  107.     '  
  108.     End If 
  109.     '
  110.     If Y>_INC
  111.       _PLOT=True
  112.       Y=Y-_INC
  113.       '
  114.       If DY>0
  115.         Inc _PLOTY
  116.       Else 
  117.         Dec _PLOTY
  118.       End If 
  119.     '
  120.     End If 
  121.     '  
  122.     If _PLOT
  123.       Plot _PLOTX,_PLOTY
  124.     End If 
  125.     '
  126.   Next LOP
  127.   Repeat 
  128.     '
  129.   Until Mouse Key=1
  130.   Cls 0
  131. End Proc