+ switch (variation)
+ {
+ case 0: /* sinusoidal */
+ nx = sin(nx);
+ ny = sin(ny);
+ break;
+ case 1: /* complex */
+ {
+ double r2 = nx * nx + ny * ny + 1e-6;
+ nx = nx / r2;
+ ny = ny / r2;
+ }
+ break;
+ case 2: /* bent */
+ if (nx < 0.0)
+ nx = nx * 2.0;
+ if (ny < 0.0)
+ ny = ny / 2.0;
+ break;
+ case 3: /* swirl */
+ {
+ double r = (nx * nx + ny * ny); /* times k here is fun */
+ double c1 = sin(r);
+ double c2 = cos(r);
+ double t = nx;
+
+ if (nx > 1e4 || nx < -1e4 || ny > 1e4 || ny < -1e4)
+ ny = 1e4;
+ else
+ ny = c2 * t + c1 * ny;
+ nx = c1 * nx - c2 * ny;
+ }
+ break;
+ case 4: /* horseshoe */
+ {
+ double r, c1, c2, t;
+
+ /* Avoid atan2: DOMAIN error message */
+ if (nx == 0.0 && ny == 0.0)
+ r = 0.0;
+ else
+ r = atan2(nx, ny); /* times k here is fun */
+ c1 = sin(r);
+ c2 = cos(r);
+ t = nx;
+
+ nx = c1 * nx - c2 * ny;
+ ny = c2 * t + c1 * ny;
+ }
+ break;
+ case 5: /* drape */
+ {
+ double t;
+
+ /* Avoid atan2: DOMAIN error message */
+ if (nx == 0.0 && ny == 0.0)
+ t = 0.0;
+ else
+ t = atan2(nx, ny) / M_PI;
+
+ if (nx > 1e4 || nx < -1e4 || ny > 1e4 || ny < -1e4)
+ ny = 1e4;
+ else
+ ny = sqrt(nx * nx + ny * ny) - 1.0;
+ nx = t;
+ }
+ break;
+ case 6: /* broken */
+ if (nx > 1.0)
+ nx = nx - 1.0;
+ if (nx < -1.0)
+ nx = nx + 1.0;
+ if (ny > 1.0)
+ ny = ny - 1.0;
+ if (ny < -1.0)
+ ny = ny + 1.0;
+ break;
+ case 7: /* spherical */
+ {
+ double r = 0.5 + sqrt(nx * nx + ny * ny + 1e-6);
+
+ nx = nx / r;
+ ny = ny / r;
+ }
+ break;
+ case 8: /* */
+ nx = atan(nx) / M_PI_2;
+ ny = atan(ny) / M_PI_2;
+ break;
+/* #if 0 */ /* core dumps on some machines, why not all? */
+ case 9: /* complex sine */
+ {
+ double u = nx;
+ double v = ny;
+ double ev = exp(v);
+ double emv = exp(-v);
+
+ nx = (ev + emv) * sin(u) / 2.0;
+ ny = (ev - emv) * cos(u) / 2.0;
+ }
+ break;
+ case 10: /* polynomial */
+ if (nx < 0)
+ nx = -nx * nx;
+ else
+ nx = nx * nx;
+ if (ny < 0)
+ ny = -ny * ny;
+ else
+ ny = ny * ny;
+ break;
+/* #endif */
+ default:
+ nx = sin(nx);
+ ny = sin(ny);
+ }