How to program a fractal?

后端 未结 14 929
花落未央
花落未央 2020-12-04 05:34

I do not have any experience with programming fractals. Of course I\'ve seen the famous Mandelbrot images and such.

Can you provide me with simple algorithms for fra

相关标签:
14条回答
  • 2020-12-04 05:36

    Another excellent fractal to learn is the Sierpinski Triangle Fractal.

    Basically, draw three corners of a triangle (an equilateral is preferred, but any triangle will work), then start a point P at one of those corners. Move P halfway to any of the 3 corners at random, and draw a point there. Again move P halfway towards any random corner, draw, and repeat.

    You'd think the random motion would create a random result, but it really doesn't.

    Reference: http://en.wikipedia.org/wiki/Sierpinski_triangle

    0 讨论(0)
  • If complex numbers give you a headache, there is a broad range of fractals that can be formulated using an L-system. This requires a couple of layers interacting, but each is interesting in it own right.

    First you need a turtle. Forward, Back, Left, Right, Pen-up, Pen-down. There are lots of fun shapes to be made with turtle graphics using turtle geometry even without an L-system driving it. Search for "LOGO graphics" or "Turtle graphics". A full LOGO system is in fact a Lisp programming environment using an unparenthesized Cambridge Polish syntax. But you don't have to go nearly that far to get some pretty pictures using the turtle concept.

    Then you need a layer to execute an L-system. L-systems are related to Post-systems and Semi-Thue systems, and like virii, they straddle the border of Turing Completeness. The concept is string-rewriting. It can be implemented as a macro-expansion or a procedure set with extra controls to bound the recursion. If using macro-expansion (as in the example below), you will still need a procedure set to map symbols to turtle commands and a procedure to iterate through the string or array to run the encoded turtle program. For a bounded-recursion procedure set (eg.), you embed the turtle commands in the procedures and either add recursion-level checks to each procedure or factor it out to a handler function.

    Here's an example of a Pythagoras' Tree in postscript using macro-expansion and a very abbreviated set of turtle commands. For some examples in python and mathematica, see my code golf challenge.

    ps l-system pythagoras tree luser-droog

    0 讨论(0)
  • 2020-12-04 05:38

    Here's a simple and easy to understand code in Java for mandelbrot and other fractal examples

    http://code.google.com/p/gaima/wiki/VLFImages

    Just download the BuildFractal.jar to test it in Java and run with command:

    java -Xmx1500M -jar BuildFractal.jar 1000 1000 default MANDELBROT

    The source code is also free to download/explore/edit/expand.

    0 讨论(0)
  • 2020-12-04 05:42

    I think you might not see fractals as an algorithm or something to program. Fractals is a concept! It is a mathematical concept of detailed pattern repeating itself.

    Therefore you can create a fractal in many ways, using different approaches, as shown in the image below.

    enter image description here

    Choose an approach and then investigate how to implement it. These four examples were implemented using Marvin Framework. The source codes are available here

    0 讨论(0)
  • 2020-12-04 05:42

    Well, simple and graphically appealing don't really go hand in hand. If you're serious about programming fractals, I suggest reading up on iterated function systems and the advances that have been made in rendering them.

    http://flam3.com/flame_draves.pdf

    0 讨论(0)
  • 2020-12-04 05:43

    There is a great book called Chaos and Fractals that has simple example code at the end of each chapter that implements some fractal or other example. A long time ago when I read that book, I converted each sample program (in some Basic dialect) into a Java applet that runs on a web page. The applets are here: http://hewgill.com/chaos-and-fractals/

    One of the samples is a simple Mandelbrot implementation.

    0 讨论(0)
提交回复
热议问题