AzoftSpotlightRandomness Factor in Computer Graphics

Randomness Factor in Computer Graphics

By Sergey Kalantyr on January 24, 2011

I am particularly interested in computer graphics and I notices that a combination of rules and randomness can unexpectedly result in very beautiful things.

On the one hand computer graphics is obvious when you look at such image, on the other hand randomness factor makes these pictures unique and unpredictable. One more thing that I noticed is that multiple repetition of plain forms completes harmonic pictures.  Like many programmers I've written much painting code. I started in the far 1993 with Basic for Spectrums, then Pascal, ะก++. Computer screens become better and better, resolution becomes bigger and bigger, processors become faster and I decided to «revive the customs of the old days» I wrote my next "electric artist" at C# (using GDI+). Algorithm is easy:

  1. Make random edge line of a random color; 01 Randomness Factor in Computer Graphics
  2. Make multiple duplicates from it gradually turning it around "local" center, so we get a "circle"; 02 Randomness Factor in Computer Graphics
  3. Duplicate this "circle" around a "common" center also turning it around – you get a layer; 03 Randomness Factor in Computer Graphics
  4. Using same method create some "layers" superimposing them at each other. 04 Randomness Factor in Computer Graphics

That's it. Ready. If you have a wish you can make a little postredaction later. The code is easy:

Parameters.Color = GetRandomColor();

var stars = new Star[Parameters.Random.Next(Parameters.MinStarCount, Parameters.MaxStarCount)];
for (var i = 0; i < stars.Length; i++)
{
    stars[i] = new Star();
    stars[i].GenerateRandom();
}

progressBar.Maximum = stars.Length + 1;
var bitmap = new Bitmap(Parameters.PictureSide, Parameters.PictureSide);
progressBar.Increment(1);

using (var gr = Graphics.FromImage(bitmap))
{
    gr.SmoothingMode = SmoothingMode.HighQuality;
    gr.Clear(Color.Empty);
    gr.TranslateTransform((float)bitmap.Width / 2, (float)bitmap.Height / 2);
    foreach (var star in stars)
    {
        star.Draw(gr);
        progressBar.Increment(1);
    }
}
pictureBox.Image = bitmap;

and

public void Draw(Graphics gr)
{
    var rad = Parameters.PictureSide / 2;
    float radius = Parameters.Random.Next(Splines.Spline.MaxRadius, rad - Splines.Spline.MaxRadius);

    try
    {
        Splines.Start();

        float phase = Parameters.Random.Next(360);
        var oldMatrix = gr.Transform;
        for (var i = 0; i < RayCount; i++)
        {
            var angle = 360f * (i / (float)RayCount);
            gr.RotateTransform(phase + angle);
            gr.TranslateTransform(radius, 0);
            Splines.Draw(gr);
            gr.Transform = oldMatrix;
        }
    }
    finally
    {
        Splines.Stop();
    }
}
 
and
public void Draw(Graphics gr)
{
    var oldMatrix = gr.Transform;
    for (var i = 0; i < _rotateCount; i++)
    {
        var angle = 360f * (i / (float)_rotateCount);
        gr.RotateTransform(angle);
        Spline.Draw(gr);
        gr.Transform = oldMatrix;
    }
}

Compile it for .NET 4 (run at Win7 64-bit). A maximal image resolution is 460 megapixels (a square that has an edge 22 thousand pixels). Each picture needs some seconds to be generated.

Of course not all combinations of random parameters are successful. I can choose approximately two best pictures out of ten. Which means that in 15 minutes it is possible to generate some dozens of unique images. Recently I made a gallery of such images at Silverlight using DeepZoom Here are examples of images made with the algorithm described above: 331818 Randomness Factor in Computer Graphics 331819 Randomness Factor in Computer Graphics 331823 Randomness Factor in Computer Graphics 331825 Randomness Factor in Computer Graphics 331827 Randomness Factor in Computer Graphics 331828 Randomness Factor in Computer Graphics 331833 Randomness Factor in Computer Graphics 331830 Randomness Factor in Computer Graphics Here is an app compiled for experiments. If you are interested I can send you the code. Now all parameters are directly in the code. You will need dotNet Framework 4, size of generated image — 4096 x 4096 pixels. I did it for myself – interface is minimalistic. Click at the image to generate a new one. The rest is in menu.


You can check out other images and graphs by Sergey Kalantyr on his official web site


Related articles

Enhanced by Zemanta