home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / gjr / boxes.lha / cscheme.scm < prev    next >
Encoding:
Text File  |  1991-10-02  |  3.6 KB  |  118 lines

  1. ;;; -*- Scheme -*-
  2.  
  3. #|
  4.  
  5. Copyright (c) 1991 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case.
  34.  
  35. |#
  36.  
  37. (declare (usual-integrations)
  38.      (integrate-external "squares"))
  39.  
  40. ;;;; System dependent stuff for box and pointer diagram printer.
  41. ;;;  MIT CScheme version 7.1 (using X).
  42.  
  43. (define box&pointer-window)
  44.  
  45. (define screen)
  46.  
  47. (define character-width 6)
  48. (define character-height 10)
  49.  
  50. (define (initialize-graphics)
  51.   (set! box&pointer-window
  52.     (make-graphics-device x-graphics-device-type
  53.                   (x-open-display false)
  54.                   false))
  55.   (with-values
  56.       (lambda () (graphics-device-coordinate-limits box&pointer-window))
  57.     (lambda (x-left y-bottom x-right y-top)
  58.       ;; In X top is lower than bottom, switch for this program.
  59.       (graphics-set-coordinate-limits box&pointer-window
  60.                       x-left y-top x-right y-bottom)
  61.       (set! screen
  62.         (make-rect (make-vect x-left y-top)
  63.                (make-vect (- x-right x-left) 0)
  64.                (make-vect 0 (- y-bottom y-top))))))
  65.   (graphics-operation box&pointer-window 'set-font
  66.               (string-append (number->string character-width)
  67.                      "x"
  68.                      (number->string character-height)))
  69.   'done)
  70.  
  71. (define (drawline start-point end-point)
  72.   (graphics-draw-line box&pointer-window
  73.               (exact->inexact (xcor start-point))
  74.               (exact->inexact (ycor start-point))
  75.               (exact->inexact (xcor end-point))
  76.               (exact->inexact (ycor end-point))))
  77.  
  78. (define (sign x)
  79.   (if (< x 0)
  80.       -1
  81.       1))
  82.  
  83. (define (text-picture string)
  84.   (let ((width (* character-width (string-length string)))
  85.     (height character-height))
  86.     (lambda (rectangle)
  87.       (let ((rwidth (abs (xcor (horiz rectangle))))
  88.             (rheight (abs (ycor (vert rectangle)))))
  89.         (if (or (< rwidth width) (< rheight height))
  90.         (default-text-picture rectangle)
  91.         (graphics-draw-text box&pointer-window
  92.                 (exact->inexact
  93.                  (+ (xcor (origin rectangle))
  94.                     (* (sign (xcor (horiz rectangle)))
  95.                        (/ (- rwidth width) 2))))
  96.                 (exact->inexact
  97.                  (+ (ycor (origin rectangle))
  98.                     (* (sign (ycor (vert rectangle)))
  99.                        (/ (- rheight height) 2))))
  100.                 string))))))
  101.  
  102. (define (clear-graphics)
  103.   (graphics-clear box&pointer-window))
  104.   
  105. (define (draw picture)
  106.   (clear-graphics)
  107.   (picture screen))
  108.  
  109. (define draw-permanent draw)
  110.  
  111. ;;;; Dialect dependencies
  112.  
  113. (define (atom? x)
  114.   (not (pair? x)))
  115.  
  116. (define mapc for-each)
  117.  
  118. (define mapcar map)