/*-----------------------------------------------------------------*\ | Clock mixed solution |Set the initial_frame and the final_frame. |let the clock be INTEGER |That's the key to it. Clock goes from 1 to 360 and all is jolly. | Initial_Frame = Initial_Clock = 0 | Final_Frame = Final_Clock = 20 \*---------------------------------------------------------------- */ #version 3.1; #include "colors.inc" global_settings { assumed_gamma 1.0 } #declare allScale = 1; //>3 is good for high res meshes. //This is the global scale modifier. use with care. (resolution of the triangles) #declare FileName = "plas" //our Filename base. to this is XXXX added, where XXXX is the frame number. #declare WriteFile = false; //Want a file ? #declare Display = true; //Want the display? (if you are preparing a batch of includes, this will speed things up. //Modify theese with trial and error. for the lazy, modify allScale #declare Diag = int(70*allScale); //increase this, decrease below. repeat until happy. *2 and *(3/4) isss a good ratio #declare dist = int(15/allScale); //A "distance" modifier. scale of the "plasma", higher = denser #declare hScale = int(11*allScale); #declare PalLvl = 256; //n*2. must be divideable with 4 and a multiple of 2 #declare PalLvl = 1024*3; #declare hLvl = 1024*3; //Same as Pal Lvl, except for height offset. #declare See = seed(1999); //Don't bother. #declare maxX = int(sqrt(pow(Diag,2)/2)); //Grid resolution in X #declare maxY = int(sqrt(pow(Diag,2)/2)); //Ditto, Y #debug concat("X @ Y: ",str(maxX,0,0)," @ ",str(maxY,0,0),"\n") #declare FRAME = int(clock); #declare hLvldiv8 = hLvl/8.0; #declare PalLvld8 = PalLvl/8.0; #declare P = array[maxX+1][maxY+1] //Plasma heights #declare G = array[maxX+1][maxY+1] //Plasma colours //------------ End initzialize. //------Macro to create a string from a vector. #declare Precision = 5; #macro v2str(vVector) concat("<", str(vVector.x,-1,Precision), ",", str(vVector.y,-1,Precision), ",", str(vVector.z,-1,Precision),">") #end #if(WriteFile) #declare FileName = concat(FileName,str(FRAME,-4,0),".frm") #debug concat("Output to file: ",FileName,"\n") #fopen File FileName write #write (File,"#version 3.1;") #write (File,"global_settings { assumed_gamma 1.0 }\n") #write (File,"camera{ location",v2str(<0,-Diag/2,-10>)," look_at ",v2str(<0,maxX/4,0>),"}\n") #write (File,"light_source{ <0,0,-500> colour rgb 1 shadowless }\n") #else #debug "NOT writing to file\n" #end camera { /*camera { location<0,0,-103> look_at<0,0,0>} */ location <0,-Diag/2,-10> look_at <0,maxX/4,0> } light_source { <0,0,-500> colour rgb 1 shadowless } //-------------Misc funstuff #debug "Building percentage meter... \n" #declare ps = " " #declare N = Diag; #while(N>0) #declare ps = concat(".",ps) #declare N = N - 1; #end #debug "...done\n" #macro percent(N) #debug concat ("\r", substr(ps, 1, N)) #end //------------------------------Loop variables //Time lookups. Loop theese for a animation. #declare T = array[4] {0,360,0,360} #declare L = array[4] {0,360,0,360} #debug "Calculating the frame... \n" #declare N = FRAME; #while(N>0) //The plasma movement #if(T[0]>=359) #declare T[0]=000; #else #declare T[0]=T[0]+1; #end #if(T[1]<=002) #declare T[1]=360; #else #declare T[1]=T[1]-2; #end #if(T[2]>=357) #declare T[2]=000; #else #declare T[2]=T[2]+3; #end #if(T[3]<=004) #declare T[3]=360; #else #declare T[3]=T[3]-4; #end //The ground movement #if(L[0]<=001) #declare L[0]=360; #else #declare L[0]=L[0]-1; #end #if(L[1]>=358) #declare L[1]=000; #else #declare L[1]=L[1]+2; #end #if(L[2]<=003) #declare L[2]=360; #else #declare L[2]=L[2]-3; #end #if(L[3]>=356) #declare L[3]=000; #else #declare L[3]=L[3]+4; #end #declare N = N - 1; #end #debug concat("...done\nFrame ",str(FRAME,0,0),"\n" ) //--------------------- Height lookup #debug "Height data... \n" #declare Harr = array[hLvl+1] #declare N = 0; #while(N<(hLvl/2)) //Build up. #declare Harr[N] = <0, 0/*+N/hLvl*8*/, N/hLvl*hScale>; #declare N = N + 1; #end #while(N<(hLvl)+1) //And down #declare Harr[N] = <0, 0/*+(hLvl-N)/hLvl*8*/, (hLvl-N)/hLvl*hScale>; #declare N = N + 1; #end #debug "...done\n" //----------------------------------Palette lookup #if(WriteFile) #write(File, "#declare pal=array[", str(PalLvl+1,-3,0),"]\n") //Write the palette lookup. Why? Cause we want a textured mesh. #end #debug "Palette loookup...\n" //First build all the vectors. Then build the lookups. #declare ClrPal = array[PalLvl+1] #declare pal = array[PalLvl+1] #declare N = 0; #while(N<(PalLvl/4)) //Palette part 1 (Blue to red) #declare ClrPal[N] = /PalLvl ; #declare pal[N] = texture{pigment{colour rgb ClrPal[N]}} #declare N = N + 1; #end #while(N<2*(PalLvl/4)) //Palette part 2 (Red to yelllow ) #declare ClrPal[N] = /PalLvl; #declare pal[N] = texture{pigment{colour rgb ClrPal[N]}} #declare N = N + 1; #end #while(N<3*(PalLvl/4)) //Palette part 3 (yelllow to red) #declare ClrPal[N] = /PalLvl; #declare pal[N] = texture{pigment{colour rgb ClrPal[N]}} #declare N = N + 1; #end #while(N/PalLvl; #declare pal[N] = texture{pigment{colour rgb ClrPal[N]}} #declare N = N + 1; #end #debug "...done\n" #if(WriteFile) #debug "Writing palette to file...\n" #declare N = 0; #while(N + Harr[ getH(X+L[0]) + getH(X+L[1]) + getH(Y+L[2]) + getH(Y+L[3]) ] ) #end //return a palette entry #macro gPal(X,Y) ( getC(X+T[0]) + getC(X+T[1]) + getC(Y+T[2]) + getC(Y+T[3]) ) #end //-------------------------- //Speed things up with a lookup table. #declare N = maxX+360; #debug concat("Building 2x", str(N,-3,0)," entries cosine lookup table...\n") #declare Hcos = array[N+1] #declare Pcos = array[N+1] #while(N>0) #declare Hcos[N] = cos(radians(N*dist))*hLvldiv8+hLvldiv8; #declare Pcos[N] = cos(radians(N*dist))*PalLvld8+PalLvld8; #declare N = N - 1; #end #debug "...done\n" #debug "Lookup plasma and texture...\n\n" #if(WriteFile) #declare SP = array[maxX+1][maxY+1] //Plasma heights in string #declare SG = array[maxX+1][maxY+1] //Plasma colours in string #declare X = 0; #while(X + Harr[ Hcos[(X+L[0])]+ Hcos[(X+L[1])]+ Hcos[(Y+L[2])]+ Hcos[(Y+L[3])] ]; #declare P[X][Y] = Ptmp; #declare SP[X][Y] = v2str(Ptmp) #declare Gtmp = Pcos[X+T[0]] + Pcos[X+T[1]] + Pcos[Y+T[2]] + Pcos[Y+T[3]]; #declare G[X][Y] = Gtmp; #declare SG[X][Y] = str(Gtmp,-1,10) #declare Y = Y + 1; #end #declare X = X + 1; #end #else #declare X = 0; #while(X + Harr[ Hcos[(X+L[0])]+ Hcos[(X+L[1])]+ Hcos[(Y+L[2])]+ Hcos[(Y+L[3])] ]; #declare G[X][Y] = Pcos[X+T[0]] + Pcos[X+T[1]] + Pcos[Y+T[2]] + Pcos[Y+T[3]]; #declare Y = Y + 1; #end #declare X = X + 1; #end #end #debug "...done\n" #if(WriteFile) #debug "Writing triangle mesh...\n\n" #write( File, "mesh{\n") #declare X = 0; #while(X<(maxX-1)) percent(X) #declare Y = 0; #while(Y<(maxY-1)) #write(File, concat("triangle{", SP[X+0][Y+0], ",", SP[X+1][Y+0], ",", SP[X+0][Y+1], " texture{pal[", SG[X][Y], "]}}\n")) #write(File, concat("triangle{", SP[X+1][Y+0], ",", SP[X+1][Y+1], ",", SP[X+0][Y+1], " texture{pal[", SG[X][Y], "]}}\n")) #declare Y = Y + 1; #end #declare X = X + 1; #end #write(File, "translate "v2str(-1/2*),"\n}\n\n") #fclose File #debug "...done\n" #debug "Removing temporary variables...\n" #undef SP #undef SG #debug "...done\n" #end #if(Display) #debug "Creating triangle mesh to memory...\n\n" mesh { #declare X = 0; #while(X<(maxX-1)) percent(X) #declare Y = 0; #while(Y<(maxY-1)) triangle { P[X][Y], P[X+1][Y], P[X][Y+1] texture{pal[G[X][Y]]} } triangle { P[X+1][Y], P[X+1][Y+1], P[X][Y+1] texture{pal[G[X][Y]]} } #declare Y = Y + 1; #end #declare X = X + 1; #end translate -1/2* } #debug "...done\n" #end #debug "\nPlasma complete\n"