PasteRack.org
Paste # 36388
2020-07-09 15:45:43

Fork as a new paste.

Paste viewed 180 times.


Embed:

lefty gradebook grid

  1. (require 2htdp/image lang/posn)
  2.  
  3. (define N-GRID-ROWS 42)
  4. (define N-RECTO-GRID-COLUMNS 17)
  5.  
  6. (define PX/PT 1)
  7.  
  8. ;; produces the number of pixels equivalent to n points
  9. (define (pt n) (* n PX/PT))
  10.  
  11.  
  12. (define CELL-W (pt 24))
  13. (define CELL-H (pt 24))
  14.  
  15. (define HEADER-ROW-H (pt 108))
  16.  ; how far the header line & number are rotated from horiz:
  17. (define HEADER-ROW-ANGLE 60)
  18. (define HEADER-LINE-LENGTH
  19.   (/ HEADER-ROW-H (sin (degrees->radians HEADER-ROW-ANGLE))))
  20.  
  21. (define HEADER-NUMERAL-SIZE (pt 9))
  22.  
  23. ;; Names column geometry
  24. (define NAMES-COLUMN-W (pt 72))
  25. (define NAMES-NUMERAL-SIZE (pt 8))
  26.  
  27. (define NAMES-ROW-ANGLE 30)
  28.  
  29. (define NAMES-COLUMN-LINE-LENGTH (/ NAMES-COLUMN-W (cos (degrees->radians NAMES-ROW-ANGLE))))
  30.  
  31. (define NAME-CELL-DIAGONAL-H
  32.   ;; vertical distance from bottom-left corner of a name cell to the right end of
  33.   ;; the bottom line of the cell
  34.   (* NAMES-COLUMN-LINE-LENGTH (sin (degrees->radians NAMES-ROW-ANGLE))))
  35. (define NAME-CELL-DIAGONAL-OVERLAP (- NAME-CELL-DIAGONAL-H CELL-H))
  36.  
  37. ;; Colors
  38.  
  39. (define GRID-BG-COLORS
  40.   ; lavenders
  41.   #;(list 'white
  42.         (make-color #xF0 #xE0 #xFF)
  43.         (make-color #xD0 #xC0 #xFF))
  44.   ; greens
  45.   (list 'white
  46.         (make-color #xF0 #xFF #xE0)
  47.         (make-color #xD0 #xFF #xC0)))
  48.  
  49. (define HEADER-LINE-COLOR 'forestgreen)
  50. (define GRID-LINE-COLOR (make-color 0 0 0 #x40))
  51. (define DARK-GRID-LINE-COLOR (make-color 0 0 0 #xA0))
  52. (define HEADER-NUMERAL-COLOR (make-color #x80 #x80 #x80 255))
  53. (define NAMES-NUMERAL-COLOR HEADER-NUMERAL-COLOR)
  54. (define HEADER-NUMERAL-OFFSET
  55.   (* CELL-W (cos (degrees->radians HEADER-ROW-ANGLE))))
  56.  
  57. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  58. ;; Pinhole helper
  59.  
  60. ;; x-place y-place Image -> Image
  61. ;; places a pinhole on img at the location specified by x-place and y-place
  62. (define (align-pinhole x-place y-place img)
  63.   (put-pinhole (x-place->coordinate x-place img)
  64.                (y-place->coordinate y-place img)
  65.                img))
  66.  
  67. ;; x-place Image -> (Option Nat)
  68. ;; produces the x-coordinate for the given x-place in the image, or
  69. ;; #f if x-place is 'pinhole and img has no pinhole.
  70. (define (x-place->coordinate x-place img)
  71.   (define place (if (symbol? x-place) x-place (string->symbol x-place)))
  72.   (case place
  73.     [(left) 0]
  74.     [(right)         (image-width img)]
  75.     [(middle center) (exact-round (/ (image-width img) 2))]
  76.     [(pinhole)       (pinhole-x img)]))
  77.  
  78. ;; y-place Image -> (Option Nat)
  79. ;; produces the y-coordinate for the given y-place in the image, or
  80. ;; #f if y-place is 'pinhole and img has no pinhole.
  81. (define (y-place->coordinate y-place img)
  82.   (define place (if (symbol? y-place) y-place (string->symbol y-place)))
  83.   (case place
  84.     [(top)           0]
  85.     [(bottom)        (image-height img)]
  86.     [(middle center) (exact-round (/ (image-height img) 2))]
  87.     [(baseline) (error "FIXME need to implement baseline")]
  88.     [(pinhole) (pinhole-y img)]))
  89.  
  90. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  91. ;; Making numbered slanted headers
  92.  
  93. ;; Int+ -> Image
  94. ;; makes n header cells side-by-side, numbered R-to-L from 1 to n,
  95. ;; with a pinhole at the right end of the bottom line
  96. (define (number-headers n)
  97.   (put-pinhole (* n CELL-W) HEADER-ROW-H
  98.                (for/fold ([result empty-image])
  99.                          ([i (in-range 1 (add1 n))])
  100.                  (overlay/align/offset 'left 'bottom
  101.                                        (number-header i)
  102.                                        CELL-W 0
  103.                                        result))))
  104.  
  105. ;; Int+ -> Image
  106. ;; makes a header cell containing the number i
  107. (define (number-header i)
  108.   (define lines
  109.     (overlay/align 'left 'top
  110.                    (rotate (- HEADER-ROW-ANGLE) (line CELL-W 0 HEADER-LINE-COLOR))
  111.                    (line HEADER-LINE-LENGTH 0 HEADER-LINE-COLOR)))
  112.   (rotate HEADER-ROW-ANGLE
  113.           (overlay/align/offset 'left 'middle  lines HEADER-NUMERAL-OFFSET 0
  114.                                 (numeral i HEADER-NUMERAL-COLOR HEADER-NUMERAL-SIZE))))
  115.  
  116. ;; Nat Color Int+ -> Image
  117. ;; make an image of the given numeral, given color & point size font
  118. (define (numeral n c size) (cell-text (number->string n) c size))
  119.  
  120. ;; String Color Int+ -> Image
  121. ;; make an image of the given text, color & point size font
  122. (define (cell-text s c size)
  123.   (text/font s size c "Concourse T3 Tab" 'default 'normal 'normal #f))
  124.  
  125. (define ASSIGNMENTS-TITLE
  126.   (rotate HEADER-ROW-ANGLE
  127.           (put-pinhole 0 0 (above/align 'right
  128.                                         (line HEADER-LINE-LENGTH 0 HEADER-LINE-COLOR)
  129.                                         (cell-text "Asg" HEADER-NUMERAL-COLOR 11)))))
  130.  
  131. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  132. ;; Names column
  133.  
  134. ;; Int+ -> Image
  135. ;; makes n right-sidebar name cells, stacked vertically, numbered 1 to n
  136. ;; with a pinhole @ TL corner of the top cell
  137. (define (name-cells n)
  138.   (put-pinhole 0 NAME-CELL-DIAGONAL-H
  139.                (for/fold ([result empty-image])
  140.                          ([i (in-range 1 (add1 n))]
  141.                           [c (in-cycle GRID-BG-COLORS)])
  142.                  (overlay/align/offset 'left 'bottom
  143.                                        result
  144.                                        0 CELL-H
  145.                                        (name-cell i c)))))
  146.  
  147. ;; Generate the page:
  148. (gradebook-recto 20 36)

=>

load-handler: expected a `module` declaration in "paste 36388", but found something else

Check that paste includes #lang?