Jump to content

Barnsley's Fern & Sierpinski's Triangle


Lee Mac

Recommended Posts

Posted this over at the Swamp, thought I'd share it with you guys too.

 

The fractal images can be created using a set of iterated maps of the form:

 

9a999429d9c707ff98a6afc2bd1fdda3.png

 

Each being applied recursively, with varying probability.

 

 

fern.png

 

sierpinski.png

 

(defun c:fern (/ ptlst pt probability)
 ;; Lee Mac  ~  20.02.10
 (repeat 50000    
   (setq probability (rng))

   (Point (setq pt  (cond (  (< probability 0.01)
                             (iterate pt '((0.0 0.0)
                                           (0.0 0.16)) '(0.0 0.0)))

                          (  (<= 0.01 probability 0.86)
                             (iterate pt '(( 0.85 0.04)
                                           (-0.04 0.85)) '(0.0 1.6)))

                          (  (< 0.86 probability 0.93)
                             (iterate pt '((0.20 -0.26)
                                           (0.23  0.22)) '(0.0 1.6)))

                          (t (iterate pt '((-0.15 0.28)
                                           ( 0.26 0.24)) '(0.0 0.44)))))))
 (princ))

(defun c:sierpinski (/ ptlst pt probability)
 ;; Lee Mac  ~  20.02.10
 (repeat 50000    
   (setq probability (rng))

   (Point (setq pt (cond (  (< probability 0.333)
                            (iterate pt '((0.5 0.0)
                                          (0.0 0.5)) '(0.0 0.0)))

                         (  (<= 0.333 probability 0.666)
                            (iterate pt '((0.5 0.0)
                                          (0.0 0.5)) '(0.5 0.0)))
                         
                         (t (iterate pt '((0.5 0.0)
                                          (0.0 0.5)) '(0.25 0.5)))))))
 (princ))

(defun iterate (point matrix vector)
 (mapcar
   (function +)
     (mapcar
       (function
         (lambda (row)
           (apply (function +)
                  (mapcar (function *) row point)))) matrix) vector))

(defun rng (/ modulus multiplier increment random) ;; Stig
 (if (not seed) (setq seed (getvar "DATE")))
 (setq modulus    4294967296.0 multiplier 1664525 increment 1 
       seed       (rem (+ (* multiplier seed) increment) modulus) 
       random     (/ seed modulus)))

(defun Point (pt)
 (entmakex (list (cons 0 "POINT") (cons 10 pt) (cons 62 40))))

sierpinski2.png

 

 

I have also created a small program so that you may easily generate these fractals, and many others, just using various 'Rules' representing each iterated mapping.

 

IteratedMaps.png

 

Example.png

 

See what you can come up with!

 

If you have any questions about the processes involved, I'd be more than happy to explain. :)

 

Enjoy!,

 

Lee

Mapping.lsp

Link to comment
Share on other sites

Lee: The last one almost looks like it could pass for ground cover in an architectural plan. Is there anyway to constrain it using a boundary of sorts?

Link to comment
Share on other sites

Lee: The last one almost looks like it could pass for ground cover in an architectural plan. Is there anyway to constrain it using a boundary of sorts?

 

Its just a collection of Points, and is not properly defined I suppose until n goes to infinity where n is the number of times the function has been recursively iterated:

 

f(f(...f(x)))  ~ n times

 

So, the boundary would always only be an approximation :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...