Advertisement
snicker02

Untitled

Aug 13th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 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.*;
  20.  
  21.  
  22. import org.jwildfire.create.tina.base.Layer;
  23. import org.jwildfire.create.tina.base.XForm;
  24. import org.jwildfire.create.tina.base.XYZPoint;
  25.  
  26. public class IntersectionFunc extends VariationFunc {
  27. private static final long serialVersionUID = 1L;
  28.  
  29. private static final String PARAM_X1 = "x1";
  30. private static final String PARAM_X2 = "x2";
  31. private static final String PARAM_X3 = "x3";
  32. private static final String PARAM_X4 = "x4";
  33. private static final String PARAM_Y1 = "y1";
  34. private static final String PARAM_Y2 = "y2";
  35. private static final String PARAM_Y3 = "y3";
  36. private static final String PARAM_Y4 = "y4";
  37. private static final String PARAM_XREPEAT = "xrepeat";
  38. private static final String PARAM_YREPEAT = "yrepeat";
  39.  
  40.  
  41. private static final String[] paramNames = { PARAM_X1, PARAM_X2, PARAM_X3, PARAM_X4, PARAM_Y1, PARAM_Y2, PARAM_Y3,
  42. PARAM_Y4, PARAM_XREPEAT, PARAM_YREPEAT };
  43.  
  44. private double x1 = 5.0;
  45. private double x2 = 0.30;
  46. private double x3 = 0.30;
  47. private double x4 = 0.50;
  48. private double y1 = 5.0;
  49. private double y2 = 0.30;
  50. private double y3 = 0.30;
  51. private double y4 = 0.50;
  52. private double xrepeat = 1.0;
  53. private double yrepeat = 1.0;
  54.  
  55.  
  56. @Override
  57. public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP,
  58. double pAmount) {
  59. /* Modulus in the Apophysis Plugin Pack */
  60.  
  61. if (pContext.random() < 0.5) {
  62.  
  63. double x = -x1;
  64. if (pContext.random() < 0.5)
  65. x = x1;
  66.  
  67. pVarTP.x += x2 * (pAffineTP.x + round(x * log(pContext.random())));
  68.  
  69. if (pAffineTP.y > x3) {
  70. pVarTP.y += x4 * (-x3 + fmod(pAffineTP.y + x3, _xr1));
  71. } else if (pAffineTP.y < -x3) {
  72. pVarTP.y += x4 * (x3 - fmod(x3 - pAffineTP.y, _xr1));
  73. } else {
  74.  
  75. pVarTP.y += x4 * pAffineTP.y;
  76. }
  77. } else {
  78.  
  79. double y = -y1;
  80. if (pContext.random() < 0.5)
  81. y = y1;
  82.  
  83. pVarTP.y += y2 * (pAffineTP.y + round(y * log(pContext.random())));
  84.  
  85. if (pAffineTP.x > y3) {
  86. pVarTP.x += y4 * (-y3 + fmod(pAffineTP.x + y3, _yr1));
  87. } else if (pAffineTP.x < -y3) {
  88. pVarTP.x += y4 * (y3 - fmod(y3 - pAffineTP.x, _yr1));
  89. } else {
  90. pVarTP.x += y4 * pAffineTP.x;
  91.  
  92. }
  93. }
  94. if (pContext.isPreserveZCoordinate()) {
  95. pVarTP.z += pAmount * pAffineTP.z;
  96. }
  97. }
  98.  
  99. @Override
  100. public String[] getParameterNames() {
  101. return paramNames;
  102. }
  103.  
  104. @Override
  105. public Object[] getParameterValues() {
  106. return new Object[] { x1, x2, x3, x4, y1, y2, y3, y4, xrepeat, yrepeat};
  107. }
  108.  
  109. @Override
  110. public void setParameter(String pName, double pValue) {
  111. if (PARAM_X1.equalsIgnoreCase(pName))
  112. x1 = pValue;
  113. else if (PARAM_X2.equalsIgnoreCase(pName))
  114. x2 = pValue;
  115. else if (PARAM_X3.equalsIgnoreCase(pName))
  116. x3 = pValue;
  117. else if (PARAM_X4.equalsIgnoreCase(pName))
  118. x4 = pValue;
  119. else if (PARAM_Y1.equalsIgnoreCase(pName))
  120. y1 = pValue;
  121. else if (PARAM_Y2.equalsIgnoreCase(pName))
  122. y2 = pValue;
  123. else if (PARAM_Y3.equalsIgnoreCase(pName))
  124. y3 = pValue;
  125. else if (PARAM_Y4.equalsIgnoreCase(pName))
  126. y4 = pValue;
  127. else if (PARAM_XREPEAT.equalsIgnoreCase(pName))
  128. xrepeat = pValue;
  129. else if (PARAM_YREPEAT.equalsIgnoreCase(pName))
  130. yrepeat = pValue;
  131. else
  132. throw new IllegalArgumentException(pName);
  133. }
  134.  
  135. @Override
  136. public String getName() {
  137. return "intersection";
  138. }
  139.  
  140. private double _xr1, _yr1;
  141.  
  142. @Override
  143. public void init(FlameTransformationContext pContext, Layer pLayer, XForm pXForm, double pAmount) {
  144. _xr1 = xrepeat * x3;
  145. _yr1 = yrepeat * y3;
  146.  
  147. }
  148.  
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement