Hi,
Uh, I wonder if there is a x,y function to get the "colour" of every hexagon that you find after folding. It can be so very cool.
In the case of hexagonal tiling, a more simple appreach is to convert to a sheared coordinates system then find the nearest integer coordinates point.
static a[2]={1,0};
static b[2]={0.5,0.5*sqrt(3)};
(x,y){
inthex(&x,&y);
abs(sin(3*x+y*10))//gen a color
}
inthex(&x,&y){//rouds to nearest hexagonal grid "integer" coordinates
//convert to "sheared" coodinates (x,y) -> (l,m) by solving the system:
//x=l*a[0]+m*b[0];
//y=l*a[1]+m*b[1];
idet=1/(a[0]*b[1]-b[0]*a[1]);
m=(-x*a[1]+y*a[0])*idet;
l=(x*b[1]-y*b[0])*idet;
m0=floor(m);l0=floor(l);//coordinates of the lower left nearest "integer" corner
//find nearest "integer" corner
d2=(l0*a[0]+m0*b[0]-x)^2+(l0*a[1]+m0*b[1]-y)^2;
nl=l0; nm=m0;nd=d2;
d2=((l0+1)*a[0]+m0*b[0]-x)^2+((l0+1)*a[1]+m0*b[1]-y)^2;
if(d2<nd) {nl=l0+1; nm=m0;nd=d2;}
d2=(l0*a[0]+(m0+1)*b[0]-x)^2+(l0*a[1]+(m0+1)*b[1]-y)^2;
if(d2<nd) {nl=l0; nm=m0+1;nd=d2;}
d2=((l0+1)*a[0]+(m0+1)*b[0]-x)^2+((l0+1)*a[1]+(m0+1)*b[1]-y)^2;
if(d2<nd) {nl=l0+1; nm=m0+1;nd=d2;}
x=nl; y=nm;
}
In the picture below, I've drawn the fundamental domain of 3-3-3 triangle group in the right side. if you draw from the center of that fundamental domain three lines perpendicular to it's edges you will obtain an hexagonal grid. The three lines divide the fundamental domain into three regions with a different color each. Therefor, you get a 3 colored hexagonal tiling. This is basically what I used in the fragmentarium script presented here:
http://www.fractalforums.com/fragmentarium/triangle-groups-tessellation/ .
The two triangles at the left are the fundamental domain of 2-3-6 triangle group and it's mirror image about the diagonal (I could also have mirrored it about any other two edges). The procedure is to count the number of folding (necessary to go inside the fundamental domain) then give a color dependent on the parity of folding number to the bigger part (the fundamental domain is divided in two parts by the line perpendicular to the diagonal).
In my previous post I was referring to a general (too general) method of using subgroups of the triangle group. In the euclidean case, Most of the wallpaper groups (and friese groups) are subgroups of triangle groups. I haven't worked out the math though.