Advertisement
snicker02

Untitled

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