Tuesday, November 27, 2012

a seven dimensional work in progress

As a direct rezult of a FB update here is my unfinished POV-Ray code,
like with no spell checking or anything:



/*
while in the begining I thought to add this to wikipedia as a wasy to describe multidimensional space
I was actually more interested in researching which diods would best correspont to the human eye.
The ones that emmittid photons at the wavelength that our cone photoreceptors can most easely convert into electerical energy for interpretation by the brain.

You see I'm a chemist and the most fun thing about chemistry is the funky colours, particularly the organometalic coordination complexes.

but in the end this document became programming practice, particularly for my comments. And when I realised that I tried to make the program more effecient too.




*/



//~~~~~~~~~~~~~~~~~~~~~~~~~~
//Above: intro
//Below: initial setup
//~~~~~~~~~~~~~~~~~~~~~~~~~~




#include "colors.inc"
#include "math.inc"
#include "colors.inc"
#include "textures.inc"
#include "shapes.inc"
#include "metals.inc"
#include "glass.inc"
#include "woods.inc"

//for a box centered on the origen
#declare corner1x = 0;
#declare corner1y = 0;
#declare corner1z = 0;
#declare corner2x = 0;
#declare corner2y = 0;
#declare corner2z = 0;

//Initial_Frame = 1
//Final_Frame = 60 //create 60 frames for a gif, 1200 for final
// Time needs to run from 1 to 60 seconds
// then I can repeate the images twice to show 2 cycles in the time dimension
//for testing purposes only. when this works check trigometry, then use time to make a movie.
#declare Time = 30.0;
//45=0, 35=0.25 0/30/60=0.5, 5/25=0.75, 15=1
//rsine = gsine = bsine = xsine = ysine = zsine = 0.5*sin(0.10472*(Time +0))+0.5


#if (1)    //initially I was commenting out parts of code but then I realised an if     statement with a boolian toggle would be quicker.

    //clock moves from 0-1, so multiply by 60 to get the new range.
    //Final_Frame = 6;        //generates number of frames, less is faster more is     smoother
    #declare Time = 100*clock; //I really dont know how to et the FPS, maybe thats in a diferent program?
    //Cyclic_Animation= On;    //this means that ot wont end on the same fram that     it starts with, making animation loops easier
    //may need to install redShark again to render this.
#else
    //the clock is not setup so only one frame will be rendered
#end


//timeless testing
#declare rsine =0.5; //for red
#declare gsine =0.5; //for green
#declare bsine =0.5; //for blue
#declare xsine =0; //for the x axis
#declare ysine =0; //for the y axis
#declare zsine =0; //for the z axis
/*
being the first place I declare these variables I should explain
all the dimensional translations are based on a sine waveform
and all should stay within the bounds of 0-1, thus rsine = xsine = 1 would make
the red color dimension 100% and move the x axis as far away from the origen as possible.
*/


//~~~~~~~~~~~~~~~~~~~~~~~~~~
//above: initial setup
//Below: camera, lighting, simple static shape. The begining of the scene
//~~~~~~~~~~~~~~~~~~~~~~~~~~


camera {
   location <1, 1, -1>
 //  direction <0, 0,  2.25>
 //  right x*1.33
   look_at <0,0,1>
}

//lighting
//light_source{ <2.0,0.5,0.5> color White Jitter = 0}
light_source{ <0.5,0.5,-0.5> color White }
light_source{ <1,1,-1> color White }
//light_source{ <2.0,2.0,-1.0> color White Jitter = 0 }
//need to turn jitter off because it is unhelpfull for animated sequences

// Uncomment the area lights only if you've got lots of time.
#declare Dist=80.0;
light_source {< -50, 25, -50> color White
     fade_distance Dist fade_power 2
//   area_light <-40, 0, -40>, <40, 0, 40>, 3, 3
//   adaptive 1
   jitter
}
sky_sphere {
    pigment {
        gradient y
        color_map {
            [0, 1  color Gray50 color Gray80]
        }
    }
}


//axis gridlines should lay embedded in the planes
//This is what I played with to make the textures work and to hose where the image would be
//in relation to the camera and lights for example.
//generally I find the first object the most callengin to make visable
cylinder { <0,0,0>, <1,0,0>, 0.101 texture { T_Glass4 } interior {I_Glass caustics 1} }
cylinder { <0,0,0>, <0,1,0>, 0.101 pigment{ White }}
cylinder { <0,0,0>, <0,0,1>, 0.101
        texture { T_Wood10
            finish { specular 0.5 roughness 0.005 ambient 0.35 }
            translate x*1
            rotate <30, 10, 20>
        }
 }

//~~~~~~~~~~~~~~~~~~~~~~~~~~
//above: camera, lighting, simple static shape. The begining of the scene
//Below: trigonimetry calculations
//~~~~~~~~~~~~~~~~~~~~~~~~~~





//Simple sine formula
// All dimensions move the same
//Amplitude * Sin( Frequency * (time + Phase)) + Range
#declare xamplitude = 0.5;
#declare xfrequency = pi/30;
#declare xphase = 0;
#declare yamplitude = 0.5;
#declare yfrequency = pi/30;
#declare yphase = 0;
#declare zamplitude = 0.5;
#declare zfrequency = pi/30;
#declare zphase = 0;
#declare ramplitude = 0.5;
#declare rfrequency = pi/30;
#declare rphase = 0;
#declare gamplitude = 0.5;
#declare gfrequency = pi/30;
#declare gphase = 0;
#declare bamplitude = 0.5;
#declare bfrequency = pi/30;
#declare bphase = 0;


//calculating it out

#declare rsine = ramplitude * sin( rfrequency * ( Time + rphase))+0.5;
#declare gsine = gamplitude * sin( gfrequency * ( Time + gphase))+0.5;
#declare bsine = bamplitude * sin( bfrequency * ( Time + bphase))+0.5;
#declare xsine = xamplitude * sin( xfrequency * ( Time + xphase))+0.5;
#declare ysine = yamplitude * sin( yfrequency * ( Time + yphase))+0.5;
#declare zsine = zamplitude * sin( zfrequency * ( Time + zphase))+0.5;

/*
below I have six different scenarios where each dimension moves different to the others
they only change the parts required for the pocture, otherwise they are the same as the simple sine above.
To change what is rendered uncomment one of the blocks, edit the number below

*/

#declare Graph_adjustment = 4;

#if (Graph_adjustment = 1)
//1    Amplitude modulation
#declare xamplitude = 0.5/6;
#declare yamplitude = 0.5/6*2;
#declare zamplitude = 0.5/6*3;
#declare ramplitude = 0.5/6*4;
#declare gamplitude = 0.5/6*5;
#declare bamplitude = 0.5;

#else #if (Graph_adjustment = 2)

//2    frequency modulation (Repeatable cycle)
#declare rfrequency = PI()/30;
#declare gfrequency = PI()/30*5;
#declare bfrequency = PI()/30*3;
#declare xfrequency = PI()/30*6;
#declare yfrequency = PI()/30*2;
#declare zfrequency = PI()/30*4;

#else #if (Graph_adjustment = 3)

//3    frequency modulation (smaller Hz)
#declare rfrequency = PI()/30*2;
#declare gfrequency = PI()/30;
#declare bfrequency = PI()/20;
#declare xfrequency = PI()/30*2+PI()/20;
#declare yfrequency = PI()/20*2;
#declare zfrequency = PI()/30+PI()/20;

#else #if (Graph_adjustment = 4)

//4    Phase modulation (uniform distortion)
#declare rphase = 10;
#declare gphase = 50;
#declare bphase = 30;
#declare xphase = 60;
#declare yphase = 20;
#declare zphase = 40;

#else #if (Graph_adjustment = 5)

//5    Phase modulation (heilical distortion)
#declare rphase = 0;
#declare gphase = 6;
#declare bphase = 12;
#declare xphase = 18;
#declare yphase = 24;
#declare zphase = 30;

#else #if (Graph_adjustment = 6)

//6    ~~~~~Really complex
/*
I practiced these in an excell document to see what each line looks like
the simple x,y image was easy to follow even with 6 lines ontop of eachother
I picked some equations from above that I shought would be visible and also
repeatable, starting and ending at 50%, with no sharp movements.
*/
#declare ramplitude = 0.4;
#declare rfrequency = pi/15;
#declare rphase = 10;
#declare gamplitude = 0.4;
#declare gfrequency = pi/30;
#declare gphase = 40;
#declare bamplitude = 0.5;
#declare bfrequency = pi/15;
#declare bphase = 40;

#declare rsine = ramplitude * sin( rfrequency * ( Time + rphase))+0.5;
#declare gsine = gamplitude * sin( gfrequency * ( Time + gphase))+0.5;
#declare bsine = bamplitude * sin( bfrequency * ( Time + bphase))+0.5;

//x average of small + simple
#declare xsine = ((0.1 * sin( pi/3  * ( Time + 1))+0.5)+xamplitude * sin( xfrequency * ( Time + xphase))+0.5 )/2 ;
//y average of 0.21Hz + simple
#declare ysine = ((0.5 * sin( pi/15 * ( Time + 0))+0.5)+yamplitude * sin( yfrequency * ( Time + yphase))+0.5 )/2 ;
//z average of x and y
#declare zsine = (xsine + ysine)/2 ;
//*/
//~~~~~end of really complex

#else //nothing here so the variables are never changed from the simple sine at the begining
#end #end #end #end #end #end// need an end here for each of the if statements

//protected untill the manual formula is not nesescary
//this uses time and will take ~60 times longer to generate
//The new location
#declare rsine = ramplitude * sin( rfrequency * ( Time + rphase))+0.5;
#declare gsine = gamplitude * sin( gfrequency * ( Time + gphase))+0.5;
#declare bsine = bamplitude * sin( bfrequency * ( Time + bphase))+0.5;
#declare xsine = xamplitude * sin( xfrequency * ( Time + xphase))+0.5;
#declare ysine = yamplitude * sin( yfrequency * ( Time + yphase))+0.5;
#declare zsine = zamplitude * sin( zfrequency * ( Time + zphase))+0.5;


//~~~~~~~~~~~~~~~~~~~~~~~~~~
//Above: trigonimetry calculations
//Below: assembelling the dimensional cube
//~~~~~~~~~~~~~~~~~~~~~~~~~~



//finally the focus of all this code
//this is the cube, rather than phasing the color and transllating an object
//each frame will render a new cube in a new location.
//thus it is easier to color but I'll rely on the FPS to pretend it is mooving.
#declare  corner1x = xsine - 0.15;
#declare  corner1y = ysine - 0.15;
#declare  corner1z = zsine - 0.15;
#declare  corner2x = xsine + 0.15;
#declare  corner2y = ysine + 0.15;
#declare  corner2z = zsine + 0.15;

//by making this a light source I dont have to worry about any radiosity effects
//I dont want the cubes color to be effected by the background.
light_source
{ <0,0,0> rgb <rsine, gsine,bsine>
  looks_like
  {

        box {    <corner1x,corner1y,corner1z>,
            <corner2x,corner2y,corner2z>
            texture {pigment{rgb <rsine, gsine,bsine>} }
        }
        finish { ambient 1 }
  }
}


//far corner box
// was a simple test to get the box to work at all
/*
box {
        <-0.5,-0.5,-0.5>
        <0.5,0.5,0.5>
    texture {pigment{Grey}}
    scale 0.2
    translate <1,1,1>
}
*/



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Above: assembelling the dimensional cube
//Below: background and RGB phase trasition
//~~~~~~~~~~~~~~~~~~~~~~~~~~


//background
//will try fading in and out to show the color witout being a pastell
//hopefully then scaling the z plane from pure blue to totally black
plane {x,0 texture {pigment{rgb <rsine,0,0> } }}
plane {y,0 texture {pigment{rgb <0,gsine,0> } }}
plane {z,1 texture {pigment{rgb <0,0,bsine> } }}
//other than that I could put slider bars somewhere