;;; Examples of sheets, samples, and scanners ;;; ================================================ ;;; Creating sheets ;;; ================================================ ;;; 1D manifolds (define man1a (make-manifold "a manifold" '(flat 1 (0 10)) '(flat 1 (0 200)) #t)) (define man1b (make-manifold "precise manifold" '(flat 1 (0 10)) '(flat 0.1 (-50 50)) #t)) (define man1c (make-manifold "circular manifold" '(circle 1 (0 10)) '(flat 0.1 (0 200)) #t)) ;;; 2D manifolds (define man2a (make-manifold "2D manifold" '(flat 1 (0 10) (-10 10)) '(flat 0.1 (0 200)) #t)) ;;; 1D grids (define grid1a (make-integer-grid "1D grid" '(flat 2 (0 10)) '(flat 1 (0 200)) #t)) ;;; 2D grids (define grid2a (make-integer-grid "2D grid" '(flat 2 (0 10) (20 50)) '(flat 1 (0 200)) #t)) (define grid2b (make-integer-grid "another 2D grid" '(flat 1 (0 100) (0 150)) '(flat 1 (0 200)) #f 50)) (define grid2c (make-real-grid "real grid" '(flat 2 (0 10) (20 50)) '(flat 1 (0 200)) #t)) ;;; ================================================= ;;; Using samples ;;; ================================================= (bulk-define get-sample ((integer-grid 2 1) integer integer) (integer-grid-sample 2 1) (lambda (g x y) (nearest-sample g x y))) (get-sample grid2a 2 6) ;;; Setting values in a 1D integer grid (bulk-define mung-sample ((integer-grid 1 1) integer integer) unspecified (lambda (g coord val) (sample-set! (nearest-sample g coord) val))) ;;; Similar, but for a 1D manifold (bulk-define mung-sample ((manifold 1 1) real real) unspecified (lambda (g coord val) (sample-set! (nearest-sample g coord) val))) ;;; Must handle scaling of locations in sheet (bulk-define test ((manifold 1 1) integer) real (lambda (x y) (sheet-ref x y))) ;;; Erase a spot around (x,y) (bulk-define erase-spot! ((manifold 2 1) real real) unspecified (lambda (man x y) (let ((center-sample (nearest-sample man x y))) (do ((i -5 (+ i 1))) ((> i 5)) (do ((j -5 (+ j 1))) ((> j 5)) (sample-erase! (shift-sample center-sample i j))))))) ;;; ================================================= ;;; 1D scanners ;;; ================================================= (bulk-define fill-sheet! ((manifold 1 1) real) unspecified (lambda (m val) (scan (s m) (sample-set! s val)))) (bulk-define increment-sheet! (manifold 1 1) unspecified (lambda (m) (scan (s m) (sample-set! s (+ 3 (sample-ref s)))))) (bulk-define copy-sheet! ((manifold 1 1) (manifold 1 1)) unspecified (lambda (m m2) (scan (s m2) (sample-set! s (sheet-ref m (sample->point s)))))) ;;; ================================================= ;;; 2D scanners ;;; ================================================= (bulk-define mung-value ((integer-grid 2 1) integer integer integer) unspecified (lambda (g x y v) (sample-set! (nearest-sample g x y) v))) (bulk-define fill-sheet! ((integer-grid 2 1) integer) unspecified (lambda (m val) (scan (s m) (sample-set! s val))))