Advertisement
snicker02

bad code 2

Jun 13th, 2019
132
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. This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
  5. General Public License as published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7.  
  8. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  9. even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License along with this software;
  12. if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  13. 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  14. */
  15. package org.jwildfire.create.tina.variation;
  16.  
  17. import org.jwildfire.create.tina.base.XForm;
  18. import org.jwildfire.create.tina.base.XYZPoint;
  19.  
  20. import static org.jwildfire.base.mathlib.MathLib.M_PI;
  21. import static java.lang.Math.abs;
  22. import static java.lang.Math.*;
  23. import static org.jwildfire.base.mathlib.MathLib.*;
  24.  
  25. public class Waves23Func extends VariationFunc {
  26. private static final long serialVersionUID = 1L;
  27.  
  28.  
  29. private static final String PARAM_WD = "wd";
  30. private static final String PARAM_MODE = "mode";
  31. private static final String PARAM_INV = "inv";
  32. private static final String PARAM_SEED = "seed";
  33. private static final String[] paramNames = {PARAM_WD, PARAM_MODE, PARAM_INV, PARAM_SEED};
  34.  
  35. private double wd = 0.05;
  36. private int mode = 0;
  37. private int inv = 0;
  38. private int seed = 13;
  39.  
  40. private final static double M_SQRT3_2 = 0.86602540378443864676372317075249;
  41. private final static double M_SQRT3 = 1.73205080756887729352;
  42.  
  43. @Override
  44. public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
  45. /* waves23 from Tatyana Zabanova converted by Brad Stefanov https://www.deviantart.com/tatasz/art/Weird-Waves-Plugin-Pack-1-783560564*/
  46.  
  47. //get hex
  48. double x = 0.57735026918962576450914878050196 * pAffineTP.x - pAffineTP.y / 3.0; // sqrt(3) / 3
  49. double z = 2.0 * pAffineTP.y / 3.0;
  50. double y = -x - z;
  51.  
  52. //round
  53. double rx = round(x);
  54. double ry = round(y);
  55. double rz = round(z);
  56.  
  57. double x_diff = abs(rx - x);
  58. double y_diff = abs(ry - y);
  59. double z_diff = abs(rz - z);
  60.  
  61. if ((x_diff > y_diff) && (x_diff > z_diff)){ // only &
  62. rx = -ry-rz;
  63. } else if (y_diff > z_diff){
  64. ry = -rx-rz;
  65. } else {
  66. rz = -rx-ry;
  67. }
  68.  
  69. double FX_h = M_SQRT3 * rx + M_SQRT3_2 * rz;
  70. double FY_h = 1.5 * rz;
  71.  
  72. double FX = pAffineTP.x - FX_h;
  73. double FY = pAffineTP.y - FY_h;
  74.  
  75. double add = 0.0;
  76.  
  77. if (seed == 1){
  78. if (((rx) == 0) && ((rz) == 0)) { //&& , %? if ((int(rx) % 2 == 0) && (int(rz) % 2 == 0))
  79. add = 1.0471975511965977461542144610932;
  80. }
  81. }
  82. if (seed >= 2){
  83. double hash_f = sin(FX_h * 12.9898 + FY_h * 78.233 + (seed)) * 43758.5453; // double(seed) causing issue)
  84. hash_f = hash_f - floor(hash_f);
  85. if (hash_f < 0.5) {
  86. add = 1.0471975511965977461542144610932; //pi/3
  87. }
  88. }
  89.  
  90. double angle = atan2(FY, FX) + 0.52359877559829887307710723054658 - add; // pi/6
  91. double coef = 0.47746482927568600730665129011754; //1.5 / pi
  92. double angle2 = floor(angle * coef) / coef + 0.52359877559829887307710723054658 + add; //or subtract 0.5
  93. double x0 = cos(angle2);
  94. double y0 = sin(angle2);
  95. double dist = sqrt(sqr(FX - x0) + sqr(FY - y0));
  96. double d1 = 0.5 + wd;
  97. double d2 = 0.5 - wd;
  98. if (inv == 0){ // no condition?
  99. if ((dist > d1) || (dist < d2)){ // only |
  100. if (mode < 0.5){
  101. FX = 0.0;
  102. FY = 0.0;
  103. } else {
  104. if (mode < 1.5){
  105. FX = x0;
  106. FY = y0;
  107. } else {
  108. double rangle = atan2(FY - y0, FX - x0);
  109. double D =0; // D equals?
  110. if (pContext.random() < 0.5){
  111. D = d1;
  112. } else {
  113. D = d2;
  114. }
  115. FX = x0 + cos(rangle) * D;
  116. FY = y0 + sin(rangle) * D;
  117. }
  118. }
  119. }
  120.  
  121. }
  122. // else {
  123. // if ((dist < d1) && (dist > d2)){
  124. // if mode < 0.5){
  125. // FX = 0.0;
  126. // FY = 0.0;
  127. // } else {
  128. // if (mode < 1.5){ // missing (
  129. // FX = x0;
  130. // FY = y0;
  131. // } else {
  132. // double rangle = atan2(FY - y0, FX - x0);
  133. // double D = 0; // D equals?
  134. // if (pContext.random() < 0.5){
  135. // D = d1;
  136. // } else {
  137. // D = d2;
  138. // }
  139. // FX = x0 + cos(rangle) * D;
  140. // FY = y0 + sin(rangle) * D;
  141. // }
  142. // }
  143. // }
  144. // }
  145.  
  146. pVarTP.x += (FX + FX_h)* pAmount;
  147. pVarTP.y += (FY + FY_h)* pAmount;
  148. }
  149.  
  150. @Override
  151. public String[] getParameterNames() {
  152. return paramNames;
  153. }
  154.  
  155. @Override
  156. public Object[] getParameterValues() {
  157. return new Object[]{wd, mode, inv, seed};
  158. }
  159.  
  160. @Override
  161. public void setParameter(String pName, double pValue) {
  162. if (PARAM_WD.equalsIgnoreCase(pName))
  163. wd = limitVal(pValue, 0, 5);
  164. else if (PARAM_MODE.equalsIgnoreCase(pName))
  165. mode = (int) limitVal(pValue, 0, 2);
  166. else if (PARAM_INV.equalsIgnoreCase(pName))
  167. inv = (int) limitVal(pValue, 0, 1);
  168. else if (PARAM_SEED.equalsIgnoreCase(pName))
  169. seed = (int) pValue;
  170. else
  171. throw new IllegalArgumentException(pName);
  172. }
  173.  
  174. @Override
  175. public String getName() {
  176. return "waves23";
  177. }
  178.  
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement