I did a far more complicated version with extra rotations in fragmentarium, if McLarekin can translate it... eventually.
Doy.. here is a Kaleidoscopic rotation demo- you can do multiple 3d polyfolds if you know multiple axes of symmetry and know the tricks to align them. I'll write a tutorial if someone wants me to.
If Luca checks it for redundancies, it basically does the polyfold stuff, but has extra cool Kaleidoscopic rotations thrown into the mix.
If you want to avoid additional trig functions, set EXTRA_TRIG_FUNCTIONS=false, otherwise do it the extra trig function way.
If you have an even number of polyfolds, set EvenFolds true for... less rotations.
bool EvenFolds = set true if Folds is even
float Rotate= kaleidscopic rotation variable...
float FoldAdjust= adjustment so axis of symmetry (if you use an object with symmetry) is aligned correctly
float folds= number of folds
bool EXTRA_TRIG_FUNCTION=false;
float rxy;
float ratrack=pi2-pi2/folds; //pi2 is 2*pi
float rotadjust=-pi/folds + FoldAdjust; // I called folds splits in my original code...
// I called them splits because I didn't know
float pintrack=pi/folds; //what they were called.....
float pi2splits=pi2/folds;
float i=0.0; //why a float?? I was doing something with it...
float omega=atan(z.y,z.x);
if (omega<0.0) {omega+=pi2;} //so angle goes from 0 to 2pi instead of having negative part
float rotate=0;
//I only wanted to do the kaleidoscope rotations on specific iterations
// doing multiple polyfolds... you can do it every iteration or whatever- for cool effects
// only do it on specific iterations- I was making kaleidoscopes out of 2d polyfolding
if (RotateIter==n) {rotate=Rotate;} //only do the rotation on a specific iteration
while (omega>pi2folds && i<floor(folds+1.0)) {
i+=1.0;
if (EvenFolds) {rotate*=-1;} //if you have an even number of folds, you can do 1/2 as
//many rotations- it's sort of cool
if (!EXTRA_TRIG_FUNCTION) { //that is a NOT "!" :D
rotadjust+=ratrack;
pintrack+=pi2folds;
omega-=pi2folds;
} else { //with extra trig function, you don't need the above... just do the above instead
omega-=pi2folds;
}
}
if (EXTRA_TRIG_FUNCTION) { // don't do this unless you absolutely love using transcendental functions
z=length(z)*vec2(cos(omega),sin(omega));
}
// if you don't have an even number of folds, you have to make an even number of rotations like the following:
if (omega>pi2folds*.5 && !EvenFolds) {rotate*=-1;}
// pintrack is used to shift the fold center outwords- images follow
vec2 z2=vec2(cos(pintrack),sin(pintrack));
// splitrad is the distance from the center that the folds are shifted outwards
z.xy-=z2*splitrad;
rxy=length (z.xy);
// rotadjust keeps every duplicate aligned correctly.
omega=atan(z.y,z.x)+rotadjust+rotate+FoldAdjust;
z.xy=rxy * vec2(cos(omega),sin(omega));
return z;
Did a 2d kaleidoscope using the above function:
And other stuff (polyfolds, and a modified boxtiling function):