;;;; flower.ss ;; Purpose: Demonstrate primitive.c and highlevel.ss ;; First-edit: 2002-07-24 SSeidel ;; Latest-revision: 2002-11-09 SSeidel ;; To get the ultimate animation, search this source-file for ;; "adjust here". On that line you will find the command: ;; (flower-blossom start step end) ;; The animation beginnes at and runs towards . ;; Lowering step increases the smoothness of the animation ;; as well as the time that's spend with computation. ;; ------------------------------------------------------------- ;; The tools of the trade. (require (lib "primitive.ss" "matlab-interface") (lib "highlevel.ss" "matlab-interface")) ;; Three, two, one, zero ... (engine-open) ;; Visual contact! (newline) (array->string (engine-apply "fliplr" (string->array "mossolb srewolf eht gnirps ni") '() )) ;; Map a procedure on vector-indices. ;; Return the vector. (define vector:map-index! (lambda (p v) (let F ((x (- (vector-length v) 1))) (and (<= 0 x) (begin (vector-set! v x (p x)) (F (- x 1)))) v))) ;; Make a linearly increasing or decreasing vector. (define subscript-vector (lambda (start step end) (vector:map-index! (lambda (i) (+ start (* i step))) (make-vector (inexact->exact (round (/ (- end start) step))))))) ;; Map a procedure on matrix-indices. ;; Return the matrix. (define 2d-matrix:map-index! (lambda (p mx) (let F ((y (- (vector-length mx) 1))) (and (<= 0 y) (begin (let G ((x (- (vector-length (vector-ref mx y)) 1))) (and (<= 0 x) (begin (vector-set! (vector-ref mx y) x (p x y)) (G (- x 1))))) (F (- y 1)))) mx))) ;; A flower. (define flower (lambda (z) (2d-matrix:map-index! (lambda (x y) (let ((x (- x 40)) (y (- y 40))) (sin (/ z (let ((val (sqrt (+ (* x x) (* y y))))) (if (= val 0) 0.01 val)))))) (vector:map-index! (lambda (i) (make-vector 80)) (make-vector 80))))) ;; Animate the flower in matlab. (define flower-blossom (lambda (start step end) (for-each (lambda (matrix) (engine-apply "surf" (list (matrix->array matrix)))) (map flower (vector->list (subscript-vector start step end)))))) ;; I love spring. (flower-blossom -50 1 80) ;; <-- adjust here ;; Wait a moment. (engine-eval "pause (8);") ;; Good bye! (engine-close)