Saturday, October 29, 2016

Contractive Affine Transformations

It is too much of an effort to reproduce the theory behind this but suffice is to give a link to this page and this page. Now I will show you a C-curve I produced using a method called contractive affine transformation in Java OpenGL.

Snapshot:

A small change in the iteration can produce the Dragon curve:
 The change is in the display function:
gl.glBegin(GL2.GL_POINTS);
    for(int i=0;i<100000;i++)
    {
        switch(rand.nextInt(2))
        {
        case 0:
            x1=(x+y)*0.5f;
            y=(-x+y)*0.5f;

            x=x1;
            break;
        case 1:
            x1=(-x+y)*0.5f+1;
            y=(-x-y)*0.5f;

            x=x1;
            break;
        }
        gl.glVertex2f(x, y);
    }
Snapshot:

Here is the source for the C curve.
Another modification I thought would be useful is the fractal "Scroll".
Snapshot:

This is the code to generate it:
 gl.glBegin(GL2.GL_POINTS);
    for(int i=0;i<100000;i++)
    {
        switch(rand.nextInt(2))
        {
        case 0:
            x1=0.693f*x-0.4f*y;
            y=0.4f*x+0.693f*y;

            x=x1;
            break;
        case 1:
            x1=0.346f*x+0.2f*y+0.693f;
            y=-0.2f*x+0.346f*y+0.4f;

            x=x1;
            break;
        }
        gl.glVertex2f(x, y);
    }
    gl.glEnd();

No comments:

Post a Comment