Search in sources :

Example 76 with XYZPoint

use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.

the class LogDbFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    // logdb by DarkBeam 2014, http://jwildfire.org/forum/viewtopic.php?f=23&t=1450&p=2692#p2692
    double fix_atan_period = 0;
    int adp;
    int i;
    for (i = 0; i < 7; i++) {
        // approximated binomial distr
        adp = pContext.random(10) - 5;
        if (iabs(adp) >= 3)
            // 0 needs more chances
            adp = 0;
        fix_atan_period += (double) adp;
    }
    fix_atan_period *= _fixpe;
    pVarTP.x += _denom * log(pAffineTP.getPrecalcSumsq());
    pVarTP.y += pAmount * (pAffineTP.getPrecalcAtanYX() + fix_atan_period);
    if (pContext.isPreserveZCoordinate()) {
        pVarTP.z += pAmount * pAffineTP.z;
    }
}
Also used : XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 77 with XYZPoint

use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.

the class RosoniFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    double x = pAffineTP.x;
    double y = pAffineTP.y;
    double r = sqrt(sqr(x) + sqr(y)) - cutoff;
    if (cutoff < 0.0)
        r = Math.max(fabs(x), fabs(y)) + cutoff;
    boolean cerc = r > 0.0;
    if (cerc) {
        pVarTP.x += pAmount * x;
        pVarTP.y += pAmount * y;
        if (pContext.isPreserveZCoordinate()) {
            pVarTP.z += pAmount * pAffineTP.z;
        }
        return;
    }
    cerc = (dx > 0.0);
    int i;
    double xrt = x, yrt = y, swp, r2 = xrt;
    double sweetx = xrt, sweety = yrt;
    for (i = 0; i < maxiter; i++) {
        if (altshapes == 0) {
            // circle
            r2 = sqr(xrt - dx) + sqr(yrt - dy) - sqr(radius);
            if (radius < 0.0)
                // square
                r2 = Math.max(fabs(xrt - dx), fabs(y - dy)) + radius;
        } else {
            // lemniscate
            r2 = ((xrt - dx) < 0.0) ? -(xrt - dx) : ((sqr(yrt - dy)) - sqr(xrt - dx) * (sqr(radius) - sqr(xrt - dx)));
            if (radius < 0.0)
                // angle
                r2 = fabs(atan2(y - dy, xrt - dx)) * M_1_PI + radius;
        }
        cerc ^= (r2 <= 0.0);
        // rotate around to get the the sides!!! :D
        if (i == sweetiter) {
            sweetx = xrt;
            sweety = yrt;
        }
        swp = xrt * _cosa - yrt * _sina;
        yrt = xrt * _sina + yrt * _cosa;
        xrt = swp;
    }
    if (cerc) {
        if (sweetiter == 0) {
            if (dy != 0)
                pVarTP.x -= pAmount * sweetx;
            else
                pVarTP.x += pAmount * sweetx;
            pVarTP.y -= pAmount * sweety;
        } else {
            pVarTP.x += pAmount * sweetx;
            pVarTP.y += pAmount * sweety;
        }
        if (pContext.isPreserveZCoordinate()) {
            pVarTP.z += pAmount * pAffineTP.z;
        }
        return;
    }
    pVarTP.x += pAmount * x;
    pVarTP.y += pAmount * y;
    if (pContext.isPreserveZCoordinate()) {
        pVarTP.z += pAmount * pAffineTP.z;
    }
}
Also used : XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 78 with XYZPoint

use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.

the class SattractorFunc method transform.

public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    // Hennon IFS Reference:
    // http://paulbourke.net/fractals/henonattractor/roger18.c
    double x, y;
    int l = (int) (pContext.random() * (double) m) + 1;
    if (pContext.random() < 0.5) {
        x = pAffineTP.x / 2.0 + a[l];
        y = pAffineTP.y / 2.0 + b[l];
    } else {
        x = pAffineTP.x * a[l] + pAffineTP.y * b[l] + pAffineTP.x * pAffineTP.x * b[l];
        y = pAffineTP.y * a[l] - pAffineTP.x * b[l] + pAffineTP.x * pAffineTP.x * a[l];
    }
    x /= 2.0;
    y /= 2.0;
    pVarTP.x += x * pAmount;
    pVarTP.y += y * pAmount;
    if (pContext.isPreserveZCoordinate()) {
        pVarTP.z += pAmount * pAffineTP.z;
    }
}
Also used : XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 79 with XYZPoint

use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.

the class TruchetAEFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    // Truchet by Alexey Ermushev, http://eralex61.deviantart.com/art/Controlled-IFS-beyond-chaos-257891160
    // Implemented bu rsidwell. Tweaks made by DarkBeam 2017
    double u1 = 0, v1 = 0, z = 0.;
    int i = (int) floor(4 * pContext.random());
    // infinite layouts are possible, here I listed the most famous / interesting / useful
    if (layout == 1) {
        // symmetrized square
        switch(i) {
            case 0:
                u1 = -x * 0.5 + 1.0;
                v1 = y * 0.5 + 1.0;
                z1 = fmod2(k01a * z1 + k02a, 1.0);
                z2 = fmod2(k01b * z2 + k02b, 1.0);
                break;
            case 1:
                u1 = x * 0.5 - 1.0;
                v1 = y * 0.5 + 1.0;
                z1 = fmod2(k11a * z1 + k12a, 1.0);
                z2 = fmod2(k11b * z2 + k12b, 1.0);
                break;
            case 2:
                u1 = -x * 0.5 + 1.0;
                v1 = -y * 0.5 - 1.0;
                z1 = fmod2(k21a * z1 + k22a, 1.0);
                z2 = fmod2(k21b * z2 + k22b, 0.5);
                break;
            case 3:
                u1 = x * 0.5 - 1.0;
                v1 = -y * 0.5 - 1.0;
                z1 = fmod2(k31a * z1 + k32a, 1.0);
                z2 = fmod2(k31b * z2 + k32b, 1.0);
                break;
        }
    } else if (layout == 2) {
        // Sierpinski 45°
        switch(i) {
            case 0:
                u1 = x * 0.5 + 1.0;
                v1 = y * 0.5 + 1.0;
                z1 = fmod2(k01a * z1 + k02a, 1.0);
                z2 = fmod2(k01b * z2 + k02b, 1.0);
                break;
            case 1:
                u1 = x * 0.5 - 1.0;
                v1 = y * 0.5 - 1.0;
                z1 = fmod2(k11a * z1 + k12a, 1.0);
                z2 = fmod2(k11b * z2 + k12b, 1.0);
                break;
            case 2:
                u1 = x * 0.5 - 1.0;
                v1 = y * 0.5 + 1.0;
                z1 = fmod2(k21a * z1 + k22a, 1.0);
                z2 = fmod2(k21b * z2 + k22b, 0.5);
                break;
            case 3:
                u1 = -x * 0.5 - 1.0;
                v1 = -y * 0.5 + 1.0;
                z1 = fmod2(k31a * z1 + k32a, 1.0);
                z2 = fmod2(k31b * z2 + k32b, 1.0);
                break;
        }
    } else if (layout == 3) {
        // Chair
        switch(i) {
            case 0:
                u1 = x * 0.5;
                v1 = y * 0.5;
                z1 = fmod2(k01a * z1 + k02a, 1.0);
                z2 = fmod2(k01b * z2 + k02b, 1.0);
                break;
            case 1:
                u1 = x * 0.5 - 1.0;
                v1 = y * 0.5 + 1.0;
                z1 = fmod2(k11a * z1 + k12a, 1.0);
                z2 = fmod2(k11b * z2 + k12b, 1.0);
                break;
            case 2:
                u1 = -y * 0.5 - 1.0;
                v1 = x * 0.5 - 1.0;
                z1 = fmod2(k21a * z1 + k22a, 1.0);
                z2 = fmod2(k21b * z2 + k22b, 0.5);
                break;
            case 3:
                u1 = y * 0.5 + 1.0;
                v1 = -x * 0.5 + 1.0;
                z1 = fmod2(k31a * z1 + k32a, 1.0);
                z2 = fmod2(k31b * z2 + k32b, 1.0);
                break;
        }
    } else if (layout == 4) {
        // EquilaterTri
        switch(i) {
            case 0:
                u1 = x * 0.5 + 1;
                v1 = y * 0.5 + M_SQ3_2;
                z1 = fmod2(k01a * z1 + k02a, 1.0);
                z2 = fmod2(k01b * z2 + k02b, 1.0);
                break;
            case 1:
                u1 = x * 0.5 - 1;
                v1 = y * 0.5 + M_SQ3_2;
                z1 = fmod2(k11a * z1 + k12a, 1.0);
                z2 = fmod2(k11b * z2 + k12b, 1.0);
                break;
            case 2:
                u1 = x * 0.5;
                v1 = y * 0.5 - M_SQ3_2;
                z1 = fmod2(k21a * z1 + k22a, 1.0);
                z2 = fmod2(k21b * z2 + k22b, 0.5);
                break;
            case 3:
                u1 = x * 0.5;
                v1 = -y * 0.5 + M_SQ3_2;
                z1 = fmod2(k31a * z1 + k32a, 1.0);
                z2 = fmod2(k31b * z2 + k32b, 1.0);
                break;
        }
    } else {
        // default = asymm. square
        double j;
        switch(i) {
            case 0:
                u1 = x * 0.5 + 1.0;
                v1 = y * 0.5 + 1.0;
                j = v1 + 0.7;
                if (j > 2.)
                    j = j - 2.;
                v1 = j;
                z1 = fmod2(k01a * z1 + k02a, 1.0);
                z2 = fmod2(k01b * z2 + k02b, 1.0);
                break;
            case 1:
                u1 = x * 0.5 - 1.0;
                v1 = y * 0.5 + 1.0;
                z1 = fmod2(k11a * z1 + k12a, 1.0);
                z2 = fmod2(k11b * z2 + k12b, 1.0);
                break;
            case 2:
                u1 = x * 0.5 + 1.0;
                v1 = y * 0.5 - 1.0;
                z1 = fmod2(k21a * z1 + k22a, 1.0);
                z2 = fmod2(k21b * z2 + k22b, 0.5);
                break;
            case 3:
                u1 = x * 0.5 - 1.0;
                v1 = y * 0.5 - 1.0;
                z1 = fmod2(k31a * z1 + k32a, 1.0);
                z2 = fmod2(k31b * z2 + k32b, 1.0);
                break;
        }
    }
    double uu1 = cosang * u1 - sinang * v1;
    double vv1 = sinang * u1 + cosang * v1;
    int m = (int) floor(uu1 / step);
    int n = (int) floor(vv1 / step);
    double u = uu1 / step - m;
    double v = vv1 / step - n;
    double chance = dn1((m + 34 * n + seed));
    double cir = 0.0;
    double square = 0.;
    boolean inv = false;
    // tweaking them generates different styles
    switch(style) {
        case // Apo (default) by Eralex
        0:
            if (chance > 0.5) {
                if (((v < u + 1 - width) && (v > u + width)) || ((v < u - width) && (v > u - 1 + width)))
                    z = z1;
                else
                    z = z2;
            } else {
                if (((v < -u + 1 - width) && (v > -u + width)) || ((v > -u + 1 + width) && (v < -u + 2 - width)))
                    z = z1;
                else
                    z = z2;
            }
            break;
        case // Original by Truchet (added width for effect) was with four tiles
        1:
            square = max(fabs(u - .5), fabs(v - .5)) - 0.5 * (1. - width);
            if (chance < 0.25) {
                if (((square < 0) ^ (u > v)))
                    z = z1;
                else
                    z = z2;
            } else if (chance < 0.5) {
                if (((square < 0) ^ (u > 1. - v)))
                    z = z1;
                else
                    z = z2;
            } else if (chance < 0.75) {
                if (((square < 0) ^ (u < v)))
                    z = z1;
                else
                    z = z2;
            } else {
                if (((square < 0) ^ (u < 1. - v)))
                    z = z1;
                else
                    z = z2;
            }
            break;
        case // circle Apo truchet (simulated) :P
        2:
            if (chance < 0.5) {
                cir = sqrt((u - 1.) * (u - 1.) + (v - 1.) * (v - 1.));
                cir = min(cir, sqrt(u * u + v * v));
                cir = fabs(fabs(cir - 0.5) - 0.5) - 0.5 * (1. - width);
                if (cir < 0)
                    z = z1;
                else
                    z = z2;
            } else {
                cir = sqrt((u - 1.) * (u - 1.) + v * v);
                cir = min(cir, sqrt(u * u + (v - 1.) * (v - 1.)));
                cir = fabs(fabs(cir - 0.5) - 0.5) - 0.5 * (1. - width);
                if (cir < 0)
                    z = z1;
                else
                    z = z2;
            }
            break;
        case // circle Apo truchet plus + tile - looks cool 8)
        3:
            if (chance < 0.333333) {
                cir = sqrt((u - 1.) * (u - 1.) + (v - 1.) * (v - 1.));
                cir = min(cir, sqrt(u * u + v * v));
                cir = fabs(fabs(cir - 0.5) - 0.5) - 0.5 * (1. - width);
                if (cir < 0)
                    z = z1;
                else
                    z = z2;
            } else if (chance < 0.666666) {
                cir = sqrt((u - 1.) * (u - 1.) + v * v);
                cir = min(cir, sqrt(u * u + (v - 1.) * (v - 1.)));
                cir = fabs(fabs(cir - 0.5) - 0.5) - 0.5 * (1. - width);
                if (cir < 0)
                    z = z1;
                else
                    z = z2;
            } else {
                // PLUS!
                cir = 0.5 * (width) - min(fabs(u - .5), fabs(v - .5));
                if (cir < 0)
                    z = z1;
                else
                    z = z2;
            }
            break;
        case // Original Modded (added width for effect) 8 tiles
        4:
            square = max(fabs(u - .5), fabs(v - .5)) - 0.5 * (1. - width);
            if (chance < 0.125) {
                if (((square < 0) ^ (u > v)))
                    z = z1;
                else
                    z = z2;
            } else if (chance < 0.25) {
                if (((square < 0) ^ (u > 1. - v)))
                    z = z1;
                else
                    z = z2;
            } else if (chance < 0.375) {
                if (((square < 0) ^ (u < v)))
                    z = z1;
                else
                    z = z2;
            } else if (chance < 0.5) {
                if (((square < 0) ^ (u < 1. - v)))
                    z = z1;
                else
                    z = z2;
            // ---------------------
            } else if (chance < 0.625) {
                if (((square < 0) ^ (u < 0.5)))
                    z = z1;
                else
                    z = z2;
            } else if (chance < 0.75) {
                if (((square < 0) ^ (v < 0.5)))
                    z = z1;
                else
                    z = z2;
            } else if (chance < 0.875) {
                if (((square < 0) ^ (u > 0.5)))
                    z = z1;
                else
                    z = z2;
            } else {
                if (((square < 0) ^ (v > 0.5)))
                    z = z1;
                else
                    z = z2;
            }
            break;
        case // circle filled truchet + width for effect
        5:
            inv = (m % 2 == 0) ^ (n % 2 == 0);
            if (chance < 0.5) {
                cir = sqrt((u - 1.) * (u - 1.) + (v - 1.) * (v - 1.));
                cir = min(cir, sqrt(u * u + v * v));
                square = cir;
                cir = fabs(cir) - 0.5;
                // dots effect (suggested a width = 0.25)
                square = min(square, sqrt((u - 1.) * (u - 1.) + v * v));
                square = min(square, sqrt(u * u + (v - 1.) * (v - 1.)));
                square = fabs(square) - width;
                if ((cir < 0) ^ (square < 0) ^ inv)
                    z = z1;
                else
                    z = z2;
            } else {
                cir = sqrt((u - 1.) * (u - 1.) + v * v);
                cir = min(cir, sqrt(u * u + (v - 1.) * (v - 1.)));
                square = cir;
                cir = fabs(cir) - 0.5;
                // dots effect (suggested a width = 0.25)
                square = min(square, sqrt((u - 1.) * (u - 1.) + (v - 1.) * (v - 1.)));
                square = min(square, sqrt(u * u + v * v));
                square = fabs(square) - width;
                if ((cir < 0) ^ (square < 0) ^ inv)
                    z = z2;
                else
                    z = z1;
            }
            break;
    }
    x = u1;
    y = v1;
    pVarTP.x += u1;
    pVarTP.y += v1;
    if (pContext.isPreserveZCoordinate())
        pVarTP.z += pAmount * pAffineTP.z;
    pVarTP.color = z;
    z1 = z;
    z2 = z;
}
Also used : XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 80 with XYZPoint

use of org.jwildfire.create.tina.base.XYZPoint in project JWildfire by thargor6.

the class TruchetFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    // APO VARIABLES
    double n = exponent;
    double onen = 1.0 / exponent;
    double tdeg = rotation;
    double width = arc_width;
    double seed = fabs(this.seed);
    double seed2 = sqrt(seed + (seed / 2) + SMALL_EPSILON) / ((seed * 0.5) + SMALL_EPSILON) * 0.25;
    // VARIABLES
    double x, y;
    int intx = 0;
    int inty = 0;
    double r = -tdeg;
    double r0 = 0.0;
    double r1 = 0.0;
    double rmax = 0.5 * (pow(2.0, 1.0 / n) - 1.0) * width;
    double scale = (cos(r) - sin(r)) / pAmount;
    double tiletype = 0.0;
    double randint = 0.0;
    double modbase = 65535.0;
    // 1103515245;
    double multiplier = 32747.0;
    double offset = 12345.0;
    double niter = 0.0;
    int randiter = 0;
    // INITIALISATION
    x = pAffineTP.x * scale;
    y = pAffineTP.y * scale;
    intx = (int) round(x);
    inty = (int) round(y);
    r = x - intx;
    if (r < 0.0) {
        x = 1.0 + r;
    } else {
        x = r;
    }
    r = y - inty;
    if (r < 0.0) {
        y = 1.0 + r;
    } else {
        y = r;
    }
    // CALCULATE THE TILE TYPE
    if (seed == 0.0) {
        tiletype = 0.0;
    } else if (seed == 1.0) {
        tiletype = 1.0;
    } else {
        if (extended == 0) {
            double xrand = round(pAffineTP.x);
            double yrand = round(pAffineTP.y);
            xrand = xrand * seed2;
            yrand = yrand * seed2;
            niter = xrand + yrand + xrand * yrand;
            randint = (niter + seed) * seed2 / 2.0;
            randint = fmod((randint * multiplier + offset), modbase);
        } else {
            seed = floor(seed);
            int xrand = (int) round(pAffineTP.x);
            int yrand = (int) round(pAffineTP.y);
            niter = fabs(xrand + yrand + xrand * yrand);
            if (niter > 1000)
                niter = 1000;
            randint = seed + niter;
            randiter = 0;
            while (randiter < niter) {
                randiter += 1;
                randint = fmod((randint * multiplier + offset), modbase);
            }
        }
        // randint%2;
        tiletype = fmod(randint, 2.0);
    }
    // DRAWING THE POINTS
    if (extended == 0) {
        // Fast drawmode
        if (tiletype < 1.0) {
            r0 = pow((pow(fabs(x), n) + pow(fabs(y), n)), onen);
            r1 = pow((pow(fabs(x - 1.0), n) + pow(fabs(y - 1.0), n)), onen);
        } else {
            r0 = pow((pow(fabs(x - 1.0), n) + pow(fabs(y), n)), onen);
            r1 = pow((pow(fabs(x), n) + pow(fabs(y - 1.0), n)), onen);
        }
    } else {
        if (tiletype == 1.0) {
            // Slow drawmode
            r0 = pow((pow(fabs(x), n) + pow(fabs(y), n)), onen);
            r1 = pow((pow(fabs(x - 1.0), n) + pow(fabs(y - 1.0), n)), onen);
        } else {
            r0 = pow((pow(fabs(x - 1.0), n) + pow(fabs(y), n)), onen);
            r1 = pow((pow(fabs(x), n) + pow(fabs(y - 1.0), n)), onen);
        }
    }
    r = fabs(r0 - 0.5) / rmax;
    if (r < 1.0) {
        if (direct_color == 1) {
            pVarTP.color = limitVal(r0, 0.0, 1.0);
        }
        pVarTP.x += size * (x + floor(pAffineTP.x));
        pVarTP.y += size * (y + floor(pAffineTP.y));
    }
    r = fabs(r1 - 0.5) / rmax;
    if (r < 1.0) {
        if (direct_color == 1) {
            pVarTP.color = limitVal(1.0 - r1, 0.0, 1.0);
        }
        pVarTP.x += size * (x + floor(pAffineTP.x));
        pVarTP.y += size * (y + floor(pAffineTP.y));
        if (pContext.isPreserveZCoordinate()) {
            pVarTP.z += pAmount * pAffineTP.z;
        }
    }
}
Also used : XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Aggregations

XYZPoint (org.jwildfire.create.tina.base.XYZPoint)102 XForm (org.jwildfire.create.tina.base.XForm)16 Layer (org.jwildfire.create.tina.base.Layer)13 Test (org.junit.Test)4 VectorD (org.jwildfire.base.mathlib.VecMathLib.VectorD)4 Flame (org.jwildfire.create.tina.base.Flame)4 ZigguratRandomGenerator (org.jwildfire.create.tina.random.ZigguratRandomGenerator)4 FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)4 SimpleHDRImage (org.jwildfire.image.SimpleHDRImage)4 SimpleImage (org.jwildfire.image.SimpleImage)4 Complex (org.jwildfire.base.mathlib.Complex)2 XYZProjectedPoint (org.jwildfire.create.tina.base.XYZProjectedPoint)2 Face (org.jwildfire.create.tina.variation.mesh.Face)2 Vertex (org.jwildfire.create.tina.variation.mesh.Vertex)2 VertexWithUV (org.jwildfire.create.tina.variation.mesh.VertexWithUV)2 RenderColor (org.jwildfire.create.tina.palette.RenderColor)1 CannabisCurveWFFunc (org.jwildfire.create.tina.variation.CannabisCurveWFFunc)1 CloverLeafWFFunc (org.jwildfire.create.tina.variation.CloverLeafWFFunc)1 DCPerlinFunc (org.jwildfire.create.tina.variation.DCPerlinFunc)1 FlowerFunc (org.jwildfire.create.tina.variation.FlowerFunc)1