[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [dev-serveez] complex guile server test
From: |
stefan |
Subject: |
Re: [dev-serveez] complex guile server test |
Date: |
Mon, 5 Nov 2001 19:55:03 +0100 (CET) |
Hello again,
playing around with Mandelbrot-Algorithm I got the following Guile
code bit:
======= 8< == mandelbrot.scm ======================================
;; Mandelbrot set
(define epsilon 1e-4)
(define MaxIteration (* 1 1024))
(define Colors MaxIteration)
(define xRes 100)
(define yRes 100)
(define Start (make-rectangular -2 -2))
(define End (make-rectangular +2 +2))
(define (near z1 z2)
(and (< (abs (real-part (- z2 z1))) epsilon)
(< (abs (imag-part (- z2 z1))) epsilon)))
(define (iterateMandel z)
(let* ((old-z z) (done #f) (i 0) (result (- MaxIteration 1)))
(do ((i 0 (+ i 1)))
((or done (>= i MaxIteration)))
(set! z (+ z (* z z)))
(if (near z old-z)
(set! i (- MaxIteration 1)))
(if (> (magnitude z) 2)
(begin
(set! done #t)
(set! result i)))
(set! old-z z))
result))
(define (doMandel z1 z2 x-res y-res colors)
(let* ((x-diff (real-part (- z2 z1)))
(y-diff (imag-part (- z2 z1)))
(x-ratio (/ x-diff x-res))
(y-ratio (/ y-diff y-res))
(x 0)
(y 0)
(z z1)
(i 0) (n 0)
(vector (make-vector (* x-res y-res))))
(set! y-diff (* 0+1i y-diff))
(set! y-ratio (* 0+1i y-ratio))
(set! z (+ z (+ (/ y-ratio 2) (/ x-ratio 2))))
(do ((x 0 (+ x 1)))
((>= x x-res))
(do ((y 0 (+ y 1)))
((>= y y-res))
(set! i (iterateMandel z))
(vector-set! vector n (modulo i colors))
(set! n (+ n 1))
(set! z (+ z y-ratio)))
(set! z (- (+ z x-ratio) y-diff)))
vector))
(define (pretty i)
(let ((str ""))
(if (< i 10)
(set! str "0")
(if (< i 100)
(set! str "")))
(display str) (display i)))
(define (printMandel Mandel x-res y-res)
(let* ((x 0) (y 0))
(display "Mandelbrot:\n")
(do ((y 0 (+ y 1)))
((>= y y-res))
(do ((x 0 (+ x 1)))
((>= x x-res))
(pretty (vector-ref Mandel (+ (* x-res y) x)))
(display " "))
(newline))))
(define t (current-time))
(define Mandel (doMandel Start End xRes yRes Colors))
(display (- (current-time) t)) (display " seconds --- ")
(printMandel Mandel xRes yRes)
======= >8 ==========================================================
Martin: Is this any good/acceptable Guile style? When looking at the
*.scm files in ice-9 I start shivering. The above code is rather C
thinking and straight forward. Could you please comment?
Thanks in advance,
address@hidden
- Re: [dev-serveez] complex guile server test,
stefan <=