#version 3.8; global_settings {assumed_gamma 1} #declare E = 0.0001; #include "ArrayMacros.inc" #include "functions.inc" //#include "math.inc" #include "rand.inc" #declare Zoom = 1; //768/2; camera { orthographic location right x*image_width up y*image_height //sky y look_at rotate y*0 } light_source { rgb 1} sky_sphere {pigment {rgb 1}} #macro Push (Array, Element, Index) #debug concat ("Pushing <", vstr(3, Element, ", ", 0, 3), "> onto array stack at index ", str (Index, 0, 0), "\n" ) #local Array [Index] = Element; #local Index = Index + 1; #end #macro Splice (Array, Index, IndexValue) #debug "Splicing. \n" #local Temp = array; #local Size = dimension_size (Array, 1)-1; #debug concat (" Original array size = ", str (Size, 0, 0), "\n" ) #local T = 0; #for (i, 0, Size) #if (i = IndexValue) #local i = i + 1; #debug concat (" skipping array index ", str (IndexValue, 0, 0), "\n" ) #else #ifdef (Array [i]) #local Temp [T] = Array [i]; #local T = T + 1; #else #local i = i + 1; #end // end ifdef #end // end if #end #debug concat (" T = ", str (T, 0, 0), "\n" ) #debug concat (" i = ", str (i, 0, 0), "\n" ) #local NewSize = dimension_size (Temp, 1)-1; #debug concat (" New array size = ", str (NewSize, 0, 0), "\n" ) #declare Array = Temp; //#declare Index = Index - 1; #end #declare Width = image_width; #declare Height = image_height; // Step 0 #declare R = 15; #declare k = 30; #declare N = 2; #declare W = R / sqrt (N); #declare Cols = floor (Width / W); #declare Rows = floor (Height / W); #debug concat( "Cols = ", str (Cols, 0, 0), "\n") #debug concat( "Rows = ", str (Rows, 0, 0), "\n") #declare Grid = array [Cols * Rows]; #for (Y, 0, Height, Rows) cylinder {<0, Y, 0>, 0.1 pigment {rgb x}} #end #for (X, 0, Width, Cols) cylinder {, 0.1 pigment {rgb y}} #end //#for (i, 0, Cols*Rows) //#declare Grid [i] = -1; //#end #declare SeedX = seed(1357); #declare SeedY = seed(2468); #declare SeedR = seed(123); #declare SeedA = seed(9753); // Step 1 #declare X = Width/2; //rand (SeedX); #declare Y = Height/2; //rand (SeedY); #declare Pos = ; #declare i = floor (X/W); #declare j = floor (Y/W); #declare Grid [i + j * Cols] = Pos; #declare ActiveIndex = 0; //Push (Active, Pos, ActiveIndex) //ArrayPush (Active, Pos) #declare Active = array [1] {Pos} #macro DrawPoints () #local GridLength = dimension_size (Grid, 1); #local ActiveLength = dimension_size (Active, 1); #debug concat( "1st ActiveLength = ", str (ActiveLength, 0, 0), "\n") #local cycles = 0; #local bailout = GridLength *1.5; //------------------------------------------------------------------------ #while (ActiveLength > 0 & cycles < bailout) #local RandomIndex = floor (RRand (0, ActiveLength, SeedR)); //#debug concat( "ActiveLength = ", str (ActiveLength, 0, 0), "\n") //#debug concat( "RandomIndex = ", str (RandomIndex, 0, 0), "\n") #local Pos = Active [RandomIndex]; #local Found = false; #for (n, 0, k) #local Angle = RRand (0, tau, SeedA); #local Length = RRand (R, 2*R, SeedR); #local PointX = Length * cos (Angle); #local PointY = Length * sin (Angle); #local Point = ; #local Sample = Point + Pos; #local Col = floor (Sample.x/W); #local Row = floor (Sample.y/W); //sphere {Sample, 0.15 pigment {rgb x}} //torus {R , 0.05 pigment {rgb x} rotate x*90 translate Sample} //torus {R*2, 0.05 pigment {rgb x} rotate x*90 translate Sample} #if (Col >= 0 & Row >= 0 & Col < Cols & Row < Rows) #ifndef (Grid[Col + Row * Cols]) #local Valid = true; #local Exit = false; #for (i, -2, 2) #for (j, -2, 2) #local GridIndex = (Col+i) + (Row+j) * Cols; #if (GridIndex > 0 & GridIndex < GridLength) #ifdef (Grid [GridIndex]) #local Neighbor = Grid [GridIndex]; #local D = vlength (Sample - Neighbor); #if (D <= R) #local Valid = false; #else #local Valid = true; #local Exit = true; #end // end if (D < R) #end // end ifdef (Grid [GridIndex]) #end // end if (GridIndex > 0 & GridIndex < GridLength) #if (Exit) #break #end #end // end for j #if (Exit) #break #end #end // end for i #if (Valid) #local GridIndex = Col + Row * Cols; #if (GridIndex >= 0 & GridIndex < GridLength) #local Found = true; #declare Grid [GridIndex] = Sample; //Push (Active, Sample, ActiveIndex) ArrayPush (Active, Sample) //#break #end // end if (GridIndex > 0 & GridIndex < GridLength) #end // end if (Valid) #if (Found) #else //Splice (Active, ActiveIndex, RandomIndex) ArrayDeleteAt (Active, RandomIndex) #end // end (!Found) #local ActiveLength = dimension_size (Active, 1); #end // end ifndef (Grid[Col + Row * Cols]) #end // end if (Col > -1 & Row > -1 & Col < Cols & Row < Rows) //#debug concat( "Sample test = ", str (n, 0, 0), "\n") #end // end for (n, 0, k) #local cycles = cycles + 1; //#debug concat( "cycle = ", str (cycles, 0, 0), "\n") #end // end while //------------------------------------------------------------------------ #local GridLength = dimension_size (Grid, 1)-1; #debug concat( "Cycles = ", str (cycles, 0, 0), "\n") #debug concat( "GridLength = ", str (GridLength, 0, 0), "\n") #debug concat( "ActiveLength = ", str (ActiveLength, 0, 0), "\n") #for (i, 0, GridLength) #ifdef (Grid [i]) sphere {Grid [i], R/4 pigment {rgb z*0.2}} //torus {R, 0.2 pigment {rgb 0} rotate x*90 translate Grid [i]} #end #end #for (i, 0, ActiveLength) //sphere {Active [i], 0.5 pigment {rgb x}} #end #end DrawPoints ()