fractal result by accident

Started by
41 comments, last by Bacterius 10 years, 2 months ago
This is fun. I think I remember the formula for the last video from aregee. Had copy the link manually, but the resolution is really bad, therefore...

C# code (console app, copy paste, add reference for System.Drawing)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;

namespace Moire
{
    class Program
    {
        static void Main(string[] args)
        {
            int width = 640;
            int height = 480;
            var scale = 50.0;
            scale /= height; // adjust for resolution
            var xh = width / 2;
            var yh = height / 2;
            var bitmap = new Bitmap(width, height);
            for (int y = 0; y < height; y++)
            {
                var yy = (y - yh) * scale;
                for (int x = 0; x < width; x++)
                {
                    var xx = (x - xh) * scale;
                    var value = xx * xx + yy * yy;  // f(x,y) = x^2 + y ^ 2
                    value = value % 1.0;            // mod, though Hue should actually wrap anyway
                    var color = Hue((float)value);
                    bitmap.SetPixel(x, y, color);
                }
            }
            bitmap.Save("image.png", ImageFormat.Png);
            bitmap.Dispose();
        }

        #region Color functions
        public static byte ToByte(float value)
        {
            return (byte)System.Math.Max(0, System.Math.Min(255, System.Math.Round(255f * value)));
        }

        public static Color FromFloat(float r, float g, float b)
        {
            return Color.FromArgb(ToByte(r), ToByte(g), ToByte(b));
        }

        public static Color Hue(float hue)
        {
            float oneSixth = 1f / 6f;
            float h = hue - (int)hue;
            int index = (int)(h / oneSixth);
            h = (h / oneSixth) - index;
            var q = 1f - h;
            switch (index)
            {
                case 0: return FromFloat(1, h, 0);
                case 1: return FromFloat(q, 1, 0);
                case 2: return FromFloat(0, 1, h);
                case 3: return FromFloat(0, q, 1);
                case 4: return FromFloat(h, 0, 1);
                default: return FromFloat(1, 0, q);
            }
        }
        #endregion

    }
}

Playing with the scale:
scale = 10
MoireScale10_zpsf2704063.png
scale = 20
MoireScale20_zpsc4e29252.png
scale = 50
MoireScale50_zps2d1c360c.png
Advertisement


Fractals are not pretty pictures: They are subsets of R^n with certain self-similarity properties. So you have to start by defining a subset of R^n in some way. A picture doesn't help much.
It kind of does, to dismiss it as fractal. Even if the term "subsets of R^n" produces a "Huh, WTF?" reaction inside you, you can still very clearly see that the pattern is not self-similar.

If this was a fractal, there should be little concentric circles inside the pretty colorful concentric circles. No such thing as even a single odd pixel that doesn't fit into the pretty gradients can be seen in the original picture, nor when you zoom in.


Fractals are not pretty pictures: They are subsets of R^n with certain self-similarity properties. So you have to start by defining a subset of R^n in some way. A picture doesn't help much.
It kind of does, to dismiss it as fractal. Even if the term "subsets of R^n" produces a "Huh, WTF?" reaction inside you, you can still very clearly see that the pattern is not self-similar.

If this was a fractal, there should be little concentric circles inside the pretty colorful concentric circles. No such thing as even a single odd pixel that doesn't fit into the pretty gradients can be seen in the original picture, nor when you zoom in.

If sierpi?ski carpet is a fractal i see no reazon for this to be not fractal ;\

we should ask some mathematician good in fractals, for answer why ifsierpi?ski is a fractal this ball is not ;\

For me it looks like a interferency of circular vaves made by sierpi?ski like raindrop

As everyone suspected, it's just a Moiré pattern. Here's my attempt at producing it:


#include <cstdio>
#include <cmath>

int main() {
  std::puts("# ImageMagick pixel enumeration: 800,800,255,srgb");

  for (int j=0; j<800; ++j) {
    double y = (400.0 - j) / 360.0;
    for (int i=0; i<800; ++i) {
      double x = (i - 400.0) / 360.0;
      double z2 = 1.0 - x * x - y * y;
      double distance = (z2 >= 0.0) ? std::sqrt(z2) : 0.0;
      double color = std::fmod(1000.0*distance, 1.0);
      int r = 256 * color;
      int g = 256 * color;
      int b = 256 * (1.0 - color);
      r = r > 255 ? 255 : r < 0 ? 0 : r;
      g = g > 255 ? 255 : g < 0 ? 0 : g;
      b = b > 255 ? 255 : b < 0 ? 0 : b;
      std::printf("%d,%d: (%d,%d,%d)  #%02X%02X%02X  srgb(%d,%d,%d)\n",
                  i, j,
                  r, g, b,
                  r, g, b,
                  r, g, b);
    }
  }
}

I compiled that code and then executed it, passing the output through `| convert TXT:- output.png' (`convert' is a command-line utility, part of ImageMagick). The output is this:

output.png

[EDIT: If you replace 1000.0 with something like 250.0, you'll get an image much closer to the original in this thread.]

Very good work! I see the central part is probably

distance = sqrt(1-(x*x+y*y))

do you know maybe what klind of function it is id drawed z=f(x,y)

of just z=f(x,0); ?

Im rarely doing mathematics so i forgot the thing

As to moire pattern I suspect this could be treated set of infinite number of moire interferentions - but those interferentions are purely mathematical not 'presentation aliasing' artifacts

This is fun. I think I remember the formula for the last video from aregee. Had copy the link manually, but the resolution is really bad, therefore...

C# code (console app, copy paste, add reference for System.Drawing)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;

namespace Moire
{
    class Program
    {
        static void Main(string[] args)
        {
            int width = 640;
            int height = 480;
            var scale = 50.0;
            scale /= height; // adjust for resolution
            var xh = width / 2;
            var yh = height / 2;
            var bitmap = new Bitmap(width, height);
            for (int y = 0; y < height; y++)
            {
                var yy = (y - yh) * scale;
                for (int x = 0; x < width; x++)
                {
                    var xx = (x - xh) * scale;
                    var value = xx * xx + yy * yy;  // f(x,y) = x^2 + y ^ 2
                    value = value % 1.0;            // mod, though Hue should actually wrap anyway
                    var color = Hue((float)value);
                    bitmap.SetPixel(x, y, color);
                }
            }
            bitmap.Save("image.png", ImageFormat.Png);
            bitmap.Dispose();
        }

        #region Color functions
        public static byte ToByte(float value)
        {
            return (byte)System.Math.Max(0, System.Math.Min(255, System.Math.Round(255f * value)));
        }

        public static Color FromFloat(float r, float g, float b)
        {
            return Color.FromArgb(ToByte(r), ToByte(g), ToByte(b));
        }

        public static Color Hue(float hue)
        {
            float oneSixth = 1f / 6f;
            float h = hue - (int)hue;
            int index = (int)(h / oneSixth);
            h = (h / oneSixth) - index;
            var q = 1f - h;
            switch (index)
            {
                case 0: return FromFloat(1, h, 0);
                case 1: return FromFloat(q, 1, 0);
                case 2: return FromFloat(0, 1, h);
                case 3: return FromFloat(0, q, 1);
                case 4: return FromFloat(h, 0, 1);
                default: return FromFloat(1, 0, q);
            }
        }
        #endregion

    }
}

Playing with the scale:
scale = 10
MoireScale10_zpsf2704063.png
scale = 20
MoireScale20_zpsc4e29252.png
scale = 50
MoireScale50_zps2d1c360c.png

nice, good work

If sierpi?ski carpet is a fractal i see no reazon for this to be not fractal ;\

That is like saying: If a circle is round, I see no reason why a square should not be.

A Sierpinski carpet (or triangle) has the "stereotypical look" of a fractal, which your image just doesn't have. Note that looking like a fractal doesn't make an image a fractal, but not looking like one at all rules it out pretty safely.

If you look at a Sierpinski triangle starting at level 1, it has the look of a filled triangle where an upside-down triangle has been cut out (it works if you start with the level-0 triangle too, but I find the similarity more striking if you start at one subdivision). That exact same pattern is visible in each of the three smaller filled triangles around that cut-out triangle, and in each of the three even smaller triangles inside these, and so on. You can repeat this ad infinitum, and it will always look the same.

If you look at your image, there are circles and rings, and yes they are somewhat similar, arranged in a somewhat repeating texture. But that's where it stops. If you zoom into one of the circles, it doesn't turn out being an orb with many smaller circles and rings. It's just a circle.

This, too, is a regular, repeating pattern, but it is not fractal:

XceBm.png

we should ask some mathematician good in fractals, for answer why ifsierpi?ski is a fractal this ball is not ;\

Well, one mathematician already gave an explanation a dozen or so posts above.

If sierpi?ski carpet is a fractal i see no reazon for this to be not fractal ;\

That is like saying: If a circle is round, I see no reason why a square should not be.

A Sierpinski carpet (or triangle) has the "stereotypical look" of a fractal, which your image just doesn't have. Note that looking like a fractal doesn't make an image a fractal, but not looking like one at all rules it out pretty safely.

If you look at a Sierpinski triangle starting at level 1, it has the look of a filled triangle where an upside-down triangle has been cut out (it works if you start with the level-0 triangle too, but I find the similarity more striking if you start at one subdivision). That exact same pattern is visible in each of the three smaller filled triangles around that cut-out triangle, and in each of the three even smaller triangles inside these, and so on. You can repeat this ad infinitum, and it will always look the same.

If you look at your image, there are circles and rings, and yes they are somewhat similar, arranged in a somewhat repeating texture. But that's where it stops. If you zoom into one of the circles, it doesn't turn out being an orb with many smaller circles and rings. It's just a circle.

This, too, is a regular, repeating pattern, but it is not fractal:

XceBm.png

Probably when increasing the palette frequency inifinitely you will get infinite level of depth in such circle patterns - you ignore this thing or you do not understand? Im not sure but maybe there can be stated that if you will get any small rectangle area you will find a circles in it (though maybe some vaves may be much smaller than dominant one

for me i may repeat it seem this is not worse fractal than sierpi?ski carpet

I wonder if 3d version of it could be obtained? maybe someone will know? (this is maybe more 2d than 3d and i wonder if real spheric

3d versiion surface is obtainable and which formula?)

PS Alvaro could ypu maybe rise up the visuals by inventing more colorfull palette here (more like unbird did)? (I cannot work on this today but would be curious if this could be more colorfull)

It should look something similar to this:

round_Sierpinski_carpet_small.png

(that's a Sierpinski carpet with circles)

for me i may repeat it seem this is not worse fractal than sierpi?ski carpet


Take a square. If you scale it up by a factor of 3 in every direction, you get a figure composed of 9 copies of the original square. We can then define the dimension of the square as log(9)/log(3)=2 (that is, what power of the scaling factor gives you the number of copies).

If you scale the Sierpinski carpet up by a factor of 3 in every direction, you get a figure composed of 8 copies of the original Sierpinski carpet. Therefore its dimension is log(8)/log(3) = 1.89278926071437231130... That's why we call that a fractal.

I have no idea why you still think your image is a fractal. The way I see it, what you plotted is a couple of hundred concentric circles, which when sampled with a regular grid result in a spectacular moiré pattern. It's not like we are saying your image isn't pretty: It just has little to do with fractals.

I found this link: http://www.nahee.com/spanky/www/fractint/circle_type.html (Notice the "not a fractal" part.)

for me i may repeat it seem this is not worse fractal than sierpi?ski carpet


I have no idea why you still think your image is a fractal. The way I see it, what you plotted is a couple of hundred concentric circles, which when sampled with a regular grid result in a spectacular moiré pattern. It's not like we are saying your image isn't pretty: It just has little to do with fractals.

I found this link: http://www.nahee.com/spanky/www/fractint/circle_type.html (Notice the "not a fractal" part.)

I think it is unrelated to sampling on the grid- all in all this is well defined

F(x,y) function for x,y are real, - so sampling to a grid is not important imo, it just blurs the details, dont you think?

Very good info in this link, (i was searching for such references) though here is written ". The resulting image is not a fractal because all detail is lost after zooming in too far. "

Im not sure if this is true, if one will raise the frequenzy of palette

i think the detail depth will probably increase to infinity - so it probably depends how you define this construct

This topic is closed to new replies.

Advertisement