Advertisement
snicker02

bad code 1

Jun 13th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 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 org.jwildfire.base.mathlib.MathLib.*;
  23.  
  24. public class Waves23Func extends VariationFunc {
  25. private static final long serialVersionUID = 1L;
  26.  
  27.  
  28. private static final String PARAM_WD = "wd";
  29. private static final String PARAM_MODE = "mode";
  30. private static final String PARAM_INV = "inv";
  31. private static final String PARAM_SEED = "seed";
  32. private static final String[] paramNames = {PARAM_WD, PARAM_MODE, PARAM_INV, PARAM_SEED};
  33.  
  34. private double wd = 0.05;
  35. private int mode = 0;
  36. private int inv = 0;
  37. private int seed = 13;
  38.  
  39. private final static double M_SQRT3_2 = 0.86602540378443864676372317075249;
  40. private final static double M_SQRT3 = 1.73205080756887729352;
  41.  
  42. @Override
  43. public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
  44. /* waves23 from Tatyana Zabanova converted by Brad Stefanov https://www.deviantart.com/tatasz/art/Weird-Waves-Plugin-Pack-1-783560564*/
  45.  
  46. //get hex
  47. double x = 0.57735026918962576450914878050196 * pAffineTP.x - pAffineTP.y / 3.0; // sqrt(3) / 3
  48. double z = 2.0 * pAffineTP.y / 3.0;
  49. double y = -x - z;
  50.  
  51. //round
  52. double rx = round(x);
  53. double ry = round(y);
  54. double rz = round(z);
  55.  
  56. double x_diff = abs(rx - x);
  57. double y_diff = abs(ry - y);
  58. double z_diff = abs(rz - z);
  59.  
  60. if ((x_diff > y_diff) & (x_diff > z_diff)){
  61. rx = -ry-rz;
  62. } else if (y_diff > z_diff){
  63. ry = -rx-rz;
  64. } else {
  65. rz = -rx-ry;
  66. }
  67.  
  68. double FX_h = M_SQRT3 * rx + M_SQRT3_2 * rz;
  69. double FY_h = 1.5 * rz;
  70.  
  71. double FX = pAffineTP.x - FX_h;
  72. double FY = pAffineTP.y - FY_h;
  73.  
  74. double add = 0.0;
  75.  
  76. if (seed == 1){
  77. if ((int(rx) % 2 == 0) & (int(rz) % 2 == 0)) {
  78. add = 1.0471975511965977461542144610932;
  79. }
  80. }
  81. if (seed >= 2){
  82. double hash_f = sin(FX_h * 12.9898 + FY_h * 78.233 + double(seed)) * 43758.5453;
  83. hash_f = hash_f - floor(hash_f);
  84. if (hash_f < 0.5) {
  85. add = 1.0471975511965977461542144610932; //pi/3
  86. }
  87. }
  88.  
  89. double angle = atan2(FY, FX) + 0.52359877559829887307710723054658 - add; // pi/6
  90. double coef = 0.47746482927568600730665129011754; //1.5 / pi
  91. double angle2 = floor(angle * coef) / coef + 0.52359877559829887307710723054658 + add; //or subtract 0.5
  92. double x0 = cos(angle2);
  93. double y0 = sin(angle2);
  94. double dist = sqrt(sqr(FX - x0) + sqr(FY - y0));
  95. double d1 = 0.5 + wd;
  96. double d2 = 0.5 - wd;
  97. if (inv){
  98. if ((dist > d1) | (dist < d2)){
  99. if (mode < 0.5){
  100. FX = 0.0;
  101. FY = 0.0;
  102. } else {
  103. if (mode < 1.5){
  104. FX = x0;
  105. FY = y0;
  106. } else {
  107. double rangle = atan2(FY - y0, FX - x0);
  108. double D;
  109. if (pContext.random() < 0.5){
  110. D = d1;
  111. } else {
  112. D = d2;
  113. }
  114. FX = x0 + cos(rangle) * D;
  115. FY = y0 + sin(rangle) * D;
  116. }
  117. }
  118. }
  119.  
  120. } else {
  121. if ((dist < d1) & (dist > d2)){
  122. if mode < 0.5){
  123. FX = 0.0;
  124. FY = 0.0;
  125. } else {
  126. if mode < 1.5){
  127. FX = x0;
  128. FY = y0;
  129. } else {
  130. double rangle = atan2(FY - y0, FX - x0);
  131. double D;
  132. if (pContext.random() < 0.5){
  133. D = d1;
  134. } else {
  135. D = d2;
  136. }
  137. FX = x0 + cos(rangle) * D;
  138. FY = y0 + sin(rangle) * D;
  139. }
  140. }
  141. }
  142. }
  143.  
  144. pVarTP.x += (FX + FX_h)* pAmount;
  145. pVarTP.y += (FY + FY_h)* pAmount;
  146. }
  147.  
  148. @Override
  149. public String[] getParameterNames() {
  150. return paramNames;
  151. }
  152.  
  153. @Override
  154. public Object[] getParameterValues() {
  155. return new Object[]{wd, mode, inv, seed};
  156. }
  157.  
  158. @Override
  159. public void setParameter(String pName, double pValue) {
  160. if (PARAM_WD.equalsIgnoreCase(pName))
  161. wd = limitVal(pValue, 0, 5);
  162. else if (PARAM_MODE.equalsIgnoreCase(pName))
  163. mode = (int) limitVal(pValue, 0, 2);
  164. else if (PARAM_INV.equalsIgnoreCase(pName))
  165. inv = (int) limitVal(pValue, 0, 1);
  166. else if (PARAM_SEED.equalsIgnoreCase(pName))
  167. seed = (int) pValue;
  168. else
  169. throw new IllegalArgumentException(pName);
  170. }
  171.  
  172. @Override
  173. public String getName() {
  174. return "waves23";
  175. }
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement