Advertisement
snicker02

Untitled

May 18th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 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 LazyWFFunc 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
  63. */
  64. double x = pAffineTP.x;
  65. double y = pAffineTP.y;
  66. double z = pAffineTP.z;
  67.  
  68. if (scale_x != 0.0) {
  69. double nr = (int) floor((x - shift_x) * scale_x);
  70. if (nr >= 0) {
  71. if (nr % nx == (nx - 1))
  72. x = 2 * shift_x - x;
  73. } else {
  74. if (nr % nx == 0)
  75. x = 2 * shift_x - x;
  76. }
  77. }
  78. if (scale_y != 0.0) {
  79. double nr = (int) floor((y - shift_y) * scale_y);
  80. if (nr >= 0) {
  81. if (nr % ny == (ny - 1))
  82. y = 2 * shift_y - y;
  83. } else {
  84. if (nr % ny == 0)
  85. y = 2 * shift_y - y;
  86. }
  87. }
  88. if (scale_z != 0.0) {
  89. double nr = (int) floor((z - shift_z) * scale_z);
  90. if (nr >= 0) {
  91. if (nr % nz == (nz - 1))
  92. z = 2 * shift_z - z;
  93. } else {
  94. if (nr % nz == 0)
  95. z = 2 * shift_z - z;
  96. }
  97. }
  98.  
  99. double uu = u * pAffineTP.x;
  100. double h = sin(Math.toRadians(angle));
  101. double k = cos(Math.toRadians(angle));
  102. double vv = v * (k * uu + h * pAffineTP.y);
  103. double ww = w * (k * uu - h * pAffineTP.y);
  104. int blocku = (int) floor(uu * width);
  105. blocku += (2.0 - 4.0 * hash(blocku * seed + 1));// varying width and length
  106. int blockv = (int) floor(vv * width);
  107. blockv += (2.0 - 4.0 * hash(blockv * seed + 1));
  108. int blockw = (int) floor(ww * width);
  109. blockw += (2.0 - 4.0 * hash(blockw * seed + 1));
  110. double fLen = (hash(blocku + blockv + blockw * -seed) + hash(blocku + blockv + blockw * seed / 2));
  111. // Doesn't matter just needs to be random enough
  112. double xx = pAffineTP.x - x;
  113. double yy = pAffineTP.y + y;
  114. double zz = pAffineTP.z + z;
  115.  
  116. pVarTP.x += pAmount * xx * fLen + x;
  117. pVarTP.y += pAmount * yy * fLen - y;
  118.  
  119. pVarTP.z += pAmount * zz * fLen - z;
  120.  
  121. }
  122.  
  123. @Override
  124. public String[] getParameterNames() {
  125. return paramNames;
  126. }
  127.  
  128. @Override
  129. public Object[] getParameterValues() {
  130. return new Object[] { scale_x, shift_x, nx, scale_y, shift_y, ny, scale_z, shift_z, nz, width, seed, angle, u,
  131. v, w };
  132. }
  133.  
  134. @Override
  135. public void setParameter(String pName, double pValue) {
  136. if (PARAM_SCALEX.equalsIgnoreCase(pName))
  137. scale_x = pValue;
  138. else if (PARAM_SHIFTX.equalsIgnoreCase(pName))
  139. shift_x = pValue;
  140. else if (PARAM_NX.equalsIgnoreCase(pName))
  141. nx = Tools.limitValue(Tools.FTOI(pValue), 1, 100);
  142. else if (PARAM_SCALEY.equalsIgnoreCase(pName))
  143. scale_y = pValue;
  144. else if (PARAM_SHIFTY.equalsIgnoreCase(pName))
  145. shift_y = pValue;
  146. else if (PARAM_NY.equalsIgnoreCase(pName))
  147. ny = Tools.limitValue(Tools.FTOI(pValue), 1, 100);
  148. else if (PARAM_SCALEZ.equalsIgnoreCase(pName))
  149. scale_z = pValue;
  150. else if (PARAM_SHIFTZ.equalsIgnoreCase(pName))
  151. shift_z = pValue;
  152. else if (PARAM_NZ.equalsIgnoreCase(pName))
  153. nz = Tools.limitValue(Tools.FTOI(pValue), 1, 100);
  154. else if (PARAM_WIDTH.equalsIgnoreCase(pName))
  155. width = pValue;
  156. else if (PARAM_SEED.equalsIgnoreCase(pName))
  157. seed = Tools.FTOI(pValue);
  158. else if (PARAM_ANGLE.equalsIgnoreCase(pName))
  159. angle = pValue;
  160. else if (PARAM_UU.equalsIgnoreCase(pName)) {
  161. u = pValue;
  162. } else if (PARAM_VV.equalsIgnoreCase(pName)) {
  163. v = pValue;
  164. } else if (PARAM_WW.equalsIgnoreCase(pName)) {
  165. w = pValue;
  166. }
  167.  
  168. else
  169. throw new IllegalArgumentException(pName);
  170. }
  171.  
  172. @Override
  173. public String getName() {
  174. return "lazy_wf";
  175. }
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement