plot tests adjusted and passed

svn: r9769
This commit is contained in:
Eli Barzilay 2008-05-09 16:12:30 +00:00
parent 8be65ec594
commit ed0974616b
21 changed files with 188 additions and 236 deletions

View File

@ -61,12 +61,12 @@
1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0" 1 0 32 #"(lib \"text-snipclass.ss\" \"xml\")\0"
1 0 15 #"test-case-box%\0" 1 0 15 #"test-case-box%\0"
2 0 1 6 #"wxloc\0" 2 0 1 6 #"wxloc\0"
00000000000 1 75 0 1 #"\0" 00000000000 1 77 0 1 #"\0"
0 75 1 #"\0" 0 75 1 #"\0"
0 11 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9 0 11 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 9
#"Standard\0" #"Standard\0"
0 75 11 #" Monospace\0" 0 75 11 #" Monospace\0"
0 11 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1 0 14 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 2 1
#"\0" #"\0"
0 -1 1 #"\0" 0 -1 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24 1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 2 24
@ -198,7 +198,22 @@
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24 1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 8 24
#"drscheme:text:ports err\0" #"drscheme:text:ports err\0"
0 -1 1 #"\0" 0 -1 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 0 1 1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 4 1
#"\0"
0 71 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 4 1
#"\0"
0 -1 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 255 0 0 0 -1 -1 4 1
#"\0"
0 71 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 255 0 0 0 -1 -1 4 1
#"\0"
0 71 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 100 0 0 0 0 -1 -1 0 1
#"\0"
0 75 11 #" Monospace\0"
0 11 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 1
#"\0" #"\0"
0 75 1 #"\0" 0 75 1 #"\0"
0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 1 0 12 90 -1 90 -1 3 -1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 255 255 255 1 -1 0 1
@ -270,34 +285,16 @@
1 0 -1 -1 94 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1 1 0 -1 -1 94 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 255 0 0 0 0 0 -1 -1 2 1
#"\0" #"\0"
0 -1 1 #"\0" 0 -1 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 200 0 0 0 0 0 -1 -1 4 1 1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 200 0 0 0 0 0 -1 -1 0 1
#"\0"
0 71 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 -1 -1 4 1
#"\0" #"\0"
0 -1 1 #"\0" 0 -1 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 255 0 0 0 -1 -1 4 1 1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 200 0 0 0 0 0 -1 -1
#"\0" 00000000002 0 00000000000 3 00000000000 125 0 26 3 12 #"#lang scheme"
0 71 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 255 0 0 0 -1 -1 4 1
#"\0"
0 71 1 #"\0"
1 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 1 1 1 0 100 0 0 0 0 -1 -1
00000000002 0 00000000000 3 00000000000 159 0 22 3 1 #"("
0 0 14 3 7 #"require"
0 0 4 3 1 #" "
0 0 22 3 1 #"("
0 0 14 3 3 #"lib"
0 0 4 3 1 #" "
0 0 19 3 9 #"\"plot.ss\""
0 0 4 3 1 #" "
0 0 19 3 6 #"\"plot\""
0 0 22 3 2 #"))"
0 0 4 29 1 #"\n" 0 0 4 29 1 #"\n"
0 0 22 3 1 #"(" 0 0 22 3 1 #"("
0 0 14 3 7 #"require" 0 0 14 3 7 #"require"
0 0 4 3 1 #" " 0 0 4 3 1 #" "
0 0 14 3 9 #"mzlib/etc" 0 0 14 3 4 #"plot"
0 0 22 3 1 #")" 0 0 22 3 1 #")"
0 0 4 29 1 #"\n" 0 0 4 29 1 #"\n"
0 0 4 29 1 #"\n" 0 0 4 29 1 #"\n"
@ -332,6 +329,9 @@
0 0 14 3 1 #"x" 0 0 14 3 1 #"x"
0 0 22 3 3 #")))" 0 0 22 3 3 #")))"
0 0 4 3 1 #" " 0 0 4 3 1 #" "
0 0 17 3 25 #"; a random list of points"
0 0 4 29 1 #"\n"
0 0 4 3 7 #" "
0 0 22 3 1 #"(" 0 0 22 3 1 #"("
0 0 14 3 10 #"build-list" 0 0 14 3 10 #"build-list"
0 0 4 3 1 #" " 0 0 4 3 1 #" "
@ -349,43 +349,18 @@
0 0 4 3 1 #" " 0 0 4 3 1 #" "
0 0 14 3 1 #"x" 0 0 14 3 1 #"x"
0 0 22 3 5 #")))))" 0 0 22 3 5 #")))))"
0 0 4 3 1 #" "
0 0 17 3 1 #";"
0 0 17 3 1 #" "
0 0 17 3 1 #"a"
0 0 17 3 1 #" "
0 0 17 3 1 #"r"
0 0 17 3 1 #"a"
0 0 17 3 1 #"n"
0 0 17 3 1 #"d"
0 0 17 3 1 #"o"
0 0 17 3 1 #"m"
0 0 17 3 1 #" "
0 0 17 3 1 #"l"
0 0 17 3 1 #"i"
0 0 17 3 1 #"s"
0 0 17 3 1 #"t"
0 0 17 3 1 #" "
0 0 17 3 1 #"o"
0 0 17 3 1 #"f"
0 0 17 3 1 #" "
0 0 17 3 1 #"p"
0 0 17 3 1 #"o"
0 0 17 3 1 #"i"
0 0 17 3 3 #"nts"
0 0 4 29 1 #"\n" 0 0 4 29 1 #"\n"
0 0 4 3 1 #" " 0 0 4 3 1 #" "
0 0 22 3 1 #"(" 0 0 22 3 1 #"#"
0 0 14 3 5 #"x-max" 0 0 22 3 6 #":x-max"
0 0 4 3 1 #" "
0 0 20 3 2 #"30"
0 0 4 3 1 #" "
0 0 22 3 1 #"#"
0 0 22 3 6 #":y-max"
0 0 4 3 1 #" " 0 0 4 3 1 #" "
0 0 20 3 2 #"30" 0 0 20 3 2 #"30"
0 0 22 3 1 #")" 0 0 22 3 1 #")"
0 0 4 3 1 #" "
0 0 22 3 1 #"("
0 0 14 3 5 #"y-max"
0 0 4 3 1 #" "
0 0 20 3 2 #"30"
0 0 22 3 2 #"))"
0 0 4 29 1 #"\n" 0 0 4 29 1 #"\n"
0 0 4 29 1 #"\n" 0 0 4 29 1 #"\n"
0 0 17 3 1 #";" 0 0 17 3 1 #";"
@ -409,8 +384,7 @@
0 0 17 3 1 #"n" 0 0 17 3 1 #"n"
0 0 17 3 1 #"g" 0 0 17 3 1 #"g"
0 0 17 3 1 #" " 0 0 17 3 1 #" "
0 0 17 3 1 #"l" 0 0 17 3 2 #"li"
0 0 17 3 1 #"i"
0 0 17 3 1 #"k" 0 0 17 3 1 #"k"
0 0 17 3 1 #"e" 0 0 17 3 1 #"e"
0 0 17 3 1 #" " 0 0 17 3 1 #" "
@ -436,11 +410,9 @@
0 0 17 3 1 #"r" 0 0 17 3 1 #"r"
0 0 17 3 1 #"e" 0 0 17 3 1 #"e"
0 0 17 3 1 #" " 0 0 17 3 1 #" "
0 0 17 3 1 #"r" 0 0 17 3 6 #"random"
0 0 17 3 1 #"a"
0 0 17 3 4 #"ndom"
0 0 4 29 1 #"\n"
0 0 4 29 1 #"\n" 0 0 4 29 1 #"\n"
0 0 17 3 1 #";"
0 3 00000000037 4 1 #"\0" 0 3 00000000037 4 1 #"\0"
2 -1 -1 0 0 0 00000000013 500 2 -1 -1 0 0 0 00000000013 500
( (

View File

@ -1,3 +1,4 @@
#lang scheme
(require plot) (require plot)
(require mzlib/class plot/plot-extend) (require mzlib/class plot/plot-extend)

View File

@ -1,4 +1,4 @@
#lang scheme
(require plot) (require plot)
(require mzlib/etc)
(plot (line identity (color 'red))) (plot (line (lambda (x) x) #:color 'red))

View File

@ -1,3 +1,4 @@
#lang scheme
(require plot) (require plot)
(plot (line (lambda (x) (sin x)) (color 'red))) (plot (line sin #:color 'red))

View File

@ -1,5 +1,5 @@
#lang scheme
(require plot) (require plot)
(plot (plot (vector-field (gradient (lambda (x y) (* (sin x) (cos y)))) #:samples 25)
(vector-field (gradient (lambda (x y) (* (sin x) (cos y)))) (samples 25)) #:title "gradient field of F(x,y) = sin(x) * sin(y)")
(title "gradient field of F(x,y) = sin(x) * sin(y)"))

View File

@ -1,7 +1,7 @@
#lang scheme
(require plot) (require plot)
(define (trig x y) (* (sin x) (sin y))) (define (trig x y) (* (sin x) (sin y)))
(plot (shade trig) (plot (shade trig)
(x-min -1.5) (x-max 1.5) (y-min -1.5) (y-max 1.5) #:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
(title "shdade of F(x,y) = sin(x) * sin(y)")) #:title "shdade of F(x,y) = sin(x) * sin(y)")

View File

@ -1,7 +1,8 @@
#lang scheme
(require plot) (require plot)
(define (trig x y) (* (sin x) (sin y))) (define (trig x y) (* (sin x) (sin y)))
(plot (contour trig) (plot (contour trig)
(x-min -1.5) (x-max 1.5) (y-min -1.5) (y-max 1.5) #:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
(title "contours of F(x,y) = sin(x) * sin(y)")) #:title "contours of F(x,y) = sin(x) * sin(y)")

View File

@ -1,7 +1,8 @@
#lang scheme
(require plot) (require plot)
(define (trig x y) (* (sin x) (sin y))) (define (trig x y) (* (sin x) (sin y)))
(plot (vector-field (gradient trig) '((samples 25))) (plot (vector-field (gradient trig) #:samples 25)
(x-min -1.5) (x-max 1.5) (y-min -1.5) (y-max 1.5) #:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
(title "gradient field of F(x,y) = sin(x) * sin(y)")) #:title "gradient field of F(x,y) = sin(x) * sin(y)")

View File

@ -1,14 +1,14 @@
#lang scheme
(require plot) (require plot)
(define (trig x y) (* (sin x) (sin y))) (define (trig x y) (* (sin x) (sin y)))
(plot (mix (shade trig)
(plot (mix (contour trig)
(shade trig) (vector-field (gradient trig) #:samples 25))
(contour trig) #:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
(vector-field (gradient trig ) (samples 25))) #:title "gradient field +shdade + contours of F(x,y) = sin(x) * sin(y)")
(x-min -1.5) (x-max 1.5) (y-min -1.5) (y-max 1.5)
(title "gradient field +shdade + contours of F(x,y) = sin(x) * sin(y)"))
(plot3d (mesh3d trig) (plot3d (mesh3d trig)
(x-min -3.5) (x-max 3.5) (y-min -3.5) (y-max 3.5) (z-min -1.0) (z-max 1.5) (bgcolor '(0 0 0)) (fgcolor '(255 0 0))) #:x-min -3.5 #:x-max 3.5 #:y-min -3.5 #:y-max 3.5 #:z-min -1.0 #:z-max 1.5
#:bgcolor '(0 0 0) #:fgcolor '(255 0 0))

View File

@ -1,3 +1,4 @@
#lang scheme
(require plot) (require plot)
(define x-vals (build-list 15 (lambda (x) x) )) (define x-vals (build-list 15 (lambda (x) x) ))
@ -12,12 +13,12 @@
(define params (define params
(fit gues-fun (fit gues-fun
((a 1) (b 1)) '((a 1) (b 1))
(map vector x-vals z-vals errors))) (map vector x-vals z-vals errors)))
(plot (mix (plot (mix
(points (map vector x-vals z-vals)) (points (map vector x-vals z-vals))
(line (lambda (x) (line (lambda (x)
(apply gues-fun x (fit-result-final-params params))))) (apply gues-fun x (fit-result-final-params params)))))
(x-min -1) (x-max 20) #:x-min -1 #:x-max 20
(y-min -1) (y-max 10)) #:y-min -1 #:y-max 10)

View File

@ -1,5 +1,6 @@
;; This is data from the Cavendish experiment #lang scheme
;; This is data from the Cavendish experiment
(define raw-data (define raw-data
'((0.0 -14.7 3.6) '((0.0 -14.7 3.6)
(1.0 8.6 3.6) (1.0 8.6 3.6)
@ -7,39 +8,39 @@
(3.1 46.7 3.4) (3.1 46.7 3.4)
(4.2 47.4 3.5) (4.2 47.4 3.5)
(5.2 36.5 3.4) (5.2 36.5 3.4)
(6.2 37.0 10.3) (6.2 37.0 10.3)
(7.2 5.1 3.4) (7.2 5.1 3.4)
(8.2 -11.2 3.4) (8.2 -11.2 3.4)
(9.1 -22.4 3.5) (9.1 -22.4 3.5)
(10.0 -35.5 3.6) (10.0 -35.5 3.6)
(11.0 -33.6 3.9) (11.0 -33.6 3.9)
(12.0 -21.1 3.9) (12.0 -21.1 3.9)
(12.9 -15.0 4.2) (12.9 -15.0 4.2)
(13.8 -1.6 2.7) (13.8 -1.6 2.7)
(14.9 19.5 3.2) (14.9 19.5 3.2)
(15.9 27.5 2.8) (15.9 27.5 2.8)
(17.0 32.6 3.5) (17.0 32.6 3.5)
(17.9 27.5 2.7) (17.9 27.5 2.7)
(18.9 20.2 3.3) (18.9 20.2 3.3)
(20.0 13.8 3.4) (20.0 13.8 3.4)
(21.0 -1.3 4.2) (21.0 -1.3 4.2)
(22.0 -24.5 6.7) (22.0 -24.5 6.7)
(23.0 -25.0 3.3) (23.0 -25.0 3.3)
(24.0 -25.0 3.1) (24.0 -25.0 3.1)
(25.0 -20.2 3.6) (25.0 -20.2 3.6)
(26.0 -9.9 3.2) (26.0 -9.9 3.2)
(27.0 5.8 3.2) (27.0 5.8 3.2)
(28.0 14.7 3.0) (28.0 14.7 3.0)
(29.0 21.8 3.5) (29.0 21.8 3.5)
(30.0 29.8 2.7) (30.0 29.8 2.7)
(31.0 21.4 4.1) (31.0 21.4 4.1)
(32.0 24.6 2.7) (32.0 24.6 2.7)
(32.9 25.8 12.0) (32.9 25.8 12.0)
(33.8 0.6 2.9) (33.8 0.6 2.9)
(34.7 -16.6 3.2) (34.7 -16.6 3.2)
(35.7 -24.0 3.7) (35.7 -24.0 3.7)
(36.6 -24.6 3.8) (36.6 -24.6 3.8)
(37.7 -19.8 3.5))) (37.7 -19.8 3.5)))
; first column is time data, second is result, third is error. to parse them out... ; first column is time data, second is result, third is error. to parse them out...
(require mzlib/math) (require mzlib/math)
@ -55,33 +56,24 @@
(require plot) (require plot)
(plot (mix (points experemental-data (symbol 'circle)) (plot (mix (points experemental-data #:sym 'circle)
(error-bars experemental-data)) (error-bars experemental-data))
(x-min 0) (x-max 40) #:x-min 0 #:x-max 40
(y-min -40) (y-max 50) #:y-min -40 #:y-max 50
(width 400) (height 300)) #:width 400 #:height 300)
(define (define (theta x a tau phi T theta0)
(theta x a tau phi T theta0) (+ theta0
(+ (* a (exp (/ x tau -1)) (sin (+ phi (/ (* 2 pi x) T))))))
theta0
(* a
(exp (/ x tau -1))
(sin (+ phi (/ (* 2 pi x) T))))))
(define result (define result
(fit (fit theta '((a 40) (tau 15) (phi -0.5) (T 15) (theta0 10)) experemental-data))
theta
((a 40) (tau 15) (phi -0.5) (T 15) (theta0 10))
experemental-data))
(plot (mix (points (map vector times vals) #:sym 'square #:color 'black)
(plot (mix (error-bars experemental-data)
(points (map vector times vals) (symobol 'square) (color 'black)) (line (fit-result-function result) #:color 'green))
(error-bars experemental-data) #:x-min -5 #:x-max 40
(line (fit-result-function result) (color 'green))) #:y-min -40 #:y-max 50)
(x-min -5) (x-max 40)
(y-min -40) (y-max 50))
(fit-result-final-params result) (fit-result-final-params result)
;(pretty-print result) ;(pretty-print result)

View File

@ -8,7 +8,8 @@
shade surface)) shade surface))
(only-in "plot.ss" (only-in "plot.ss"
mix mix
derivative gradient make-vec) derivative gradient make-vec
mesh3d)
(only-in "fit.ss" fit-int)) (only-in "fit.ss" fit-int))
(provide plot (provide plot
@ -25,7 +26,8 @@
mix mix
derivative derivative
gradient gradient
make-vec) make-vec
mesh3d)
(define-syntax-rule (out-fit-struct) (define-syntax-rule (out-fit-struct)
(begin (begin
@ -50,6 +52,7 @@
#:fgcolor [fgcolor '(0 0 0)] #:fgcolor [fgcolor '(0 0 0)]
#:bgcolor [bgcolor '(255 255 255)] #:bgcolor [bgcolor '(255 255 255)]
#:lncolor [lncolor '(255 0 0)] #:lncolor [lncolor '(255 0 0)]
#:out-file [out-file #f]
arg-extra ...) arg-extra ...)
(orig:plot data (orig:plot data
[width width] [width width]
@ -64,16 +67,17 @@
[fgcolor fgcolor] [fgcolor fgcolor]
[bgcolor bgcolor] [bgcolor bgcolor]
[lncolor lncolor] [lncolor lncolor]
[out-file out-file]
init-extra ...))) init-extra ...)))
(define-plot plot orig:plot [] []) (define-plot plot orig:plot [] [])
(define-plot plot3d orig:plot3d (define-plot plot3d orig:plot3d
[#:z-min [z-min -5] [#:z-min [z-min -5]
#:z-max [z-max 5] #:z-max [z-max 5]
#:z-label [z-label "Z axis"] #:z-label [z-label "Z axis"]
#:alt [alt 30] #:alt [alt 30]
#:az [az 45]] #:az [az 45]]
[[z-min z-min] [[z-min z-min]
[z-max z-max] [z-max z-max]
[z-label z-label] [z-label z-label]
@ -82,8 +86,8 @@
(define (plot-color? v) (define (plot-color? v)
(memq v '(white black yellow green aqua pink (memq v '(white black yellow green aqua pink
wheat grey blown blue violet cyan wheat grey blown blue violet cyan
turquoise magenta salmon red))) turquoise magenta salmon red)))
(define (points vecs (define (points vecs
#:sym [sym 'square] #:sym [sym 'square]
@ -114,11 +118,13 @@
(define (vector-field f (define (vector-field f
#:width [width 1] #:width [width 1]
#:color [color 'red] #:color [color 'red]
#:style [style 'scaled]) #:style [style 'scaled]
#:samples [samples 20])
(orig:vector-field f (orig:vector-field f
[width width] [width width]
[color color] [color color]
[style style])) [style style]
[samples samples]))
(define (contour f (define (contour f
#:samples [samples 50] #:samples [samples 50]

View File

@ -171,8 +171,7 @@
plot-line plot-line
plot-contours plot-contours
plot-shades plot-shades
fill fill)
)
; set-labels : string string string -> nothing ; set-labels : string string string -> nothing
; sets the x, y and title lables ; sets the x, y and title lables

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -1,24 +1,19 @@
#!/bin/sh #!/bin/sh
#| #| -*- scheme -*-
exec mred -u "$0" "$@" exec mred "$0" "$@"
|# |#
(module run-tests mzscheme #lang scheme
(require plot mzlib/md5)
(require plot
mzlib/md5
mzlib/pretty)
;; thisi should be big enough to read thse files
(define (read-file file) (define (read-file file)
(with-input-from-file file (lambda () (read-bytes 100000)))) (with-input-from-file file (lambda () (read-bytes (file-size file)))))
(define-syntax run-test (define-syntax run-test
(syntax-rules () (syntax-rules ()
[(_ description (plot args ...) file-name) [(_ description (plot args ...) file-name)
(let* ([result-file-name (string-append file-name "-out.png")] (let* ([result-file-name (string-append file-name "-out.png")]
[expected-file-name (string-append file-name ".png")]) [expected-file-name (string-append file-name ".png")])
(plot args ... (out-file result-file-name)) (plot args ... #:out-file result-file-name)
;; WILL COMPARE by MD5 hash. ;; WILL COMPARE by MD5 hash.
(printf "testing \"~a\" ... " description) (printf "testing \"~a\" ... " description)
(if (equal? (md5 (read-file result-file-name)) (if (equal? (md5 (read-file result-file-name))
@ -28,60 +23,47 @@ exec mred -u "$0" "$@"
expected-file-name expected-file-name
result-file-name)))])) result-file-name)))]))
(run-test "Line" (run-test "Line"
(plot (plot (line (lambda (x) x) #:color 'red))
(line (lambda (x) x) (color 'red)))
"red-identity") "red-identity")
(run-test "Vector Field"
(plot (vector-field (gradient (lambda (x y) (* (sin x) (cos y))))
(run-test #:samples 25)
"Vector Field" #:title "gradient field of F(x,y) = sin(x) * sin(y)")
(plot "vector-field")
(vector-field
(gradient (lambda (x y) (* (sin x) (cos y))))
(samples 25))
(title "gradient field of F(x,y) = sin(x) * sin(y)"))
"vector-field")
(define (trig x y) (* (sin x) (sin y))) (define (trig x y) (* (sin x) (sin y)))
(run-test (run-test "Shading"
"Shading" (plot (shade trig)
(plot (shade trig) #:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
(x-min -1.5) (x-max 1.5) (y-min -1.5) (y-max 1.5) #:title "shdade of F(x,y) = sin(x) * sin(y)")
(title "shdade of F(x,y) = sin(x) * sin(y)")) "shade")
"shade")
(run-test (run-test "Contours"
"Contours" (plot (contour trig)
(plot (contour trig) #:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
(x-min -1.5) (x-max 1.5) (y-min -1.5) (y-max 1.5) #:title "contours of F(x,y) = sin(x) * sin(y)")
(title "contours of F(x,y) = sin(x) * sin(y)")) "contours")
"contours")
(run-test (run-test "Mix of all three"
"Mix of all three" (plot (mix (shade trig)
(plot (mix (contour trig)
(shade trig) (vector-field (gradient trig) #:samples 25))
(contour trig) #:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5
(vector-field (gradient trig ) (samples 25))) #:title "gradient field & shade & contours")
(x-min -1.5) (x-max 1.5) (y-min -1.5) (y-max 1.5) "mix")
(title
"gradient field +shdade + contours of F(x,y) = sin(x) * sin(y)"))
"mix")
(run-test (run-test "3d mesg"
"3d mesg" (plot3d (mesh3d trig)
(plot3d (mesh3d trig) #:x-min -3.5 #:x-max 3.5
(x-min -3.5) (x-max 3.5) (y-min -3.5) (y-max 3.5) (z-min -1.0) (z-max 1.5) (bgcolor '(0 0 0)) (fgcolor '(255 0 0))) #:y-min -3.5 #:y-max 3.5
"3d-mesh") #:z-min -1.0 #:z-max 1.5
#:bgcolor '(0 0 0) #:fgcolor '(255 0 0))
(require mzlib/class "3d-mesh")
(lib "plot-extend.ss" "plot")
mzlib/etc)
(require plot/plot-extend)
; (number -> number) mumbo-jumbo -> 2d-renderer ; (number -> number) mumbo-jumbo -> 2d-renderer
(define-plot-type dashed-line (define-plot-type dashed-line
@ -101,14 +83,10 @@ exec mred -u "$0" "$@"
(map (lambda (x) (vector x (fun x))) dash))) (map (lambda (x) (vector x (fun x))) dash)))
x-lists))) x-lists)))
(run-test (run-test "Simple plot-extend"
"Simple plot-extend" (plot (dashed-line (lambda (x) x) [color 'red]))
(plot (dashed-line (lambda (x) x) (color 'red))) "dashed-line")
"dashed-line")
(run-test (run-test "canvas sizing"
"canvas sizing" (plot (line sin) #:height 100 #:width 100)
(plot (line sin) (height 100) (width 100)) "size")
"size")
)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB