Advertisement
snicker02

Untitled

May 19th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.33 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 org.jwildfire.create.tina.base.XForm;
  20. import org.jwildfire.create.tina.base.XYZPoint;
  21. import org.jwildfire.create.tina.variation.FlameTransformationContext;
  22. import static org.jwildfire.base.mathlib.MathLib.*;
  23.  
  24. import org.jwildfire.base.Tools;
  25.  
  26. public class Glitchy1Func extends VariationFunc {
  27. private static final long serialVersionUID = 1L;
  28.  
  29. private static final String PARAM_SCALEX = "scale_x";
  30. private static final String PARAM_SHIFTX = "shift_x";
  31. private static final String PARAM_NX = "n_x";
  32. private static final String PARAM_SCALEY = "scale_y";
  33. private static final String PARAM_SHIFTY = "shift_y";
  34. private static final String PARAM_NY = "n_y";
  35. private static final String PARAM_SCALEZ = "scale_z";
  36. private static final String PARAM_SHIFTZ = "shift_z";
  37. private static final String PARAM_NZ = "n_z";
  38. private static final String PARAM_WIDTH = "width";
  39. private static final String PARAM_SEED = "seed";
  40. private static final String PARAM_ANGLE = "angle";
  41. private static final String PARAM_UU = "u";
  42. private static final String PARAM_VV = "v";
  43. private static final String PARAM_WW = "w";
  44.  
  45. private static final String[] paramNames = { PARAM_SCALEX, PARAM_SHIFTX, PARAM_NX, PARAM_SCALEY, PARAM_SHIFTY,
  46. PARAM_NY, PARAM_SCALEZ, PARAM_SHIFTZ, PARAM_NZ, PARAM_WIDTH, PARAM_SEED, PARAM_ANGLE, PARAM_UU, PARAM_VV,
  47. PARAM_WW };
  48. private double scale_x = 1;
  49. private double scale_y = 1;
  50. private double scale_z = 0;
  51. private double shift_x = 0;
  52. private double shift_y = 0;
  53. private double shift_z = 0;
  54. private int nx = 2;
  55. private int ny = 2;
  56. private int nz = 2;;
  57. private double width = 1.0;
  58. private int seed = 42;
  59. private double angle = 30;
  60. private double u = 1.0;
  61. private double v = 1.0;
  62. private double w = 1.0;
  63.  
  64. private double hash(int a) { // http://burtleburtle.net/bob/hash/integer.html
  65. a = (a ^ 61) ^ (a >> 16);
  66. a = a + (a << 3);
  67. a = a ^ (a >> 4);
  68. a = a * 0x27d4eb2d;
  69. a = a ^ (a >> 15);
  70. return (double) a / (double) Integer.MAX_VALUE;
  71. }
  72.  
  73. @Override
  74. public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP,
  75. double pAmount) {
  76. /*
  77. * Mix of lazysensen and pixel flow by bezo97, https://bezo97.tk/plugins.html
  78. * Variables added by Brad Stefanov and Rick Sidwell and special thanks to
  79. * dark-beam
  80. */
  81. double x = pAffineTP.x;
  82. double y = pAffineTP.y;
  83. double z = pAffineTP.z;
  84.  
  85. if (scale_x != 0.0) {
  86. double nr = (int) floor((x - shift_x) * scale_x);
  87. if (nr >= 0) {
  88. if (nr % nx == (nx - 1))
  89. x = 2 * shift_x - x;
  90. } else {
  91. if (nr % nx == 0)
  92. x = 2 * shift_x - x;
  93. }
  94. }
  95. if (scale_y != 0.0) {
  96. double nr = (int) floor((y - shift_y) * scale_y);
  97. if (nr >= 0) {
  98. if (nr % ny == (ny - 1))
  99. y = 2 * shift_y - y;
  100. } else {
  101. if (nr % ny == 0)
  102. y = 2 * shift_y - y;
  103. }
  104. }
  105. if (scale_z != 0.0) {
  106. double nr = (int) floor((z - shift_z) * scale_z);
  107. if (nr >= 0) {
  108. if (nr % nz == (nz - 1))
  109. z = 2 * shift_z - z;
  110. } else {
  111. if (nr % nz == 0)
  112. z = 2 * shift_z - z;
  113. }
  114. }
  115.  
  116. double uu = u * pAffineTP.x;
  117. double h = sin(Math.toRadians(angle));
  118. double k = cos(Math.toRadians(angle));
  119. double vv = v * (k * uu + h * pAffineTP.y);
  120. double ww = w * (k * uu - h * pAffineTP.y);
  121. int blocku = (int) floor(uu * width);
  122. blocku += (2.0 - 4.0 * hash(blocku * seed + 1));// varying width and length
  123. int blockv = (int) floor(vv * width);
  124. blockv += (2.0 - 4.0 * hash(blockv * seed + 1));
  125. int blockw = (int) floor(ww * width);
  126. blockw += (2.0 - 4.0 * hash(blockw * seed + 1));
  127. double fLen = (hash(blocku + blockv + blockw * -seed) + hash(blocku + blockv + blockw * seed / 2));
  128. // Doesn't matter just needs to be random enough
  129.  
  130. pVarTP.x += pAmount * x * fLen;
  131. pVarTP.y += pAmount * y * fLen;
  132. pVarTP.z += pAmount * z * fLen;
  133.  
  134. }
  135.  
  136. @Override
  137. public String[] getParameterNames() {
  138. return paramNames;
  139. }
  140.  
  141. @Override
  142. public Object[] getParameterValues() {
  143. return new Object[] { scale_x, shift_x, nx, scale_y, shift_y, ny, scale_z, shift_z, nz, width, seed, angle, u,
  144. v, w };
  145. }
  146.  
  147. @Override
  148. public void setParameter(String pName, double pValue) {
  149. if (PARAM_SCALEX.equalsIgnoreCase(pName))
  150. scale_x = pValue;
  151. else if (PARAM_SHIFTX.equalsIgnoreCase(pName))
  152. shift_x = pValue;
  153. else if (PARAM_NX.equalsIgnoreCase(pName))
  154. nx = Tools.limitValue(Tools.FTOI(pValue), 1, 100);
  155. else if (PARAM_SCALEY.equalsIgnoreCase(pName))
  156. scale_y = pValue;
  157. else if (PARAM_SHIFTY.equalsIgnoreCase(pName))
  158. shift_y = pValue;
  159. else if (PARAM_NY.equalsIgnoreCase(pName))
  160. ny = Tools.limitValue(Tools.FTOI(pValue), 1, 100);
  161. else if (PARAM_SCALEZ.equalsIgnoreCase(pName))
  162. scale_z = pValue;
  163. else if (PARAM_SHIFTZ.equalsIgnoreCase(pName))
  164. shift_z = pValue;
  165. else if (PARAM_NZ.equalsIgnoreCase(pName))
  166. nz = Tools.limitValue(Tools.FTOI(pValue), 1, 100);
  167. else if (PARAM_WIDTH.equalsIgnoreCase(pName))
  168. width = pValue;
  169. else if (PARAM_SEED.equalsIgnoreCase(pName))
  170. seed = Tools.FTOI(pValue);
  171. else if (PARAM_ANGLE.equalsIgnoreCase(pName))
  172. angle = pValue;
  173. else if (PARAM_UU.equalsIgnoreCase(pName)) {
  174. u = pValue;
  175. } else if (PARAM_VV.equalsIgnoreCase(pName)) {
  176. v = pValue;
  177. } else if (PARAM_WW.equalsIgnoreCase(pName)) {
  178. w = pValue;
  179. }
  180.  
  181. else
  182. throw new IllegalArgumentException(pName);
  183. }
  184.  
  185. @Override
  186. public String getName() {
  187. return "glitchy1";
  188. }
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement