Giter Club home page Giter Club logo

fractastic's Introduction

Fractastic

Fractastic is a simple and approachable fractal generator written in C. It generates Julia set fractals by repeatedly iterating a complex quadratic function until divergence (or convergence). The number of iterations required to diverge at a point is recorded and used as part of the value to color the related pixel in the final, rendered image of the fractal.

Usage

run.sh is a script that will handle everything for you automatically. It is heavily commented, so you can see the exact steps that it takes. The C program outputs to stdout; run.sh just captures its output and pipes it to a ppm (and png, if ImageMagick is installed) file.

Use run.sh as follows:

./run.sh [output_file] [fractastic_options]

where [fractastic_options] are the options that you would pass in as if you had invoked fractastic directly (as follows).

For Julia sets:

./fractastic J [width] [height]
               [x_min] [x_max] [y_min] [y_max]
               [max_iterations]
               [color_multiplier]
               [c_re] [c_im]
               [d]

And for (generalized) Mandelbrot sets:

./fractastic M [width] [height]
               [x_min] [x_max] [y_min] [y_max]
               [max_iterations]
               [color_multiplier]
               [d]

Parameter Descriptions

  • output_file: the name of the file to output to (do not include file extension; .ppm and .png are auto-generated)
  • width: the width of the output file in pixels
  • height: the height of the output file in pixels
  • x_min: the x-coordinate of the left bound of the rendered image (left bound of the window)
  • x_max: the x-coordinate of the right bound of the rendered image (right bound of the window)
  • y_min: the y-coordinate of the lower bound of the rendered image (lower bound of the window)
  • y_max: the y-coordinate of the upper bound of the rendered image (upper bound of the window)
  • max_iterations: the number of iterations to try before determining that f does not diverge
  • color_multiplier: a multiplier for the contrast of the image (lower values result in more black; higher values result in more white; honestly, just play with it until the fractal looks nice!)
  • c_re: the real component of the complex parameter c to be passed into the iterated function f(z) = zd + c
  • c_im: the imaginary component of the complex parameter c to be passed into the iterated function f(z) = zd + c
  • d: the real parameter d to be passed into the iterated function f(z) = zd + c

Note that the scale and step of the render algorithm are automatically determined from the above parameters.

ImageMagick

ImageMagick is available in most package managers, including homebrew (Mac) and apt-get (Debian, Ubuntu, etc.). Just install it, and be sure that the convert command is available. If you do not install ImageMagick, fractastic will still work, but you will not be able to get png output (only ppm).

Examples

To generate all of these examples, execute ./gen-examples.sh. Note that this may take a while depending on the speed of your computer.

I deleted the ppm output of these commands before uploading them to the git repository to save (massive amounts) of space. In normal usage, these commands will generate ppm files.

Example 1 (Julia set)

Input

f(z) = z2 - 0.618

./run.sh examples/julia1 J 2000 2000 -2 2 -2 2 1000 20 -0.618 0 2

Output

Julia Set Fractal 1

Example 2 (Julia set)

Input

f(z) = z2 + (-0.4 + 0.6i)

./run.sh examples/julia2 J 2000 2000 -2 2 -2 2 1000 1 -0.4 0.6 2

Output

Julia Set Fractal 2

Example 3 (Julia set)

Input

f(z) = z3 + (-0.4 + 0.6i)

./run.sh examples/julia3 J 2000 2000 -2 2 -2 2 1000 20 -0.4 0.6 3

Output

Julia Set Fractal 3

Example 4 (Julia set)

Input

f(z) = z2 + (-0.8 + 0.156i)

./run.sh examples/julia4 J 2000 2000 -2 2 -2 2 1000 1 -0.8 0.156 2

Output

Julia Set Fractal 4

Example 5 (Mandelbrot set)

Input

f(z) = z2 + c

./run.sh examples/mandel1 M 2000 2000 -2.5 1.5 -2 2 1000 20 2

Output

Mandelbrot Set Fractal 1

Example 6 (Mandelbrot set)

Input

f(z) = z3 + c

./run.sh examples/mandel2 M 2000 2000 -2 2 -2 2 1000 20 3

Output

Mandelbrot Set Fractal 2

Example 7 (Mandelbrot set)

Input

f(z) = z4 + c

./run.sh examples/mandel3 M 2000 2000 -2 2 -2 2 1000 20 4

Output

Mandelbrot Set Fractal 3

Example 8 (Mandelbrot set)

Input

f(z) = z6 + c

./run.sh examples/mandel4 M 2000 2000 -2 2 -2 2 1000 20 6

Output

Mandelbrot Set Fractal 4

Purpose

The purpose of this project was to create a simple yet powerful fractal generator in pure, best-practice C code without relying on external libraries. This was done so that I could learn more about fractals and C, as well as to serve as a pedagogical tool for other beginners to learn about C (in particular, how to generate images). Most of the resources I found online were in incomprehensible, difficult-to-read C or used advanced graphics libraries, so I wanted to provide an alternative.

Possible Improvements

  • Color

fractastic's People

Contributors

justinlubin avatar gabriel-v avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.