Advertisement
rsidwell

dc_bubble fixed

Nov 26th, 2017
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 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.fabs;
  20. import static org.jwildfire.base.mathlib.MathLib.fmod;
  21. import static org.jwildfire.base.mathlib.MathLib.sqr;
  22. import static org.jwildfire.base.Tools.limitValue;
  23.  
  24. import org.jwildfire.create.tina.base.Layer;
  25. import org.jwildfire.create.tina.base.XForm;
  26. import org.jwildfire.create.tina.base.XYZPoint;
  27.  
  28. public class DCBubbleFunc extends VariationFunc {
  29.  
  30.   private static final long serialVersionUID = 1L;
  31.  
  32.   private static final String PARAM_CENTERX = "centerx";
  33.   private static final String PARAM_CENTERY = "centery";
  34.   private static final String PARAM_SCALE = "scale";
  35.   private static final String PARAM_INVERT = "invert";
  36.  
  37.   private static final String[] paramNames = { PARAM_CENTERX, PARAM_CENTERY, PARAM_SCALE, PARAM_INVERT };
  38.  
  39.   private double centerx = 0.0;
  40.   private double centery = 0.0;
  41.   private double scale = 1.0;
  42.   private int invert = 1;
  43.  
  44.   @Override
  45.   public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
  46.     /* corrected version of dc_bubble by Xyrus02, http://apophysis-7x.org/extensions */
  47.  
  48.     double r = ((pAffineTP.x * pAffineTP.x + pAffineTP.y * pAffineTP.y) / 4.0 + 1.0);
  49.     double t = pAmount / r;
  50.     pVarTP.x += t * pAffineTP.x;
  51.     pVarTP.y += t * pAffineTP.y;
  52.     pVarTP.z += pAmount * (2.0 / (invert == 1 ? t : r) - 1.0);
  53.  
  54.     pVarTP.color = fmod(fabs(bdcs * (sqr(pVarTP.x + centerx) + sqr(pVarTP.y + centery))), 1.0);
  55.   }
  56.  
  57.   @Override
  58.   public String[] getParameterNames() {
  59.     return paramNames;
  60.   }
  61.  
  62.   @Override
  63.   public Object[] getParameterValues() {
  64.     return new Object[] { centerx, centery, scale, invert };
  65.   }
  66.  
  67.   @Override
  68.   public void setParameter(String pName, double pValue) {
  69.     if (PARAM_CENTERX.equalsIgnoreCase(pName))
  70.       centerx = pValue;
  71.     else if (PARAM_CENTERY.equalsIgnoreCase(pName))
  72.       centery = pValue;
  73.     else if (PARAM_SCALE.equalsIgnoreCase(pName))
  74.       scale = pValue;
  75.     else if (PARAM_INVERT.equalsIgnoreCase(pName))
  76.       invert = limitValue((int) pValue, 0, 1);
  77.     else
  78.       throw new IllegalArgumentException(pName);
  79.   }
  80.  
  81.   @Override
  82.   public String getName() {
  83.     return "dc_bubble";
  84.   }
  85.  
  86.   private double bdcs;
  87.  
  88.   @Override
  89.   public void init(FlameTransformationContext pContext, Layer pLayer, XForm pXForm, double pAmount) {
  90.     bdcs = 1.0 / (scale == 0.0 ? 10E-6 : scale);
  91.   }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement