-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawing.scm
78 lines (69 loc) · 2.73 KB
/
drawing.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
;;; This file is part of Adaptive Plot, a library for intelligently
;;; plotting functions from the MIT Scheme REPL.
;;; Copyright (C) 2010-2011 Alexey Radul
;;;
;;; Adaptive Plot is free software: you can redistribute it and/or
;;; modify it under the terms of the GNU Affero General Public License
;;; as published by the Free Software Foundation, either version 3 of
;;; the License, or (at your option) any later version.
;;;
;;; Adaptive Plot is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; Affero General Public License for more details.
;;;
;;; You should have received a copy of the GNU Affero General Public
;;; License along with Adaptive Plot. If not, see
;;; <http://www.gnu.org/licenses/>.
(declare (usual-integrations))
;;;; Drawing
;;; Creating, releasing, and maintaining live Scheme windows. The
;;; only really tricky thing here is making sure there are enough
;;; points in the plot to pick window boundaries from.
(define *scheme-plot-window-x-res* 1024)
(define *scheme-plot-window-y-res* 768)
(define (plot-drawing? plot)
(graphics-device? (plot-window plot)))
(define (plot-draw! plot)
(plot-stop-drawing! plot)
(plot-ensure-initialized! plot)
(receive (xlow xhigh ylow yhigh) (plot-dimensions plot)
(set-plot-window! plot
(new-plot-window xlow xhigh ylow yhigh
*scheme-plot-window-x-res*
*scheme-plot-window-y-res*))
(plot-sync-window! plot)))
(define (plot-stop-drawing! plot)
(if (plot-drawing? plot)
(graphics-close (plot-window plot)))
(set-plot-window! plot #f)
plot)
(define (plot-sync-window! plot)
(if (plot-drawing? plot)
(begin
(graphics-clear (plot-window plot))
(plot-ensure-initialized! plot)
(receive (xlow xhigh ylow yhigh) (plot-dimensions plot)
(graphics-set-coordinate-limits (plot-window plot) xlow ylow xhigh yhigh)
(graphics-set-clip-rectangle (plot-window plot) xlow ylow xhigh yhigh)
(let ((relevant-points (plot-relevant-points-alist plot)))
#;
(for-each
(lambda (x.y)
(%plot-point (plot-window plot) (car x.y) (cdr x.y)))
relevant-points)
(for-each
(lambda (x.y1 x.y2)
(%plot-line (plot-window plot)
(car x.y1) (cdr x.y1) (car x.y2) (cdr x.y2)))
relevant-points
(cdr relevant-points))))))
plot)
(define (plot-draw-point! plot x y)
(if (plot-drawing? plot)
(receive
(xlow xhigh ylow yhigh) (plot-dimensions plot)
(and (<= xlow y xhigh)
(<= ylow y yhigh)
(%plot-point (plot-window plot) x y))))
plot)