home *** CD-ROM | disk | FTP | other *** search
- ;;; -*- Scheme -*-
-
- #|
-
- Copyright (c) 1986-91 Massachusetts Institute of Technology
-
- This material was developed by the Scheme project at the Massachusetts
- Institute of Technology, Department of Electrical Engineering and
- Computer Science. Permission to copy this software, to redistribute
- it, and to use it for any purpose is granted, subject to the following
- restrictions and understandings.
-
- 1. Any copy made of this software must include this copyright notice
- in full.
-
- 2. Users of this software agree to make their best efforts (a) to
- return to the MIT Scheme project any improvements or extensions that
- they make, so that these may be included in future releases; and (b)
- to inform MIT of noteworthy uses of this software.
-
- 3. All materials developed as a consequence of the use of this
- software shall duly acknowledge such use, in accordance with the usual
- standards of acknowledging credit in academic research.
-
- 4. MIT has made no warrantee or representation that the operation of
- this software will be error-free, and MIT is under no obligation to
- provide any services, by way of maintenance, update, or otherwise.
-
- 5. In conjunction with products arising from the use of this material,
- there shall be no use of the name of the Massachusetts Institute of
- Technology nor of any adaptation thereof in any advertising,
- promotional, or sales literature without prior written consent from
- MIT in each case.
-
- |#
-
- ;;;; System dependent stuff for box and pointer diagram printer.
- ;; Chipmunk (MIT Student Scheme) compatibility file.
-
- (define chipmunk-screen
- ;; These are the Chipmunk screen parameters
- (make-rect (make-vect -250 -190)
- (make-vect 500 0)
- (make-vect 0 380)))
-
- #|
- (define bobcat-screen
- ;; These are the Gator/Bobcat screen parameters
- (make-rect (make-vect -500 -380)
- (make-vect 1000 0)
- (make-vect 0 760)))
- |#
-
- (define screen chipmunk-screen)
-
- (define (drawline start-point end-point)
- (position-pen (xcor start-point)
- (ycor start-point))
- (draw-line-to (xcor end-point)
- (ycor end-point)))
-
- ;; clear-graphics is predefined.
-
- (define (draw pict)
- (clear-graphics)
- (pict screen))
-
- (define draw-permanent draw)
-
- ;;; Other dialect dependencies:
-
- (define double-quote-string "\"")
-
- (define string?
- (access string? '()))
-
- (define symbol->string
- (access symbol-print-name '()))
-
- (define string-append
- (access string-append '()))
-
- (define substring
- (access substring '()))
-
- (define number->string
- (let ((prin1-to-string (access write-to-string '())))
- (lambda (x format)
- ;; format is ignored
- (prin1-to-string x))))
-
- ;;; text-picture:
-
- (define character-width 10)
- (define character-height 14)
- (define maximum-number-of-characters 8)
- (define string-truncation-marker #\#)
-
- (define (sign x)
- (if (< x 0) -1 1))
-
- ;; All rectangles given to the result of text-picture
- ;; are the same size for any given show operation.
- ;; Thus, although each invocation recomputes the current
- ;; font size, they should all come out the same.
-
- (define (text-picture string)
- (lambda (rect)
- (let* ((len (string-length string))
- (rwidth (abs (round (xcor (horiz rect)))))
- (rheight (abs (round (ycor (vert rect))))))
- (define (draw-string charwidth height)
- (let ((nchars (floor (/ rwidth charwidth))))
- (if (or (< rheight height)
- (< nchars 1)
- (and (= nchars 1)
- (not (= len 1))))
- (default-text-picture rect)
- (let ((nstring
- (if (>= nchars len)
- string
- (string-append
- (substring string 0 (- nchars 1))
- (make-string 1
- string-truncation-marker)))))
- (let ((signx (sign (xcor (horiz rect))))
- (signy (sign (ycor (vert rect))))
- (width (* charwidth (string-length nstring))))
- ((string->picture nstring)
- (make-rect
- (+vect (origin rect)
- (scale .5
- (make-vect (* signx (- rwidth width))
- (* signy (- rheight height)))))
- (make-vect (* signx width) 0)
- (make-vect 0 (* signy height)))))))))
- (if (< (floor (/ rwidth character-width)) maximum-number-of-characters)
- (draw-string character-width character-height)
- (let* ((dw (floor (/ rwidth maximum-number-of-characters)))
- (dh (round (/ (* dw character-height) character-width))))
- (if (< dh rheight)
- (draw-string dw dh)
- (draw-string (floor (/ (* rheight character-width)
- character-width))
- rheight)))))))
-
- ;;;; String->picture
-
- (define empty-picture (make-picture '()))
-
- (define (string->picture string)
- (let ((n (string-length string)))
- (define (loop m pic)
- (if (= n m)
- pic
- (loop (1+ m)
- (beside pic
- (character-picture (string-ref string m))
- (/ m (1+ m))))))
- (loop 0 empty-picture)))
-
- ;;; Character pictures
-
- (define character-pictures '())
-
- (define (add-character-picture! character picture)
- (let ((place (assq character character-pictures)))
- (sequence
- (if (null? place)
- (set! character-pictures
- (cons (cons character picture)
- character-pictures))
- (set-cdr! place picture))
- 'DONE)))
-
- (define (character-picture character)
- (let ((place (assq character character-pictures)))
- (if (null? place)
- default-character-picture
- (cdr place))))
-
- (define (mpict all)
- (make-picture
- (mapcar (lambda (seg-desc)
- (make-segment (apply make-vect (car seg-desc))
- (apply make-vect (cadr seg-desc))))
- all)))
-
- (define (mline all)
- (define (duplicate all)
- (if (null? (cdr all))
- '()
- (cons (list (car all) (cadr all))
- (duplicate (cdr all)))))
- (mpict (duplicate all)))
-
- ;;; Computer Terrible Font, by Jinx
-
- (define left .15)
- (define middle .5)
- (define right (- 1 left))
- (define bottom .15)
- (define top (- 1 bottom))
- (define ml .35)
- (define mr (- 1 ml))
- (define mb .35)
- (define mt (- 1 mb))
-
- (define default-character-picture ; A boxed asterisk
- (mpict `(((,left ,bottom) (,right ,top))
- ((,right ,bottom) (,left ,top))
- ((,middle ,bottom) (,middle ,top))
- ((,left ,middle) (,right ,middle))
- ((,left ,top) (,left ,bottom))
- ((,left ,bottom) (,right ,bottom))
- ((,right ,bottom) (,right ,top))
- ((,right ,top) (,left ,top)))))
-
- ;;; Punctuation and spacing
-
- (add-character-picture!
- #\Space (mpict '()))
-
- (add-character-picture!
- #\@
- (mpict `(((,right ,bottom) (,left ,bottom))
- ((,left ,bottom) (,left ,top))
- ((,left ,top) (,right ,top))
- ((,right ,top) (,right ,middle))
- ((,right ,middle) (,middle ,middle))
- ((,middle ,middle) (,middle ,top)))))
-
- (add-character-picture!
- #\#
- (mpict `(((,mr ,top) (,mr ,bottom))
- ((,ml ,top) (,ml ,bottom))
- ((,left ,mt) (,right ,mt))
- ((,left ,mb) (,right ,mb)))))
-
- (add-character-picture!
- #\"
- (mpict `(((,mr ,top) (,mr ,mt))
- ((,ml ,top) (,ml ,mt)))))
-
- (add-character-picture!
- #\.
- (mpict `(((,middle ,middle) (,middle ,middle)))))
-
- (add-character-picture!
- #\+
- (mpict `(((,left ,middle) (,right ,middle))
- ((,middle ,top) (,middle ,bottom)))))
-
- (add-character-picture!
- #\-
- (mpict `(((,left ,middle) (,right ,middle)))))
-
- (add-character-picture!
- #\*
- (mpict `(((,left ,middle) (,right ,middle))
- ((,middle ,top) (,middle ,bottom))
- ((,right ,top) (,left ,bottom))
- ((,left ,top) (,right ,bottom)))))
-
- (add-character-picture!
- #\/
- (mpict `(((,left ,bottom) (,right ,top)))))
-
- (add-character-picture!
- #\\
- (mpict `(((,right ,bottom) (,left ,top)))))
-
- (add-character-picture!
- #\=
- (mpict `(((,left ,middle) (,right ,middle))
- ((,left ,bottom) (,right ,bottom)))))
-
- (add-character-picture!
- #\!
- (mpict `(((,middle ,top) (,middle ,middle))
- ((,middle ,bottom) (,middle ,bottom)))))
-
- (add-character-picture!
- #\$
- (mpict `(((,left ,bottom) (,right ,bottom))
- ((,right ,bottom) (,right ,middle))
- ((,right ,middle) (,left ,middle))
- ((,left ,middle) (,left ,top))
- ((,left ,top) (,right ,top))
- ((,middle ,top) (,middle ,bottom)))))
-
- ;;; Digits
-
- (add-character-picture!
- #\0
- (mline `((,mr ,top)
- (,right ,mt)
- (,right ,mb)
- (,mr ,bottom)
- (,ml ,bottom)
- (,left ,mb)
- (,left ,mt)
- (,ml ,top)
- (,mr ,top)
- (,ml ,bottom))))
-
- (add-character-picture!
- #\1
- (mpict `(((,ml ,bottom) (,right ,bottom))
- ((,mr ,bottom) (,mr ,top))
- ((,ml ,mt) (,mr ,top)))))
-
- (add-character-picture!
- #\2
- (mline `((,left ,mt)
- (,ml ,top)
- (,mr ,top)
- (,right ,mt)
- (,left ,bottom)
- (,right ,bottom)
- (,right ,mb))))
-
- (add-character-picture!
- #\3
- (mline `((,left ,top)
- (,right ,top)
- (,middle ,middle)
- (,mr ,middle)
- (,right ,mb)
- (,mr ,bottom)
- (,ml ,bottom)
- (,left ,mb))))
-
- (add-character-picture!
- #\4
- (mline `((,mr ,bottom)
- (,mr ,top)
- (,left ,middle)
- (,right ,middle))))
-
- (add-character-picture!
- #\5
- (mline `((,right ,top)
- (,left ,top)
- (,left ,middle)
- (,middle ,mt)
- (,right ,middle)
- (,right ,mb)
- (,middle ,bottom)
- (,left ,mb))))
-
- (add-character-picture!
- #\6
- (mpict `(((,right ,top) (,left ,top))
- ((,left ,top) (,left ,bottom))
- ((,left ,bottom) (,right ,bottom))
- ((,right ,bottom) (,right ,middle))
- ((,right ,middle) (,left ,middle)))))
-
- (add-character-picture!
- #\7
- (mpict `(((,left ,top) (,right ,top))
- ((,right ,top) (,ml ,bottom))
- ((,ml ,middle) (,mr ,middle)))))
-
- (add-character-picture!
- #\8
- (mpict `(((,left ,top) (,right ,top))
- ((,right ,top) (,right ,bottom))
- ((,right ,bottom) (,left ,bottom))
- ((,left ,bottom) (,left ,top))
- ((,left ,middle) (,right ,middle)))))
-
- (add-character-picture!
- #\9
- (mpict `(((,right ,bottom) (,right ,top))
- ((,right ,top) (,left ,top))
- ((,left ,top) (,left ,middle))
- ((,left ,middle) (,right ,middle)))))
-
- ;;; Upper case alphabetic characters
-
- (add-character-picture!
- #\A
- (mpict `(((,left ,bottom) (,right ,top))
- ((,right ,top) (,right ,bottom))
- ((,middle ,middle) (,right ,middle)))))
-
- (add-character-picture!
- #\B
- (mline `((,mr ,middle)
- (,right ,mt)
- (,mr ,top)
- (,left ,top)
- (,left ,bottom)
- (,mr ,bottom)
- (,right ,mb)
- (,mr ,middle)
- (,left ,middle))))
-
- (add-character-picture!
- #\C
- (mline `((,right ,mb)
- (,mr ,bottom)
- (,ml ,bottom)
- (,left ,mb)
- (,left ,mt)
- (,ml ,top)
- (,mr ,top)
- (,right ,mt))))
-
- (add-character-picture!
- #\D
- (mline `((,right ,mt)
- (,middle ,top)
- (,left ,top)
- (,left ,bottom)
- (,middle ,bottom)
- (,right ,mb)
- (,right ,mt))))
-
- (add-character-picture!
- #\E
- (mpict `(((,right ,top) (,left ,top))
- ((,left ,top) (,left ,bottom))
- ((,left ,bottom) (,right ,bottom))
- ((,left ,middle) (,right ,middle)))))
-
- (add-character-picture!
- #\F
- (mpict `(((,right ,top) (,left ,top))
- ((,left ,top) (,left ,bottom))
- ((,left ,middle) (,right ,middle)))))
-
- (add-character-picture!
- #\G
- (mpict `(((,right ,top) (,left ,top))
- ((,left ,top) (,left ,bottom))
- ((,left ,bottom) (,right ,bottom))
- ((,right ,bottom) (,right ,middle))
- ((,right ,middle) (,middle ,middle)))))
-
- (add-character-picture!
- #\H
- (mpict `(((,left ,top) (,left ,bottom))
- ((,right ,top) (,right ,bottom))
- ((,left ,middle) (,right ,middle)))))
-
- (add-character-picture!
- #\I
- (mpict `(((,left ,top) (,right ,top))
- ((,middle ,top) (,middle ,bottom))
- ((,left ,bottom) (,right ,bottom)))))
-
- (add-character-picture!
- #\J
- (mline `((,ml ,mt)
- (,ml ,top)
- (,right ,top)
- (,right ,mb)
- (,mr ,bottom)
- (,ml ,bottom)
- (,left ,mb))))
-
- (add-character-picture!
- #\K
- (mpict `(((,left ,top) (,left ,bottom))
- ((,left ,middle) (,right ,top))
- ((,left ,middle) (,right ,bottom)))))
-
- (add-character-picture!
- #\L
- (mpict `(((,left ,top) (,left ,bottom))
- ((,left ,bottom) (,right ,bottom)))))
-
- (add-character-picture!
- #\M
- (mpict `(((,left ,bottom) (,left ,top))
- ((,left ,top) (,middle ,middle))
- ((,middle ,middle) (,right ,top))
- ((,right ,top) (,right ,bottom)))))
-
- (add-character-picture!
- #\N
- (mpict `(((,left ,bottom) (,left ,top))
- ((,left ,top) (,right ,bottom))
- ((,right ,bottom) (,right ,top)))))
-
- (add-character-picture!
- #\O
- (mline `((,mr ,top)
- (,right ,mt)
- (,right ,mb)
- (,mr ,bottom)
- (,ml ,bottom)
- (,left ,mb)
- (,left ,mt)
- (,ml ,top)
- (,mr ,top))))
-
- (add-character-picture!
- #\P
- (mpict `(((,left ,bottom) (,left ,top))
- ((,left ,top) (,right ,top))
- ((,right ,top) (,right ,middle))
- ((,right ,middle) (,left ,middle)))))
-
- (add-character-picture!
- #\Q
- (mpict `(((,mr ,top) (,right ,mt))
- ((,right ,mt) (,right ,mb))
- ((,right ,mb) (,mr ,bottom))
- ((,mr ,bottom) (,ml ,bottom))
- ((,ml ,bottom) (,left ,mb))
- ((,left ,mb) (,left ,mt))
- ((,left ,mt) (,ml ,top))
- ((,ml ,top) (,mr ,top))
- ((,middle ,middle) (,right ,bottom)))))
-
- (add-character-picture!
- #\R
- (mpict `(((,left ,bottom) (,left ,top))
- ((,left ,top) (,right ,top))
- ((,right ,top) (,right ,middle))
- ((,right ,middle) (,left ,middle))
- ((,middle ,middle) (,right ,bottom)))))
-
- (add-character-picture!
- #\S
- (mline `((,right ,mt)
- (,mr ,top)
- (,ml ,top)
- (,left ,mt)
- (,right ,mb)
- (,mr ,bottom)
- (,ml ,bottom)
- (,left ,mb))))
-
- (add-character-picture!
- #\T
- (mpict `(((,left ,top) (,right ,top))
- ((,middle ,top) (,middle ,bottom)))))
-
- (add-character-picture!
- #\U
- (mline `((,left ,top)
- (,left ,mb)
- (,ml ,bottom)
- (,mr ,bottom)
- (,right ,mb)
- (,right ,top))))
-
- (add-character-picture!
- #\V
- (mpict `(((,left ,top) (,middle ,bottom))
- ((,middle ,bottom) (,right ,top)))))
-
- (add-character-picture!
- #\W
- (mpict `(((,left ,top) (,left ,bottom))
- ((,left ,bottom) (,middle ,middle))
- ((,middle ,middle) (,right ,bottom))
- ((,right ,bottom) (,right ,top)))))
-
- (add-character-picture!
- #\X
- (mpict `(((,left ,top) (,right ,bottom))
- ((,right ,top) (,left ,bottom)))))
-
- (add-character-picture!
- #\Y
- (mpict `(((,left ,top) (,middle ,middle))
- ((,right ,top) (,middle ,middle))
- ((,middle ,middle) (,middle ,bottom)))))
-
- (add-character-picture!
- #\Z
- (mpict `(((,left ,top) (,right ,top))
- ((,right ,top) (,left ,bottom))
- ((,left ,bottom) (,right ,bottom)))))