home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lisp / interpre / pclisp / turtle.l < prev   
Lisp/Scheme  |  1986-09-06  |  4KB  |  123 lines

  1. ;; TURTLE.L for PC-LISP.EXE V2.13
  2. ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. ;;    A set of rough turtle graphics primitives to demonstrate PC-LISP's BIOS 
  4. ;; graphics routines. These routines are pretty self explanitory. The first
  5. ;; 5 defun's define the primitives, next are a set of routines to draw things
  6. ;; like squares, triangles etc. Try the function (GraphicsDemo). It will
  7. ;; draw Squirals, Trianglerals, etc. Note that the BIOS line drawing is really
  8. ;; slow. This is because the BIOS 'set dot/pixel' routine is used for every
  9. ;; point in a line. Using the BIOS has the advantage however of portability,
  10. ;; these routines work on virtually every MS-DOS machine. The global variable
  11. ;; !Mode controls the graphics resolution that will be used. It is set by 
  12. ;; default to 6, I set it to 8 or 9 for my Tandy 2000. You can adjust the code
  13. ;; to support your machines higher resolution modes. More 640x400 modes can be
  14. ;; supported by (= !Mode NN) at ### PATCH POINT 1 ### where NN is the value
  15. ;; to pass to (#srcmde#) Ie the value to pass in AH when INT 10H is generated
  16. ;; with AL=0 (the BIOS Set CRT Mode call). If your machines has high resolution 
  17. ;; modes besides the 640x400 say X * Y resolution associated with mode NN then
  18. ;; add the following code at ### PATCH POINT 2 ### (where AA is X/2, BB is Y/2
  19. ;; CC is the ratio X/Y and DD is the number of pixels that should correspond
  20. ;; to one Turtle movement Unit):
  21. ;;
  22. ;;           ((= !Mode NN)                         
  23. ;;            (setq CenterX AA CenterY BB Scale CC Lfactor DD) 
  24. ;;            (TurtleCenter))  
  25. ;;
  26. ;;                      Peter Ashwood-Smith
  27. ;;                      August 22nd, 1986 
  28. ;;
  29.  
  30. (setq !Mode 6)                                         ; default setting
  31.  
  32. (defun TurtleGraphicsUp()           
  33.        (#scrmde# !Mode)(#scrsap# 0)      
  34.        (cond ((= !Mode 6)                              ; 640x200 B&W mode
  35.           (setq CenterX 100 CenterY 100 Scale 3.2 Lfactor 1) 
  36.           (TurtleCenter))  
  37. ;
  38.          ((= !Mode 7)
  39.           (patom '|mode 7 not allowed|))
  40. ;
  41.          ((or (= !Mode 8) (= !Mode 9)              ; Tandy 2000 640x400
  42.           (= !Mode 64)                         ; AT&T  6300 640x400?
  43.           ; ### PATCH POINT 1 ###
  44.           )  
  45.           (setq CenterX 266 CenterY 200 Scale 1.2 Lfactor 2) 
  46.           (TurtleCenter))  
  47. ;
  48. ;            ### PATCH POINT 2
  49. ;
  50.          (t (patom '|unsupported mode|))
  51.        )
  52. )   
  53.  
  54. (defun TurtleGraphicsDown()
  55.        (#scrmde# 2))
  56.  
  57. (defun TurtleCenter()    
  58.       (setq Lastx CenterX Lasty CenterY Heading 1.570796372))
  59.  
  60. (defun TurtleRight(n)   
  61.       (setq Heading (plus Heading (times n 0.01745329))))
  62.  
  63. (defun TurtleLeft(n)    
  64.       (setq Heading (diff Heading (times n 0.01745329))))
  65.  
  66. (defun TurtleGoTo(x y)  
  67.       (setq Lastx (quotient x Scale) Lasty (times y Lfactor) )) 
  68.  
  69. (defun TurtleForward(n) 
  70.       (setq n (times n Lfactor)
  71.         Newx (plus Lastx(times(cos Heading)n))
  72.         Newy (plus Lasty(times(sin Heading)n)))
  73.       (#scrline# (times Lastx Scale) Lasty (times Newx Scale) Newy 1)
  74.       (setq Lastx Newx Lasty Newy)
  75. )
  76.  
  77. ;
  78. ; end of Turtle Graphics primitives, start of Graphics demonstration code
  79. ; you can cut this out if you like and leave the Turtle primitives intact.
  80. ;
  81.  
  82. (defun Line_T(n)        
  83.     (TurtleForward n) (TurtleRight 180)
  84.     (TurtleForward (quotient n 4)) 
  85. )
  86.     
  87. (defun Square(n)
  88.     (TurtleForward n)  (TurtleRight 90)     
  89.     (TurtleForward n)  (TurtleRight 90)     
  90.     (TurtleForward n)  (TurtleRight 90)     
  91.     (TurtleForward n)                       
  92. )
  93.  
  94. (defun Triangle(n)
  95.     (TurtleForward n)  (TurtleRight 120)
  96.     (TurtleForward n)  (TurtleRight 120)
  97.     (TurtleForward n)
  98. )
  99.  
  100. (defun Make(ObjectFunc Size times skew) 
  101.       (prog()       
  102.        TOP:(cond ((zerop times) (return)))
  103.        (ObjectFunc Size) 
  104.        (TurtleRight skew)
  105.        (setq times (1- times))
  106.        (go TOP:)    
  107.        )
  108. )
  109.  
  110. (defun GraphicsDemo()
  111.        (TurtleGraphicsUp) 
  112.        (Make Square 40 18 5) (Make Square 60 18 5)
  113.        (gc)                                              ; idle work
  114.        (TurtleGraphicsUp) 
  115.        (Make Triangle 40 18 5) (Make Triangle 60 18 5)
  116.        (gc)                                              ; idle work
  117.        (TurtleGraphicsUp) 
  118.        (Make Line_T 80 50 10)
  119.        (gc)                                              ; idle work
  120.        (TurtleGraphicsDown)
  121. )
  122.  
  123.