jwildfire.org

The official JWildfire forum
It is currently Sun Mar 24, 2019 6:02 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Reciprocal
PostPosted: Tue Feb 05, 2019 4:41 am 
Offline
User avatar

Joined: Sun May 31, 2015 2:39 pm
Posts: 568
/ reciprocal by Whittaker Courtney and Brad Stefanov

Works great in place of bipolar or elliptic setups but can do so much more :)

Code:
Code:
/*
  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 = 1.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";
	}

}
Image
Image


You do not have the required permissions to view the files attached to this post.


Top
   
 Post subject: Re: Reciprocal
PostPosted: Fri Feb 08, 2019 12:07 pm 
Offline

Joined: Thu May 07, 2015 6:29 pm
Posts: 52
Looks cool! Thank you, Brad! :)


Top
   
 Post subject: Re: Reciprocal
PostPosted: Mon Feb 25, 2019 3:58 am 
Offline
User avatar

Joined: Sun May 31, 2015 2:39 pm
Posts: 568
Whittaker Courtney has re-done it and made it a pre variation that it is now much more flexible.
renamed to pre_recip
found here
https://onedrive.live.com/?cid=2c6b99ca ... XWYOQkKek0


Top
   
 Post subject: Re: Reciprocal
PostPosted: Wed Feb 27, 2019 1:04 am 
Offline

Joined: Fri Dec 02, 2016 4:08 pm
Posts: 7
Made a few slight changes to the pre_recip code. Added an x_add and y_add variable (tweaks the direction where the effect leans toward.)

Also made it so that reciprocal, divide and sqrt always go before the other function options if they are enabled, so if sqrtpow = 1 and asinhpow = 1, then it will calculate the sqrt of z before asinh. Before this they would all mix together into a messy overlapping shape but they seem to work together better with other functions when used before them. (Now you can make interesting patterns enabling reciprocal, divide and sqrt at the same time :) )

Download the variation:
(use a custom_wf_full variation and make sure to enable "pre")
https://1drv.ms/u/s!AhjR8cDKmWsspVjc41kTYTDORXYJ


Top
   
 Post subject: Re: Reciprocal
PostPosted: Wed Feb 27, 2019 5:45 am 
Offline
User avatar

Joined: Mon Jun 08, 2015 4:40 am
Posts: 293
Thanks for the update!


Top
   
 Post subject: Re: Reciprocal
PostPosted: Wed Feb 27, 2019 6:53 pm 
Offline

Joined: Tue Mar 20, 2018 7:09 pm
Posts: 14
wow so cool ty for sharing


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited
Theme Created by HOLLYSMOKE
Theme updated to phpBB 3.1.6 by KamijouTouma
Theme Version is 3.1.6-ss2