Advertisement
snicker02

Hole2 update with invert

Nov 23rd, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.02 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. import org.jwildfire.base.Tools;
  22. import org.jwildfire.create.tina.base.XForm;
  23. import org.jwildfire.create.tina.base.XYZPoint;
  24.  
  25. public class Hole2Func extends VariationFunc {
  26. private static final long serialVersionUID = 1L;
  27. private static final String PARAM_A = "a";
  28. private static final String PARAM_B = "b";
  29. private static final String PARAM_C = "c";
  30. private static final String PARAM_D = "d";
  31. public static final String PARAM_INSIDE = "inside";
  32. public static final String PARAM_SHAPE = "shape";
  33. public static final String PARAM_INVERT = "invert";
  34. private static final String[] paramNames = { PARAM_A, PARAM_B, PARAM_C, PARAM_D, PARAM_INSIDE, PARAM_SHAPE, PARAM_INVERT };
  35.  
  36. private double a = 1.0;
  37. private double b = 2.0;
  38. private double c = 1.0;
  39. private double d = 1.0;
  40.  
  41. private int inside = 0;
  42. private int shape = 0;
  43. private int invert = 0;
  44.  
  45. @Override
  46. public void transform(FlameTransformationContext pContext, XForm pXForm,
  47. XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
  48. // Hole3 by Michael Faber, Brad Stefanov, and Rick Sidwell
  49. if (invert == 0) {
  50.  
  51. double rhosq = pAffineTP.getPrecalcSumsq();
  52. double theta = pAffineTP.getPrecalcAtanYX() * d;
  53. double delta = pow(theta / M_PI + 1.0, a) * c;
  54. double r1 = 1;
  55.  
  56.  
  57.  
  58. switch (shape) {
  59. case 0: // hole
  60. r1 = sqrt(rhosq) + delta;
  61. break;
  62. case 1:// hole1
  63. r1 = sqrt(rhosq + delta);
  64. break;
  65. case 2:// double hole
  66. r1 = sqrt(rhosq + sin(b * theta) + delta);
  67. break;
  68. case 3:// heart
  69. r1 = sqrt(rhosq + sin(theta) + delta);
  70. break;
  71. case 4:// heart2
  72. r1 = sqrt(rhosq + sqr(theta) - delta + 1);
  73. break;
  74. case 5:
  75. r1 = sqrt(rhosq + fabs(tan(theta)) + delta);
  76. break;
  77. case 6:
  78. r1 = sqrt(rhosq * (1 + sin(b * theta)) + delta);
  79. break;
  80. case 7:
  81. r1 = sqrt(rhosq + fabs(sin(0.5 * b * theta)) + delta);
  82. break;
  83. case 8:
  84. r1 = sqrt(rhosq + sin(M_PI * sin(b * theta)) + delta);
  85. break;
  86. case 9:
  87. r1 = sqrt(rhosq + (sin(b * theta) + sin(2 * b * theta + M_PI_2)) / 2 + delta);
  88. break;
  89. }
  90.  
  91. if (inside != 0)
  92. r1 = pAmount / r1;
  93. else
  94. r1 = pAmount * r1;
  95.  
  96. pVarTP.x += r1 * cos(theta);
  97. pVarTP.y += r1 * sin(theta);
  98. if (pContext.isPreserveZCoordinate()) {
  99. pVarTP.z += pAmount * pAffineTP.z;
  100. }
  101. }
  102. else /*if (invert == 1)*/{
  103. double rhosq = -pAffineTP.getPrecalcSumsq();
  104. double theta = -pAffineTP.getPrecalcAtanYX() * d;
  105. double delta = pow(theta / M_PI - 1.0, a) * c;
  106. double r1 = 1;
  107.  
  108.  
  109. switch (shape) {
  110. case 0: // hole
  111. r1 = sqrt(rhosq) + delta;
  112. break;
  113. case 1:// hole1
  114. r1 = sqrt(rhosq + delta);
  115. break;
  116. case 2:// double hole
  117. r1 = sqrt(rhosq + sin(b * theta) + delta);
  118. break;
  119. case 3:// heart
  120. r1 = sqrt(rhosq + sin(theta) + delta);
  121. break;
  122. case 4:// heart2
  123. r1 = sqrt(rhosq + sqr(theta) - delta + 1);
  124. break;
  125. case 5:
  126. r1 = sqrt(rhosq + fabs(tan(theta)) + delta);
  127. break;
  128. case 6:
  129. r1 = sqrt(rhosq * (1 + sin(b * theta)) + delta);
  130. break;
  131. case 7:
  132. r1 = sqrt(rhosq + fabs(sin(0.5 * b * theta)) + delta);
  133. break;
  134. case 8:
  135. r1 = sqrt(rhosq + sin(M_PI * sin(b * theta)) + delta);
  136. break;
  137. case 9:
  138. r1 = sqrt(rhosq + (sin(b * theta) + sin(2 * b * theta + M_PI_2)) / 2 + delta);
  139. break;
  140. }
  141.  
  142. if (inside != 0)
  143. r1 = pAmount / r1;
  144. else
  145. r1 = pAmount * r1;
  146.  
  147. pVarTP.x += r1 * cos(theta);
  148. pVarTP.y += r1 * sin(theta);
  149. if (pContext.isPreserveZCoordinate()) {
  150. pVarTP.z += pAmount * pAffineTP.z;
  151. }
  152. }
  153.  
  154. }
  155.  
  156. @Override
  157. public String[] getParameterNames() {
  158. return paramNames;
  159. }
  160.  
  161. @Override
  162. public Object[] getParameterValues() {
  163. return new Object[] { a, b, c, d, inside, shape, invert };
  164. }
  165.  
  166. @Override
  167. public void setParameter(String pName, double pValue) {
  168. if (PARAM_A.equalsIgnoreCase(pName))
  169. a = pValue;
  170. else if (PARAM_B.equalsIgnoreCase(pName))
  171. b = pValue;
  172. else if (PARAM_C.equalsIgnoreCase(pName))
  173. c = pValue;
  174. else if (PARAM_D.equalsIgnoreCase(pName))
  175. d = pValue;
  176. else if (PARAM_INSIDE.equalsIgnoreCase(pName))
  177. inside = limitIntVal(Tools.FTOI(pValue), 0, 1);
  178.  
  179. else if (PARAM_SHAPE.equalsIgnoreCase(pName))
  180. shape = limitIntVal(Tools.FTOI(pValue), 0, 9);
  181. else if (PARAM_INVERT.equalsIgnoreCase(pName))
  182. invert = Tools.FTOI(pValue);
  183.  
  184. else
  185. throw new IllegalArgumentException(pName);
  186. }
  187.  
  188. @Override
  189. public String getName() {
  190. return "hole2";
  191. }
  192.  
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement