Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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 static org.jwildfire.base.mathlib.MathLib.*;
- import org.jwildfire.create.tina.base.Layer;
- import org.jwildfire.create.tina.base.XForm;
- import org.jwildfire.create.tina.base.XYZPoint;
- public class IntersectionFunc extends VariationFunc {
- private static final long serialVersionUID = 1L;
- private static final String PARAM_X1 = "x1";
- private static final String PARAM_X2 = "x2";
- private static final String PARAM_X3 = "x3";
- private static final String PARAM_X4 = "x4";
- private static final String PARAM_Y1 = "y1";
- private static final String PARAM_Y2 = "y2";
- private static final String PARAM_Y3 = "y3";
- private static final String PARAM_Y4 = "y4";
- private static final String PARAM_XREPEAT = "xrepeat";
- private static final String PARAM_YREPEAT = "yrepeat";
- private static final String[] paramNames = { PARAM_X1, PARAM_X2, PARAM_X3, PARAM_X4, PARAM_Y1, PARAM_Y2, PARAM_Y3,
- PARAM_Y4, PARAM_XREPEAT, PARAM_YREPEAT };
- private double x1 = 5.0;
- private double x2 = 0.30;
- private double x3 = 0.30;
- private double x4 = 0.50;
- private double y1 = 5.0;
- private double y2 = 0.30;
- private double y3 = 0.30;
- private double y4 = 0.50;
- private double xrepeat = 1.0;
- private double yrepeat = 1.0;
- @Override
- public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP,
- double pAmount) {
- /* Modulus in the Apophysis Plugin Pack */
- if (pContext.random() < 0.5) {
- double x = -x1;
- if (pContext.random() < 0.5)
- x = x1;
- pVarTP.x += x2 * (pAffineTP.x + round(x * log(pContext.random())));
- if (pAffineTP.y > x3) {
- pVarTP.y += x4 * (-x3 + fmod(pAffineTP.y + x3, _xr1));
- } else if (pAffineTP.y < -x3) {
- pVarTP.y += x4 * (x3 - fmod(x3 - pAffineTP.y, _xr1));
- } else {
- pVarTP.y += x4 * pAffineTP.y;
- }
- } else {
- double y = -y1;
- if (pContext.random() < 0.5)
- y = y1;
- pVarTP.y += y2 * (pAffineTP.y + round(y * log(pContext.random())));
- if (pAffineTP.x > y3) {
- pVarTP.x += y4 * (-y3 + fmod(pAffineTP.x + y3, _yr1));
- } else if (pAffineTP.x < -y3) {
- pVarTP.x += y4 * (y3 - fmod(y3 - pAffineTP.x, _yr1));
- } else {
- pVarTP.x += y4 * pAffineTP.x;
- }
- }
- if (pContext.isPreserveZCoordinate()) {
- pVarTP.z += pAmount * pAffineTP.z;
- }
- }
- @Override
- public String[] getParameterNames() {
- return paramNames;
- }
- @Override
- public Object[] getParameterValues() {
- return new Object[] { x1, x2, x3, x4, y1, y2, y3, y4, xrepeat, yrepeat};
- }
- @Override
- public void setParameter(String pName, double pValue) {
- if (PARAM_X1.equalsIgnoreCase(pName))
- x1 = pValue;
- else if (PARAM_X2.equalsIgnoreCase(pName))
- x2 = pValue;
- else if (PARAM_X3.equalsIgnoreCase(pName))
- x3 = pValue;
- else if (PARAM_X4.equalsIgnoreCase(pName))
- x4 = pValue;
- else if (PARAM_Y1.equalsIgnoreCase(pName))
- y1 = pValue;
- else if (PARAM_Y2.equalsIgnoreCase(pName))
- y2 = pValue;
- else if (PARAM_Y3.equalsIgnoreCase(pName))
- y3 = pValue;
- else if (PARAM_Y4.equalsIgnoreCase(pName))
- y4 = pValue;
- else if (PARAM_XREPEAT.equalsIgnoreCase(pName))
- xrepeat = pValue;
- else if (PARAM_YREPEAT.equalsIgnoreCase(pName))
- yrepeat = pValue;
- else
- throw new IllegalArgumentException(pName);
- }
- @Override
- public String getName() {
- return "intersection";
- }
- private double _xr1, _yr1;
- @Override
- public void init(FlameTransformationContext pContext, Layer pLayer, XForm pXForm, double pAmount) {
- _xr1 = xrepeat * x3;
- _yr1 = yrepeat * y3;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement