Reciprocal by Whittaker Courtney and Brad Stefanov

Works great in place of bipolar or elliptic setups but can do so much more.  🙂

The first variable needs set to 1 or else you just get dots!

/*
  JWildfire - an image and animation processor written in Java 
  Copyright (C) 1995-2011 Andreas Maschke
  This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 
  General Public License as published by the Free Software Foundation; either version 2.1 of the 
  License, or (at your option) any later version.
 
  This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
  Lesser General Public License for more details.
  You should have received a copy of the GNU Lesser General Public License along with this software; 
  if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jwildfire.create.tina.variation;

import org.jwildfire.create.tina.base.XForm;
import org.jwildfire.create.tina.base.XYZPoint;
import org.jwildfire.base.mathlib.Complex;
import static org.jwildfire.base.mathlib.MathLib.M_2_PI;

public class ReciprocalFunc extends VariationFunc {
	private static final long serialVersionUID = 1L;

	private static final String PARAM_ACOSECHPOW = "acosechpow";
	private static final String PARAM_ACOSECHZX = "acosechzx";
	private static final String PARAM_ACOSECHZY = "acosechzy";
	private static final String PARAM_ACOSECHDPOW = "acosechdpow";
	private static final String PARAM_ACOSECHDZX = "acosechdzx";
	private static final String PARAM_ACOSECHDZY = "acosechdzy";
	private static final String PARAM_ACOSECHDZX2 = "acosechdzx2";
	private static final String PARAM_ACOSECHDZY2 = "acosechdzy2";
	private static final String PARAM_ACOSHDPOW = "acoshdpow";
	private static final String PARAM_ACOSHDZX = "acoshdzx";
	private static final String PARAM_ACOSHDZY = "acoshdzy";
	private static final String PARAM_ACOSHDZX2 = "acoshdzx2";
	private static final String PARAM_ACOSHDZY2 = "acoshdzy2";
	private static final String PARAM_ACOSHPOW = "acoshpow";
	private static final String PARAM_ACOSHZX = "acoshzx";
	private static final String PARAM_ACOSHZY = "acoshzy";
	private static final String PARAM_ACOTHDPOW = "acothdpow";
	private static final String PARAM_ACOTHDZX = "acothdzx";
	private static final String PARAM_ACOTHDZY = "acothdzy";
	private static final String PARAM_ACOTHDZX2 = "acothdzx2";
	private static final String PARAM_ACOTHDZY2 = "acothdzy2";
	private static final String PARAM_ASECHPOW = "asechpow";
	private static final String PARAM_ASECHZX = "asechzx";
	private static final String PARAM_ASECHZY = "asechzy";
	private static final String PARAM_ASINHPOW = "asinhpow";
	private static final String PARAM_ASINHZX = "asinhzx";
	private static final String PARAM_ASINHZY = "asinhzy";
	private static final String PARAM_LOGPOW = "logpow";
	private static final String PARAM_LOGZX = "logzx";
	private static final String PARAM_LOGZY = "logzy";

	private static final String[] paramNames = { PARAM_ACOSECHPOW, PARAM_ACOSECHZX, PARAM_ACOSECHZY, PARAM_ACOSECHDPOW,
			PARAM_ACOSECHDZX, PARAM_ACOSECHDZY, PARAM_ACOSECHDZX2, PARAM_ACOSECHDZY2, PARAM_ACOSHDPOW, PARAM_ACOSHDZX,
			PARAM_ACOSHDZY, PARAM_ACOSHDZX2, PARAM_ACOSHDZY2, PARAM_ACOSHPOW, PARAM_ACOSHZX, PARAM_ACOSHZY,
			PARAM_ACOTHDPOW, PARAM_ACOTHDZX, PARAM_ACOTHDZY, PARAM_ACOTHDZX2, PARAM_ACOTHDZY2, PARAM_ASECHPOW,
			PARAM_ASECHZX, PARAM_ASECHZY, PARAM_ASINHPOW, PARAM_ASINHZX, PARAM_ASINHZY, PARAM_LOGPOW, PARAM_LOGZX,
			PARAM_LOGZY };

	private double acosechpow = 0.0;
	private double acosechzx = 0.0;
	private double acosechzy = 0.0;
	private double acosechdpow = 0.0;
	private double acosechdzx = 0.0;
	private double acosechdzy = 0.0;
	private double acosechdzx2 = 0.0;
	private double acosechdzy2 = 0.0;
	private double acoshdpow = 0.0;
	private double acoshdzx = 0.0;
	private double acoshdzy = 0.0;
	private double acoshdzx2 = 0.0;
	private double acoshdzy2 = 0.0;
	private double acoshpow = 0.0;
	private double acoshzx = 0.0;
	private double acoshzy = 0.0;
	private double acothdpow = 0.0;
	private double acothdzx = 0.0;
	private double acothdzy = 0.0;
	private double acothdzx2 = 0.0;
	private double acothdzy2 = 0.0;
	private double asechpow = 0.0;
	private double asechzx = 0.0;
	private double asechzy = 0.0;
	private double asinhpow = 0.0;
	private double asinhzx = 0.0;
	private double asinhzy = 0.0;
	private double logpow = 0.0;
	private double logzx = 0.0;
	private double logzy = 0.0;

	@Override
	public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP,
			double pAmount) {
		// reciprocal by Whittaker Courtney and Brad Stefanov
		double xx = 0.0, yy = 0.0;

		if (acosechpow != 0) {
			Complex z = new Complex(pAffineTP.x + acosechzx, pAffineTP.y + acosechzy);

			z.Recip();
			z.AcosecH();

			z.Scale(pAmount * M_2_PI);

			if (pContext.random() < 0.5) {
				xx += acosechpow * z.re;
				yy += acosechpow * z.im;
			} else {

				xx += acosechpow * -z.re;
				yy += acosechpow * -z.im;
			}
		}
		if (acosechdpow != 0) {
			Complex z = new Complex(pAffineTP.x + acosechdzx, pAffineTP.y + acosechdzy);
			Complex z2 = new Complex(pAffineTP.x + acosechdzx2, pAffineTP.y + acosechdzy2);

			z2.Dec();

			z.Inc();
			z.Div(z2);
			z.Recip();
			z.AcosecH();

			z.Scale(pAmount * M_2_PI);

			if (pContext.random() < 0.5) {
				xx += acosechdpow * z.re;
				yy += acosechdpow * z.im;
			} else {
				xx += acosechdpow * -z.re;
				yy += acosechdpow * -z.im;
			}

		}

		if (acoshdpow != 0) {
			Complex z = new Complex(pAffineTP.x + acoshdzx, pAffineTP.y + acoshdzy);
			Complex z2 = new Complex(pAffineTP.x + acoshdzx2, pAffineTP.y + acoshdzy2);

			z2.Dec();

			z.Inc();
			z.Div(z2);
			z.Recip();
			z.AcosH();

			z.Scale(pAmount * M_2_PI / 2);

			if (pContext.random() < 0.5) {
				xx += acoshdpow * z.re;
				yy += acoshdpow * z.im;
			} else {
				xx += acoshdpow * -z.re;
				yy += acoshdpow * -z.im;
			}
		}

		if (acoshpow != 0) {
			Complex z = new Complex(pAffineTP.x + acoshzx, pAffineTP.y + acoshzy);

			z.Recip();
			z.AcosH();

			z.Scale(pAmount * M_2_PI);

			if (pContext.random() < 0.5) {
				xx += acoshpow * z.re;
				yy += acoshpow * z.im;
			} else {
				xx += acoshpow * -z.re;
				yy += acoshpow * -z.im;
			}
		}

		if (acothdpow != 0) {
			Complex z = new Complex(pAffineTP.x + acothdzx, pAffineTP.y + acothdzy);
			Complex z2 = new Complex(pAffineTP.x + acothdzx2, pAffineTP.y + acothdzy2);

			z2.Inc();

			z.Dec();
			z.Div(z2);
			z.Recip();
			z.AcotH();

			z.Scale(pAmount * M_2_PI);

			xx += acothdpow * z.re;
			yy += acothdpow * z.im;

		}

		if (asechpow != 0) {
			Complex z = new Complex(pAffineTP.x + asechzx, pAffineTP.y + asechzy);

			z.Recip();
			z.AsecH();

			z.Scale(pAmount * M_2_PI);

			xx += asechpow * z.re;
			yy += asechpow * z.im;

		}

		if (asinhpow != 0) {
			Complex z = new Complex(pAffineTP.x + asinhzx, pAffineTP.y + asinhzy);

			z.Recip();
			z.AsinH();

			z.Scale(pAmount * M_2_PI);

			xx += asinhpow * z.re;
			yy += asinhpow * z.im;

		}
		if (logpow != 0) {
			Complex z = new Complex(pAffineTP.x + logzx, pAffineTP.y + logzy);

			z.Recip();
			z.Log();

			z.Scale(pAmount * M_2_PI);

			xx += logpow * z.re;
			yy += logpow * z.im;

		}

		pVarTP.x += xx;
		pVarTP.y += yy;
		if (pContext.isPreserveZCoordinate()) {
			pVarTP.z += pAmount * pAffineTP.z;
		}
	}

	@Override
	public String[] getParameterNames() {
		return paramNames;
	}

	@Override
	public Object[] getParameterValues() {
		return new Object[] { acosechpow, acosechzx, acosechzy, acosechdpow, acosechdzx, acosechdzy, acosechdzx2,
				acosechdzy2, acoshdpow, acoshdzx, acoshdzy, acoshdzx2, acoshdzy2, acoshpow, acoshzx, acoshzy, acothdpow,
				acothdzx, acothdzy, acothdzx2, acothdzy2, asechpow, asechzx, asechzy, asinhpow, asinhzx, asinhzy,
				logpow, logzx, logzy };
	}

	@Override
	public void setParameter(String pName, double pValue) {
		if (PARAM_ACOSECHPOW.equalsIgnoreCase(pName))
			acosechpow = pValue;
		else if (PARAM_ACOSECHZX.equalsIgnoreCase(pName))
			acosechzx = pValue;
		else if (PARAM_ACOSECHZY.equalsIgnoreCase(pName))
			acosechzy = pValue;
		else if (PARAM_ACOSECHDPOW.equalsIgnoreCase(pName))
			acosechdpow = pValue;
		else if (PARAM_ACOSECHDZX.equalsIgnoreCase(pName))
			acosechdzx = pValue;
		else if (PARAM_ACOSECHDZY.equalsIgnoreCase(pName))
			acosechdzy = pValue;
		else if (PARAM_ACOSECHDZX2.equalsIgnoreCase(pName))
			acosechdzx2 = pValue;
		else if (PARAM_ACOSECHDZY2.equalsIgnoreCase(pName))
			acosechdzy2 = pValue;
		else if (PARAM_ACOSHDPOW.equalsIgnoreCase(pName))
			acoshdpow = pValue;
		else if (PARAM_ACOSHDZX.equalsIgnoreCase(pName))
			acoshdzx = pValue;
		else if (PARAM_ACOSHDZY.equalsIgnoreCase(pName))
			acoshdzy = pValue;
		else if (PARAM_ACOSHDZX2.equalsIgnoreCase(pName))
			acoshdzx2 = pValue;
		else if (PARAM_ACOSHDZY2.equalsIgnoreCase(pName))
			acoshdzy2 = pValue;
		else if (PARAM_ACOSHPOW.equalsIgnoreCase(pName))
			acoshpow = pValue;
		else if (PARAM_ACOSHZX.equalsIgnoreCase(pName))
			acoshzx = pValue;
		else if (PARAM_ACOSHZY.equalsIgnoreCase(pName))
			acoshzy = pValue;
		else if (PARAM_ACOTHDPOW.equalsIgnoreCase(pName))
			acothdpow = pValue;
		else if (PARAM_ACOTHDZX.equalsIgnoreCase(pName))
			acothdzx = pValue;
		else if (PARAM_ACOTHDZY.equalsIgnoreCase(pName))
			acothdzy = pValue;
		else if (PARAM_ACOTHDZX2.equalsIgnoreCase(pName))
			acothdzx2 = pValue;
		else if (PARAM_ACOTHDZY2.equalsIgnoreCase(pName))
			acothdzy2 = pValue;
		else if (PARAM_ASECHPOW.equalsIgnoreCase(pName))
			asechpow = pValue;
		else if (PARAM_ASECHZX.equalsIgnoreCase(pName))
			asechzx = pValue;
		else if (PARAM_ASECHZY.equalsIgnoreCase(pName))
			asechzy = pValue;
		else if (PARAM_ASINHPOW.equalsIgnoreCase(pName))
			asinhpow = pValue;
		else if (PARAM_ASINHZX.equalsIgnoreCase(pName))
			asinhzx = pValue;
		else if (PARAM_ASINHZY.equalsIgnoreCase(pName))
			asinhzy = pValue;
		else if (PARAM_LOGPOW.equalsIgnoreCase(pName))
			logpow = pValue;
		else if (PARAM_LOGZX.equalsIgnoreCase(pName))
			logzx = pValue;
		else if (PARAM_LOGZY.equalsIgnoreCase(pName))
			logzy = pValue;
		else
			throw new IllegalArgumentException(pName);
	}

	@Override
	public String getName() {
		return "reciprocal";
	}

}


Download
FileAction
ReciprocalFunc.zipDownload 

Leave a Comment