Advertisement
rsidwell

RingTile2Func.java

Jan 11th, 2025
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.73 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 org.jwildfire.create.tina.base.XForm;
  20. import org.jwildfire.create.tina.base.XYZPoint;
  21.  
  22. import org.jwildfire.base.mathlib.Complex;
  23. import static org.jwildfire.base.mathlib.MathLib.*;
  24.  
  25. public class RingTile2Func extends VariationFunc  {
  26.   private static final long serialVersionUID = 1L;
  27.  
  28.   private static final String PARAM_POWER = "power";
  29.   private static final String PARAM_TILESIZE = "tilesize";
  30.   private static final String PARAM_WIDTH1 = "width1";
  31.   private static final String PARAM_WIDTH2 = "width2";
  32.   private static final String PARAM_OUTLINE = "outline";
  33.   private static final String PARAM_RING = "ring";
  34.  
  35.  
  36.   private static final String[] paramNames = {PARAM_POWER, PARAM_TILESIZE, PARAM_WIDTH1, PARAM_WIDTH2, PARAM_OUTLINE, PARAM_RING};
  37.  
  38.  
  39.   private double power = 5.0;
  40.   private double tilesize = 0.50;
  41.   private double width1 = 0.50;
  42.   private double width2 = 0.30;
  43.   private double outline = 0.000001;
  44.   private int ring = 1;
  45.  
  46.  
  47.   @Override
  48.   public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
  49.     /* ringtile by Brad Stefanov and Whittaker Courtney   */
  50.      double _yr1 = outline * width2;
  51.      double yh = -power;
  52.      double xr, yr;
  53.       if (pContext.random() < 0.5)
  54.         yh = power;
  55.       yr = tilesize * (pAffineTP.y + Math.round(yh * log(pContext.random())));
  56.       if (pAffineTP.x > width2) {
  57.         xr = width1 * (-width2 + fmod(pAffineTP.x + width2, _yr1));
  58.       }
  59.        else if (pAffineTP.x < -width2) {
  60.         xr = width1 * (width2 - fmod(width2 - pAffineTP.x, _yr1));
  61.       }
  62.        else {
  63.         xr = width1 * pAffineTP.x;
  64.       }
  65.      
  66.         Complex z = new Complex(xr, yr);
  67.         if (ring != 0)
  68.           z.Exp();
  69.         pVarTP.x += pAmount * z.re;  
  70.         pVarTP.y += pAmount * z.im;
  71.  
  72.     if (pContext.isPreserveZCoordinate()) {
  73.       pVarTP.z += pAmount * pAffineTP.z;
  74.     }
  75.   }
  76.  
  77.   @Override
  78.   public String[] getParameterNames() {
  79.     return paramNames;
  80.   }
  81.  
  82.   @Override
  83.   public Object[] getParameterValues() {
  84.     return new Object[]{power, tilesize, width1, width2, outline, ring};
  85.   }
  86.  
  87.   @Override
  88.   public void setParameter(String pName, double pValue) {
  89.     if (PARAM_POWER.equalsIgnoreCase(pName))
  90.       power = pValue;
  91.     else if (PARAM_TILESIZE.equalsIgnoreCase(pName))
  92.       tilesize = pValue;
  93.     else if (PARAM_WIDTH1.equalsIgnoreCase(pName))
  94.       width1 = pValue;
  95.     else if (PARAM_WIDTH2.equalsIgnoreCase(pName))
  96.       width2 = pValue;
  97.     else if (PARAM_OUTLINE.equalsIgnoreCase(pName))
  98.       outline = pValue;
  99.     else if (PARAM_RING .equalsIgnoreCase(pName))
  100.       ring = (int) limitVal(pValue, 0, 1);
  101.     else
  102.       throw new IllegalArgumentException(pName);
  103.   }
  104.  
  105.   @Override
  106.   public String getName() {
  107.     return "ringtile2";
  108.   }
  109.  
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement