Advertisement
rsidwell

PTransformFunc.java

Jul 20th, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.97 KB | None | 0 0
  1. /*
  2.   JWildfire - an image and animation processor written in Java
  3.   Copyright (C) 1995-2011 Andreas Maschke
  4.  
  5.   This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
  6.   General Public License as published by the Free Software Foundation; either version 2.1 of the
  7.   License, or (at your option) any later version.
  8.  
  9.   This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  10.   even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11.   Lesser General Public License for more details.
  12.  
  13.   You should have received a copy of the GNU Lesser General Public License along with this software;
  14.   if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  15.   02110-1301 USA, or see the FSF site: http://www.fsf.org.
  16. */
  17. package org.jwildfire.create.tina.variation;
  18.  
  19. import static org.jwildfire.base.mathlib.MathLib.cos;
  20. import static org.jwildfire.base.mathlib.MathLib.sin;
  21.  
  22. import org.jwildfire.base.Tools;
  23. import org.jwildfire.create.tina.base.XForm;
  24. import org.jwildfire.create.tina.base.XYZPoint;
  25.  
  26. public class PTransformFunc extends VariationFunc {
  27.   private static final long serialVersionUID = 1L;
  28.  
  29.   private static final String PARAM_ROTATE = "rotate";
  30.   private static final String PARAM_POWER = "power";
  31.   private static final String PARAM_MOVE = "move";
  32.   private static final String PARAM_SPLIT = "split";
  33.  
  34.   private static final String[] paramNames = { PARAM_ROTATE, PARAM_POWER, PARAM_MOVE, PARAM_SPLIT };
  35.  
  36.   private double rotate = 0.0;
  37.   private int power = 1;
  38.   private double move = 0.0;
  39.   private double split = 0.0;
  40.  
  41.   @Override
  42.   public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
  43.     double rho, theta;
  44.    
  45.     rho = pAffineTP.getPrecalcSqrt() / power + move;
  46.     theta = pAffineTP.getPrecalcAtanYX() + rotate;
  47.  
  48.     if (pAffineTP.x >= 0.0)
  49.       rho += split;
  50.     else
  51.       rho -= split;
  52.    
  53.     pVarTP.x += pAmount * rho * cos(theta);
  54.     pVarTP.y += pAmount * rho * sin(theta);
  55.     if (pContext.isPreserveZCoordinate()) {
  56.   pVarTP.z += pAmount * pAffineTP.z;
  57. }
  58.   }
  59.  
  60.   @Override
  61.   public String[] getParameterNames() {
  62.     return paramNames;
  63.   }
  64.  
  65.   @Override
  66.   public Object[] getParameterValues() {
  67.     return new Object[] { rotate, power, move, split };
  68.   }
  69.  
  70.   @Override
  71.   public void setParameter(String pName, double pValue) {
  72.     if (PARAM_ROTATE.equalsIgnoreCase(pName))
  73.       rotate = pValue;
  74.     else if (PARAM_POWER.equalsIgnoreCase(pName))
  75.       power = limitIntVal(Tools.FTOI(pValue), 1, Integer.MAX_VALUE);
  76.     else if (PARAM_MOVE.equalsIgnoreCase(pName))
  77.       move = pValue;
  78.     else if (PARAM_SPLIT.equalsIgnoreCase(pName))
  79.       split = pValue;
  80.     else
  81.       throw new IllegalArgumentException(pName);
  82.   }
  83.  
  84.   @Override
  85.   public String getName() {
  86.     return "pTransform";
  87.   }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement