#version 3.8; global_settings {assumed_gamma 1.0 } #default {finish {emission 1}} // Make render fill the screen #declare AspectX = image_width; #declare AspectY = image_height; #declare Fraction = min (AspectX, AspectY); camera { orthographic right x*image_width up y*image_height location look_at } //sky_sphere {pigment {rgb 1}} light_source {< 0, 0, -550> rgb 1} #declare Line = 0.25; #declare Order = 4; // 9 #declare N = pow (2, Order); #declare Total = N * N; #debug concat ("Total = ", str (Total, 0, 0), " \n") #declare Points = array [4] { <0, 0, 0>, <0, 1, 0>, <1, 1, 0>, <1, 0, 0> } #declare Path = array; #macro Hilbert (I) #local index = bitwise_and (I, 3); #local V = Points [index]; #for (j, 1, Order) // bit shift right by 2 digits #local I = I/4; #local index = bitwise_and (I, 3); //#local index = mod (I, 2); #local len = pow (2, j); #switch (index) #case (0) #local V = ; #break #case (1) #local V = ; #break #case (2) #local V = ; #break #case (3) #local V = ; //#local V = V + x*len; #break #end #end V #end #for (P, 0, Total-1) #local Len = Fraction/N; #local Offset = Len / 2; //#declare Path [P] = Hilbert (P) * + ; // Passing in loop counter identifier by reference = infinite loop! #local PP = P; #declare Path [PP] = Hilbert (PP) * + ; #end #macro Draw () #local Pathlength = dimension_size (Path, 1)-1; #for (i, 0, Pathlength) #local Current = Path [i]; #local Color = ; union { sphere {Current Line} #if (i > 0) cylinder {Last, Current Line } #end pigment {rgb Color} } #local Last = Current; #end #end Draw ()