Code Monkey home page Code Monkey logo

fractals's Introduction

Fractals

Tasks

  • Large images are taking a while to generate (8K image at 10000 iterations took 20 minutes). Need to look into optimization
  • Need to add color smoothing. There is very noticable banding. Need to implement logarithmic smoothing to mandlebrot function

Color Smoothing

Added Color smoothing by normalizing the iteration count. Done by taking the log of the log of the magnitude of the imagninary number at escape value. See below;

if(abs(z) > 2)
{
  return iterations + 1.0 - log(log2(abs(z)));
  break;
}

The normalized iteration count is now calculated as follows;

return iterations + 1.0 - log(log(abs(z))) / log(ESCAPE_RADIUS);

This is more generalized as I may choose to increase the escape radius (bailout radius to some) later.

This produces images like those below; 50 iterations to produce the image below. Smooth mandelbrot Zoomed in regions shown below need a higher iteration count Smooth mandelbrot zoomed Julia sets look like this; Smooth Julia

Estimating distance to nearest mandelbrot surface

I'll be adding in the ability to draw the mandelbrot set using a distance estimation algorithm. Currently I have the following;

double Mandelbrot::getIterations(double x, double y)
{
    complex<double> c(x, y);
    complex<double> z = 0;
    complex<double> dz = 0;

    double iterations = 0;

    while (iterations < MAX_ITERATIONS)
    {
        dz = 2.0 * dz * z + 1.0;
        z = z * z + c;

        if (abs(z) > 10000)
        {
            return abs(abs(z) * log(abs(z)) / abs(dz));
        }
        iterations++;
    }
    return 0;
}

This produces a blurred plot but this can be alleviated using a large bailout radius and also more iterations

Julia sets

Also working on implementing julia set generation. Currently have the following;

double Mandelbrot::getJulia(double x, double y)
{
    complex<double> z(x,y);
    complex<double> c(-0.7269, 0.1889);

    double iterations = 0;

    while (iterations < MAX_ITERATIONS)
    {
        z = z * z + c;
        if (abs(z) > 2) {
            return iterations + 1.0 - log(log2(abs(z)));
            break;
        }
        iterations++;
    }
    return double(MAX_ITERATIONS);
}

And also the distance estimation

double Mandelbrot::getIterations(double x, double y)
{
  complex<double> c(x, y);
  complex<double> z = 0;
  complex<double> dz = 0;

  double iterations = 0;

  while(iterations < MAX_ITERATIONS)
  {
      dz = 2.0 * dz * z + 1.0;
      z = z * z + c;

      if(abs(z) > 2)
      {
        break;
      }
      iterations++;
  }
  return 0.5*log(abs(z)*abs(z)/abs(dz);
}

Sample images

These images are genearated using the frequence of the number of iteration e.g. if at pixle x,y it took n iterations, and the total number of pixels with n iterations is m, normalize m and use taht to color in the plot.

Hue[0,60], saturation 100%, value 100% Large 8K image using limited hue region

Wide RGB range in zoomed in region Hue[0,360], saturation 100%, value 100%

Zoomed in colourful

Hue[220,260], saturation 100%, value 100%. Gradually zooming in Large 8K image using limited hue region Large 8K image using limited hue region Large 8K image using limited hue region Large 8K image using limited hue region

fractals's People

Contributors

ozyozk avatar

Watchers

James Cloos 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.