Browse files

Bump version 0.2.0

    - add colorisation, so Mandelbrot now looks beautiful
  • Loading branch information...
1 parent 2c97e77 commit 46a8342a85eceb54eede5535123dbc77f1ff6ecd @kipanshi committed Dec 25, 2012
Showing with 24 additions and 9 deletions.
  1. +4 −1 README.md
  2. +1 −1 project.clj
  3. +19 −7 src/clojure_mandelbrot/core.clj
View
5 README.md
@@ -1,6 +1,6 @@
# clojure-mandelbrot
-A simple educational project that draws Mandelbrot set into *.ppm image file
+A simple educational project that draws colorful Mandelbrot set into *.ppm image file
## Installation
@@ -18,6 +18,9 @@ and to generate `Mandelbrot.ppm` use:
lein run
+You can change colorisations by changins constans values in the
+beginning of `core.clj`.
+
Feel free to play with the code, and also refer to
`lein` docs if you want to make standalone jar-file.
View
2 project.clj
@@ -1,4 +1,4 @@
-(defproject clojure-mandelbrot "0.1.0-SNAPSHOT"
+(defproject clojure-mandelbrot "0.2.0-SNAPSHOT"
:description "Mandelbrot Set Drawing Programm"
:url "http://github.com/kipanshi"
:license {:name "Eclipse Public License"
View
26 src/clojure_mandelbrot/core.clj
@@ -19,10 +19,14 @@
(def re-factor (/ (- max-re min-re) (- image-width 1)))
(def im-factor (/ (- max-im min-im) (- image-height 1)))
-(def max-iterations 250)
+(def max-iterations 70)
-(def background-pixel '(0 0 32000))
-(def foreground-pixel '(65355 65355 65355))
+;; Foreground and background pixels are those that belong and not belong
+;; to the Mandelbrot set respectively
+(def foreground-pixel '(0 0 0))
+(def background-red-value 5000)
+(def background-green-value 3000)
+(def background-blue-value 0)
(def OUTPUT-FILE "Mandelbrot.ppm")
@@ -54,6 +58,15 @@
)
)
+(defn background-pixel
+ "Calculate the color of background pixel depending on number of iterations"
+ [n]
+ (if (= n max-iterations)
+ (list 0 0 0)
+ (list background-red-value background-green-value
+ (+ background-blue-value (int (* color-depth (/ n max-iterations))))))
+)
+
(defn process-iteration
"Process an iteration for the pixel"
[n c-re c-im z-re z-im]
@@ -63,8 +76,8 @@
(if (< (+ z-re2 z-im2) 4)
(process-iteration (inc n) c-re c-im
(+ c-re (- z-re2 z-im2)) (+ (* 2 z-re z-im) c-im))
- false)
- true))
+ (background-pixel n))
+ foreground-pixel))
)
(defn process-pixel
@@ -73,8 +86,7 @@
(let [c-re (+ min-re (* x re-factor))
z-re c-re
z-im c-im]
- (if (true? (process-iteration 0 c-re c-im z-re z-im))
- (write-pixel wrtr foreground-pixel) (write-pixel wrtr background-pixel))
+ (write-pixel wrtr (process-iteration 0 c-re c-im z-re z-im))
))
(defn process-y

0 comments on commit 46a8342

Please sign in to comment.