#version 3.8; global_settings {assumed_gamma 1} #declare E = 0.0001; #include "functions.inc" //#include "math.inc" #include "Rand.inc" #declare Zoom = 10; //768/2; camera { orthographic location right x*image_width/Zoom/1.9 up y*image_height/Zoom/1.9 //sky y look_at rotate y*0 } light_source {<0, 0, -image_width> 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/Zoom/2; #declare Height = image_height/Zoom/2; // Step 0 #declare R = 10; #declare k = 30; #declare N = 2; #declare W = R / sqrt (N); #declare Cols = floor (Width / W); #declare Rows = floor (Height / W); #declare Grid = array [Cols * Rows]; #declare Active = array; #for (Y, 0, Height) cylinder {<0, Y, 0>, 0.1 pigment {rgb x}} #end #for (X, 0, Width) 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) #macro DrawPoints () #local GridLength = dimension_size (Grid, 1)-1; #local ActiveLength = dimension_size (Active, 1); #debug concat( "1st ActiveLength = ", str (ActiveLength, 0, 0), "\n") #while (ActiveLength > 0) #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); #local Unused = false; #if (Col > -1 & Row > -1 & Col < Cols & Row < Rows) #ifndef (Grid[Col + Row * Cols]) #local Valid = true; #for (i, -1, 1) #for (j, -1, 1) #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; #end // end if #end // end if #end // end if #end // end for j #end // end for i #if (Valid) #local GridIndex = (Col+i) + (Row+j) * Cols; #if (GridIndex > 0 & GridIndex < GridLength) #local Found = true; #declare Grid [GridIndex] = Sample; Push (Active, Sample, ActiveIndex) // #break #end // end if #end // end if #if (!Found) Splice (Active, ActiveIndex, RandomIndex) #end #local ActiveLength = dimension_size (Grid, 1)-1; #end // end ifndef #end // end if #end // end for n #end // end while #local GridLength = dimension_size (Grid, 1)-1; #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], 0.2 pigment {rgb 0}} torus {R/W, 0.2/W pigment {rgb 0} rotate x*90 translate Grid [i]} #end #end #for (i, 0, ActiveLength) sphere {Active [i], 0.2 pigment {rgb x}} #end #end DrawPoints ()