Advertisement
rsidwell

dc_triTile

Oct 23rd, 2017
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.21 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.  
  20. import static org.jwildfire.base.mathlib.MathLib.sin;
  21. import static org.jwildfire.base.mathlib.MathLib.cos;
  22. import static org.jwildfire.base.mathlib.MathLib.fmod;
  23. import static org.jwildfire.base.mathlib.MathLib.sqr;
  24. import static org.jwildfire.base.mathlib.MathLib.sqrt;
  25. import static org.jwildfire.base.mathlib.MathLib.M_PI;
  26. import static org.jwildfire.base.mathlib.MathLib.M_2PI;
  27.  
  28. import org.jwildfire.base.Tools;
  29. import org.jwildfire.create.tina.base.Layer;
  30. import org.jwildfire.create.tina.base.XForm;
  31. import org.jwildfire.create.tina.base.XYZPoint;
  32. import org.jwildfire.create.tina.random.AbstractRandomGenerator;
  33.  
  34. public class DCTriTileFunc extends VariationFunc {
  35. private static final long serialVersionUID = 1L;
  36.  
  37. public static final double M_PHI = 1.6180339887498948482045868343656;
  38. public static final double M_1_PHI = 1.0 / M_PHI;
  39.  
  40. private static final String PARAM_TILING = "type";
  41. private static final String PARAM_T = "t";
  42. private static final String PARAM_COL1 = "col1";
  43. private static final String PARAM_COL2 = "col2";
  44. private static final String PARAM_ON = "on";
  45. private static final String PARAM_ITT = "itt";
  46. private static final String PARAM_EQ = "eq";
  47. private static final String PARAM_DEPTH = "depth";
  48. private static final String PARAM_ON1 = "on1";
  49. private static final String PARAM_ITT1 = "itt1";
  50. private static final String PARAM_EQ1 = "eq1";
  51. private static final String PARAM_DEPTH1 = "depth1";
  52. private static final String PARAM_ON2 = "on2";
  53. private static final String PARAM_ITT2 = "itt2";
  54. private static final String PARAM_EQ2 = "eq2";
  55. private static final String PARAM_DEPTH2 = "depth2";
  56.  
  57. private static final String[] paramNames = { PARAM_TILING, PARAM_T, PARAM_COL1, PARAM_COL2, PARAM_ON, PARAM_ITT, PARAM_EQ, PARAM_DEPTH,
  58. PARAM_ON1, PARAM_ITT1, PARAM_EQ1, PARAM_DEPTH1, PARAM_ON2, PARAM_ITT2, PARAM_EQ2, PARAM_DEPTH2 };
  59.  
  60. private int tiling = 1;
  61. private int t = 2;
  62. private double col1 = Math.round(Math.random() * 35 + 10) / 100.0, col2 = Math.round(Math.random() * 35 + 55) / 100.0;
  63. private double on = Math.round(Math.random()), on1 = Math.round(Math.random()), on2 = Math.round(Math.random());
  64. private int itt = (int) (Math.random() * 5 + 1), itt1 = (int) (Math.random() * 5), itt2 = (int) (Math.random() * 5);
  65. private int eq = (int) (Math.random() * 2 + 1), eq1 = (int) (Math.random() * 2 + 1), eq2 = (int) (Math.random() * 2 + 1);
  66. private int depth = (int) (Math.random() * 4), depth1 = (int) (Math.random() * 4), depth2 = (int) (Math.random() * 4);
  67.  
  68. private double discretNoise(int x) {
  69. int n = x;
  70. n = (n << 13) ^ n;
  71. return ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / (double) 0x7fffffff;
  72. }
  73.  
  74. private class triangle {
  75. int type;
  76. double x1, y1, x2, y2, x3, y3;
  77. double col;
  78.  
  79. public void assign(triangle t) {
  80. type = t.type; col = t.col;
  81. x1 = t.x1; y1 = t.y1;
  82. x2 = t.x2; y2 = t.y2;
  83. x3 = t.x3; y3 = t.y3;
  84. }
  85.  
  86. private void blur(XYZPoint p) {
  87. double u, v, v1, v2, w, x, x0, x1, x2, x3, x4, x5, x6, y, y0, y1, y2, y3, y4, y5, y6;
  88.  
  89. if (this.x1 <= this.x2 && this.x1 <= this.x3) {
  90. if (this.x2 <= this.x3) {
  91. x1 = this.x1; y1 = this.y1;
  92. x2 = this.x2; y2 = this.y2;
  93. x3 = this.x3; y3 = this.y3;
  94. }
  95. else {
  96. x1 = this.x1; y1 = this.y1;
  97. x2 = this.x3; y2 = this.y3;
  98. x3 = this.x2; y3 = this.y2;
  99. }
  100. }
  101. else if (this.x2 <= this.x1 && this.x2 <= this.x3){
  102. if (this.x1 <= this.x3) {
  103. x1 = this.x2; y1 = this.y2;
  104. x2 = this.x1; y2 = this.y1;
  105. x3 = this.x3; y3 = this.y3;
  106. }
  107. else {
  108. x1 = this.x2; y1 = this.y2;
  109. x2 = this.x3; y2 = this.y3;
  110. x3 = this.x1; y3 = this.y1;
  111. }
  112. }
  113. else {
  114. if (this.x1 <= this.x2) {
  115. x1 = this.x3; y1 = this.y3;
  116. x2 = this.x1; y2 = this.y1;
  117. x3 = this.x2; y3 = this.y2;
  118. }
  119. else {
  120. x1 = this.x3; y1 = this.y3;
  121. x2 = this.x2; y2 = this.y2;
  122. x3 = this.x1; y3 = this.y1;
  123. }
  124. }
  125.  
  126. double r1 = genRand.random(), r2 = genRand.random();
  127.  
  128. if (x1 == x2 && x2 == x3) {
  129. u = x1;
  130. if (y1 <= y2 && y1 <= y3) {
  131. v1 = y1;
  132. v2 = (y3 > y2) ? y2 : y3;
  133. }
  134. else if (y2 <= y1 && y2 <= y3) {
  135. v1 = y2;
  136. v2 = (y3 > y1) ? y1 : y3;
  137. }
  138. else {
  139. v1 = y3;
  140. v2 = (y2 > y1) ? y1 : y2;
  141. }
  142. v = v1 + r1 * (v2 - v1);
  143. }
  144. else if (x1 == x2) {
  145. x4 = (x1 + x3) / 2; y4 = (y1 + y3) / 2;
  146. x5 = x3 + x2 - x4; y5 = y3 + y2 - y4;
  147. x6 = x1 + x2 - x4; y6 = y1 + y2 - y4;
  148.  
  149. x = x3 + r1 * (x4 - x3); y = y3 + r1 * (y4 - y3);
  150. x0 = x5 + r1 * (x2 - x5); y0 = y5 + r1 * (y2 - y5);
  151. u = x + r2 * (x0 - x); v = y + r2 * (y0 - y);
  152. w = y3 + (y2 - y3) / (x2 - x3) * (u - x3);
  153.  
  154. if (y2 > y3 + (y3 - y1) / (x3 - x1) * (x2 - x3)) {
  155. if (v > w) {
  156. x = x4 + r1 * (x1 - x4); y = y4 + r1 * (y1 - y4);
  157. x0 = x2 + r1 * (x6 - x2); y0 = y2 + r1 * (y6 - y2);
  158. u = x0 + r2 * (x - x0); v = y0 + r2 * (y - y0);
  159. }
  160. }
  161. else {
  162. if (v < w) {
  163. x = x4 + r1 * (x1 - x4); y = y4 + r1 * (y1 - y4);
  164. x0 = x2 + r1 * (x6 - x2); y0 = y2 + r1 * (y6 - y2);
  165. u = x0 + r2 * (x - x0); v = y0 + r2 * (y - y0);
  166. }
  167. }
  168. }
  169. else {
  170. x4 = (x1 + x3) / 2; y4 = (y1 + y3) / 2;
  171. x5 = x1 + x2 - x4; y5 = y1 + y2 - y4;
  172. x6 = x3 + x2 - x4; y6 = y3 + y2 - y4;
  173.  
  174. x = x1 + r1 * (x4 - x1); y = y1 + r1 * (y4 - y1);
  175. x0 = x5 + r1 * (x2 - x5); y0 = y5 + r1 * (y2 - y5);
  176. u = x + r2 * (x0 - x); v = y + r2 * (y0 - y);
  177. w = y1 + (y2 - y1) / (x2 - x1) * (u - x1);
  178.  
  179. if (y2 > y1 + (y3 - y1) / (x3 - x1) * (x2 - x1)) {
  180. if (v > w) {
  181. x = x4 + r1 * (x3 - x4); y = y4 + r1 * (y3 - y4);
  182. x0 = x2 + r1 * (x6 - x2); y0 = y2 + r1 * (y6 - y2);
  183. u = x0 + r2 * (x - x0); v = y0 + r2 * (y - y0);
  184. }
  185. }
  186. else {
  187. if (v < w) {
  188. x = x4 + r1 * (x3 - x4); y = y4 + r1 * (y3 - y4);
  189. x0 = x2 + r1 * (x6 - x2); y0 = y2 + r1 * (y6 - y2);
  190. u = x0 + r2 * (x - x0); v = y0 + r2 * (y - y0);
  191. }
  192. }
  193. }
  194.  
  195. if (x1 == x2 && y1 == y2) {
  196. u = x1 + r1 * (x3 - x1); v = y1 + r1 * (y3 - y1);
  197. }
  198. if (x1 == x3 && y1 == y3) {
  199. u = x1 + r1 * (x2 - x1); v = y1 + r1 * (y2 - y1);
  200. }
  201. if (x2 == x3 && y2 == y3) {
  202. u = x1 + r1 * (x2 - x1); v = y1 + r1 * (y2 - y1);
  203. }
  204.  
  205. p.x = u;
  206. p.y = v;
  207. p.z = 0;
  208. }
  209. }
  210.  
  211. private triangle orig, t1, t2;
  212. private XYZPoint p;
  213. private double alfa;
  214. AbstractRandomGenerator genRand;
  215.  
  216. private void fiveFoldInit(int t, triangle orig) {
  217. switch (t) {
  218. case 1:
  219. orig.type = 1; orig.col = col1;
  220. orig.x1 = 0.0; orig.y1 = 0.0;
  221. orig.x2 = cos(M_2PI/5); orig.y2 = sin(M_2PI/5);
  222. orig.x3 = 2 * orig.x2; orig.y3 = 0.0;
  223. break;
  224. case 2:
  225. orig.type = 2; orig.col = col2;
  226. orig.x1 = 0.0; orig.y1 = 0.0;
  227. orig.x2 = cos(M_PI/5); orig.y2 = sin(M_PI/5);
  228. orig.x3 = 2 * orig.x2; orig.y3 = 0.0;
  229. break;
  230. }
  231.  
  232. alfa = 2*cos(M_2PI/5);
  233. }
  234.  
  235. private void fiveFoldDevis(triangle in, triangle out) {
  236. // http://tilings.math.uni-bielefeld.de/substitution/penrose-triangle-without-rotations/
  237. // (original FiveFold tiling)
  238. double x4, y4, x5, y5;
  239. double w;
  240.  
  241. switch (in.type) {
  242. case 1:
  243. x4 = in.x2 + alfa * (in.x3 - in.x2); y4 = in.y2 + alfa * (in.y3 - in.y2);
  244.  
  245. w = genRand.random();
  246.  
  247. if (w < alfa*alfa) {
  248. out.type = 1; out.col = col1;
  249. out.x1 = in.x3; out.y1 = in.y3;
  250. out.x2 = in.x1; out.y2 = in.y1;
  251. out.x3 = x4; out.y3 = y4;
  252. }
  253. else {
  254. out.type = 2; out.col = col2;
  255. out.x1 = in.x2; out.y1 = in.y2;
  256. out.x2 = x4; out.y2 = y4;
  257. out.x3 = in.x1; out.y3 = in.y1;
  258. }
  259. break;
  260. case 2:
  261. x4 = in.x3 + alfa * (in.x1 - in.x3); y4 = in.y3 + alfa * (in.y1 - in.y3);
  262. x5 = in.x3 + alfa * (in.x2 - in.x3); y5 = in.y3 + alfa * (in.y2 - in.y3);
  263.  
  264. w = genRand.random();
  265.  
  266. if (w < alfa*alfa) {
  267. out.type = 2; out.col = col2;
  268. out.x1 = in.x2; out.y1 = in.y2;
  269. out.x2 = x4; out.y2 = y4;
  270. out.x3 = in.x1; out.y3 = in.y1;
  271. }
  272. else if (w < 2*alfa*alfa) {
  273. out.type = 2; out.col = col2;
  274. out.x1 = in.x3; out.y1 = in.y3;
  275. out.x2 = x5; out.y2 = y5;
  276. out.x3 = x4; out.y3 = y4;
  277. }
  278. else {
  279. out.type = 1; out.col = col1;
  280. out.x1 = in.x2; out.y1 = in.y2;
  281. out.x2 = x4; out.y2 = y4;
  282. out.x3 = x5; out.y3 = y5;
  283. }
  284. break;
  285. }
  286. }
  287.  
  288. private void trihexInit(int t, triangle orig) {
  289. switch (t) {
  290. case 1:
  291. orig.type = 1; orig.col = col1;
  292. orig.x1 = 0.0; orig.y1 = 0.0;
  293. orig.x2 = cos(M_PI/3); orig.y2 = 0.0;
  294. orig.x3 = 0.0; orig.y3 = sin(M_PI/3);
  295. break;
  296. case 2:
  297. orig.type = 2; orig.col = col2;
  298. orig.x1 = 0.0; orig.y1 = 0.0;
  299. orig.x2 = cos(M_PI/3); orig.y2 = 0.0;
  300. orig.x3 = 0.0; orig.y3 = sin(M_PI/3);
  301. break;
  302. }
  303. }
  304.  
  305. private void trihexDevis(triangle in, triangle out) {
  306. // http://tilings.math.uni-bielefeld.de/substitution/trihex/
  307. double x4, y4, x5, y5, x6, y6;
  308. double w;
  309.  
  310. x4 = (in.x1 + in.x3) / 2; y4 = (in.y1 + in.y3) / 2;
  311. x5 = (in.x2 + in.x3) / 2; y5 = (in.y2 + in.y3) / 2;
  312. x6 = (in.x1 + x5) / 2; y6 = (in.y1 + y5) / 2;
  313.  
  314. w = genRand.random();
  315. if (w < 0.25) {
  316. out.type = in.type; out.col = in.type == 1 ? col1 : col2;
  317. out.x1 = x4; out.y1 = y4;
  318. out.x2 = x5; out.y2 = y5;
  319. out.x3 = in.x3; out.y3 = in.y3;
  320. }
  321. else if (w < 0.5) {
  322. out.type = 3 - in.type; out.col = in.type == 1 ? col2 : col1;
  323. out.x1 = x4; out.y1 = y4;
  324. out.x2 = x5; out.y2 = y5;
  325. out.x3 = in.x1; out.y3 = in.y1;
  326. }
  327. else if (w < 0.75) {
  328. out.type = 3 - in.type; out.col = in.type == 1 ? col2 : col1;
  329. out.x1 = x6; out.y1 = y6;
  330. out.x2 = x5; out.y2 = y5;
  331. out.x3 = in.x2; out.y3 = in.y2;
  332. }
  333. else {
  334. out.type = in.type; out.col = in.type == 1 ? col1 : col2;
  335. out.x1 = x6; out.y1 = y6;
  336. out.x2 = in.x1; out.y2 = in.y1;
  337. out.x3 = in.x2; out.y3 = in.y2;
  338. }
  339.  
  340. }
  341.  
  342. private void equiThirdsInit(int t, triangle orig) {
  343. switch (t) {
  344. case 1:
  345. orig.type = 1; orig.col = col1;
  346. orig.x1 = 0.0; orig.y1 = 0.0;
  347. orig.x2 = cos(M_PI/3); orig.y2 = sin(M_PI/3);
  348. orig.x3 = 2 * orig.x2; orig.y3 = 0.0;
  349. break;
  350. case 2:
  351. orig.type = 2; orig.col = col2;
  352. orig.x1 = 0.0; orig.y1 = 0.0;
  353. orig.x2 = cos(M_PI/6); orig.y2 = sin(M_PI/6);
  354. orig.x3 = 2 * orig.x2; orig.y3 = 0.0;
  355. break;
  356. }
  357.  
  358. alfa = 1.0 / 3.0;
  359. }
  360.  
  361. private void equiThirdsDevis(triangle in, triangle out) {
  362. // http://tilings.math.uni-bielefeld.de/substitution/equithirds/
  363. double x4, y4, x5, y5;
  364. double w;
  365.  
  366. switch (in.type) {
  367. case 1:
  368. x4 = in.x1 + 0.5 * (in.x3 - in.x1); y4 = in.y1 + 0.5 * (in.y3 - in.y1);
  369. x5 = x4 + alfa * (in.x2 - x4); y5 = y4 + alfa * (in.y2 - y4);
  370.  
  371. w = genRand.random();
  372.  
  373. if (w < alfa) {
  374. out.type = 2; out.col = col2;
  375. out.x1 = in.x2; out.y1 = in.y2;
  376. out.x2 = x5; out.y2 = y5;
  377. out.x3 = in.x1; out.y3 = in.y1;
  378. }
  379. else if (w < 2 * alfa) {
  380. out.type = 2; out.col = col2;
  381. out.x1 = in.x3; out.y1 = in.y3;
  382. out.x2 = x5; out.y2 = y5;
  383. out.x3 = in.x2; out.y3 = in.y2;
  384. }
  385. else {
  386. out.type = 2; out.col = col2;
  387. out.x1 = in.x1; out.y1 = in.y1;
  388. out.x2 = x5; out.y2 = y5;
  389. out.x3 = in.x3; out.y3 = in.y3;
  390. }
  391. break;
  392. case 2:
  393. x4 = in.x1 + alfa * (in.x3 - in.x1); y4 = in.y1 + alfa * (in.y3 - in.y1);
  394. x5 = in.x3 + alfa * (in.x1 - in.x3); y5 = in.y3 + alfa * (in.y1 - in.y3);
  395.  
  396. w = genRand.random();
  397.  
  398. if (w < alfa) {
  399. out.type = 2; out.col = col2;
  400. out.x1 = in.x2; out.y1 = in.y2;
  401. out.x2 = x4; out.y2 = y4;
  402. out.x3 = in.x1; out.y3 = in.y1;
  403. }
  404. else if (w < 2*alfa) {
  405. out.type = 2; out.col = col2;
  406. out.x1 = in.x3; out.y1 = in.y3;
  407. out.x2 = x5; out.y2 = y5;
  408. out.x3 = in.x2; out.y3 = in.y2;
  409. }
  410. else {
  411. out.type = 1; out.col = col1;
  412. out.x1 = x4; out.y1 = y4;
  413. out.x2 = in.x2; out.y2 = in.y2;
  414. out.x3 = x5; out.y3 = y5;
  415. }
  416. break;
  417. }
  418. }
  419.  
  420. private void ortInit(int t, triangle orig) {
  421. switch (t) {
  422. case 1:
  423. orig.type = 1; orig.col = col1;
  424. orig.x1 = 0.0; orig.y1 = 0.0;
  425. orig.x2 = cos(M_2PI/5); orig.y2 = sin(M_2PI/5);
  426. orig.x3 = 2 * orig.x2; orig.y3 = 0.0;
  427. break;
  428. case 2:
  429. orig.type = 2; orig.col = col2;
  430. orig.x1 = 0.0; orig.y1 = 0.0;
  431. orig.x2 = cos(M_2PI/5); orig.y2 = sin(M_2PI/5);
  432. orig.x3 = 2 * orig.x2; orig.y3 = 0.0;
  433. break;
  434. }
  435.  
  436. alfa = 2*cos(M_2PI/5);
  437. }
  438.  
  439. private void ortDevis(triangle in, triangle out) {
  440. // http://tilings.math.uni-bielefeld.de/substitution/overlapping-robinson-triangle-1/
  441. double x4, y4, x5, y5, x6, y6;
  442. double w;
  443.  
  444. x4 = in.x2 + alfa * (in.x1 - in.x2); y4 = in.y2 + alfa * (in.y1 - in.y2);
  445. x5 = in.x1 + alfa * (in.x2 - in.x1); y5 = in.y1 + alfa * (in.y2 - in.y1);
  446. x6 = in.x2 + alfa * (in.x3 - in.x2); y6 = in.y2 + alfa * (in.y3 - in.y2);
  447.  
  448. w = genRand.random();
  449. if (w < 0.3) {
  450. out.type = 2; out.col = col2;
  451. out.x1 = x4; out.y1 = y4;
  452. out.x2 = in.x2; out.y2 = in.y2;
  453. out.x3 = x6; out.y3 = y6;
  454. }
  455. else if (w < 0.63) {
  456. out.type = 3 - in.type; out.col = in.type == 1 ? col2 : col1;
  457. out.x1 = x6; out.y1 = y6;
  458. out.x2 = in.x1; out.y2 = in.y1;
  459. out.x3 = x5; out.y3 = y5;
  460. }
  461. else {
  462. out.type = 1; out.col = col1;
  463. out.x1 = in.x3; out.y1 = in.y3;
  464. out.x2 = in.x1; out.y2 = in.y1;
  465. out.x3 = x6; out.y3 = y6;
  466. }
  467.  
  468. }
  469.  
  470. private void pinwheelInit(int t, triangle orig) {
  471. switch (t) {
  472. case 1:
  473. orig.type = 1; orig.col = col1;
  474. orig.x1 = 0.0; orig.y1 = 0.0;
  475. orig.x2 = 0.0; orig.y2 = 1.0;
  476. orig.x3 = 2.0; orig.y3 = 0.0;
  477. break;
  478. case 2:
  479. orig.type = 2; orig.col = col2;
  480. orig.x1 = 0.0; orig.y1 = 0.0;
  481. orig.x2 = 0.0; orig.y2 = 2.0;
  482. orig.x3 = 1.0; orig.y3 = 0.0;
  483. break;
  484. }
  485. }
  486.  
  487. private void pinwheelDevis(triangle in, triangle out) {
  488. // http://tilings.math.uni-bielefeld.de/substitution/pinwheel/ and https://en.wikipedia.org/wiki/Pinwheel_tiling
  489. double x4, y4, x5, y5, x6, y6, x7, y7;
  490. int w;
  491.  
  492. switch(in.type) {
  493. case 1:
  494. x4 = in.x2 + 0.2 * (in.x3 - in.x2); y4 = in.y2 + 0.2 * (in.y3 - in.y2);
  495. x5 = in.x2 + 0.6 * (in.x3 - in.x2); y5 = in.y2 + 0.6 * (in.y3 - in.y2);
  496. x6 = in.x1 + 0.5 * (in.x3 - in.x1); y6 = in.y1 + 0.5 * (in.y3 - in.y1);
  497. x7 = in.x1 + 0.5 * (x4 - in.x1); y7 = in.y1 + 0.5 * (y4 - in.y1);
  498.  
  499. w = (int) (genRand.random() * 5);
  500. switch (w) {
  501. case 0:
  502. out.type = 2; out.col = col2;
  503. out.x1 = x4; out.y1 = y4;
  504. out.x2 = in.x1; out.y2 = in.y1;
  505. out.x3 = in.x2; out.y3 = in.y2;
  506. break;
  507. case 1:
  508. out.type = 2; out.col = col2;
  509. out.x1 = x7; out.y1 = y7;
  510. out.x2 = x6; out.y2 = y6;
  511. out.x3 = in.x1; out.y3 = in.y1;
  512. break;
  513. case 2:
  514. out.type = 1; out.col = col1;
  515. out.x1 = x7; out.y1 = y7;
  516. out.x2 = x4; out.y2 = y4;
  517. out.x3 = x6; out.y3 = y6;
  518. break;
  519. case 3:
  520. out.type = 1; out.col = col1;
  521. out.x1 = x5; out.y1 = y5;
  522. out.x2 = x6; out.y2 = y6;
  523. out.x3 = x4; out.y3 = y4;
  524. break;
  525. case 4:
  526. out.type = 2; out.col = col2;
  527. out.x1 = x5; out.y1 = y5;
  528. out.x2 = in.x3; out.y2 = in.y3;
  529. out.x3 = x6; out.y3 = y6;
  530. break;
  531. }
  532. break;
  533. case 2:
  534. x4 = in.x3 + 0.2 * (in.x2 - in.x3); y4 = in.y3 + 0.2 * (in.y2 - in.y3);
  535. x5 = in.x3 + 0.6 * (in.x2 - in.x3); y5 = in.y3 + 0.6 * (in.y2 - in.y3);
  536. x6 = in.x1 + 0.5 * (in.x2 - in.x1); y6 = in.y1 + 0.5 * (in.y2 - in.y1);
  537. x7 = in.x1 + 0.5 * (x4 - in.x1); y7 = in.y1 + 0.5 * (y4 - in.y1);
  538.  
  539. w = (int) (genRand.random() * 5);
  540. switch (w) {
  541. case 0:
  542. out.type = 1; out.col = col1;
  543. out.x1 = x4; out.y1 = y4;
  544. out.x2 = in.x3; out.y2 = in.y3;
  545. out.x3 = in.x1; out.y3 = in.y1;
  546. break;
  547. case 1:
  548. out.type = 1; out.col = col1;
  549. out.x1 = x7; out.y1 = y7;
  550. out.x2 = in.x1; out.y2 = in.y1;
  551. out.x3 = x6; out.y3 = y6;
  552. break;
  553. case 2:
  554. out.type = 2; out.col = col2;
  555. out.x1 = x7; out.y1 = y7;
  556. out.x2 = x6; out.y2 = y6;
  557. out.x3 = x4; out.y3 = y4;
  558. break;
  559. case 3:
  560. out.type = 2; out.col = col2;
  561. out.x1 = x5; out.y1 = y5;
  562. out.x2 = x4; out.y2 = y4;
  563. out.x3 = x6; out.y3 = y6;
  564. break;
  565. case 4:
  566. out.type = 1; out.col = col1;
  567. out.x1 = x5; out.y1 = y5;
  568. out.x2 = x6; out.y2 = y6;
  569. out.x3 = in.x2; out.y3 = in.y2;
  570. break;
  571. }
  572. break;
  573. }
  574. }
  575.  
  576. private void goldInit(int t, triangle orig) {
  577. switch (t) {
  578. case 1:
  579. orig.type = 1; orig.col = col1;
  580. orig.x1 = 0.0; orig.y1 = 0.0;
  581. orig.x2 = M_1_PHI; orig.y2 = sqrt(M_1_PHI);
  582. orig.x3 = orig.x2; orig.y3 = 0.0;
  583. break;
  584. case 2:
  585. orig.type = 2; orig.col = col2;
  586. orig.x1 = 0.0; orig.y1 = 0.0;
  587. orig.x2 = 0.0; orig.y2 = sqrt(M_1_PHI);
  588. orig.x3 = 1.0; orig.y3 = 0.0;
  589. break;
  590. }
  591.  
  592. alfa = sqr(M_1_PHI);
  593. }
  594.  
  595. private void goldDevis(triangle in, triangle out) {
  596. // http://tilings.math.uni-bielefeld.de/substitution/golden-pinwheel/
  597. double x4, y4, x5, y5, x6, y6, x7, y7, x8, y8, x9, y9, x10, y10;
  598. double w;
  599.  
  600. switch(in.type) {
  601. case 1:
  602. x4 = in.x1 + alfa * (in.x2 - in.x1); y4 = in.y1 + alfa * (in.y2 - in.y1);
  603. x5 = in.x2 + alfa * (in.x1 - in.x2); y5 = in.y2 + alfa * (in.y1 - in.y2);
  604. x6 = in.x3 + alfa * (in.x2 - in.x3); y6 = in.y3 + alfa * (in.y2 - in.y3);
  605. x7 = in.x1 + alfa * (in.x3 - in.x1); y7 = in.y1 + alfa * (in.y3 - in.y1);
  606.  
  607. w = genRand.random();
  608. if (w < 0.146) {
  609. out.type = 1; out.col = col1;
  610. out.x1 = in.x1; out.y1 = in.y1;
  611. out.x2 = x4; out.y2 = y4;
  612. out.x3 = x7; out.y3 = y7;
  613. }
  614. else if (w < 0.382) {
  615. out.type = 2; out.col = col2;
  616. out.x1 = x4; out.y1 = y4;
  617. out.x2 = x7; out.y2 = y7;
  618. out.x3 = x6; out.y3 = y6;
  619. }
  620. else if (w < 0.618) {
  621. out.type = 2; out.col = col2;
  622. out.x1 = in.x3; out.y1 = in.y3;
  623. out.x2 = x6; out.y2 = y6;
  624. out.x3 = x7; out.y3 = y7;
  625. }
  626. else if (w < 0.764) {
  627. out.type = 1; out.col = col1;
  628. out.x1 = x4; out.y1 = y4;
  629. out.x2 = x6; out.y2 = y6;
  630. out.x3 = x5; out.y3 = y5;
  631. }
  632. else {
  633. out.type = 2; out.col = col2;
  634. out.x1 = x5; out.y1 = y5;
  635. out.x2 = x6; out.y2 = y6;
  636. out.x3 = in.x2; out.y3 = in.y2;
  637. }
  638. break;
  639. case 2:
  640. x4 = in.x2 + alfa * (in.x1 - in.x2); y4 = in.y2 + alfa * (in.y1 - in.y2);
  641. x5 = in.x2 + alfa * (in.x3 - in.x2); y5 = in.y2 + alfa * (in.y3 - in.y2);
  642. x6 = in.x3 + alfa * (in.x2 - in.x3); y6 = in.y3 + alfa * (in.y2 - in.y3);
  643. x7 = in.x1 + alfa * (in.x3 - in.x1); y7 = in.y1 + alfa * (in.y3 - in.y1);
  644. x8 = in.x3 + alfa * (in.x1 - in.x3); y8 = in.y3 + alfa * (in.y1 - in.y3);
  645. x9 = x4 + alfa * (x7 - x4); y9 = y4 + alfa * (y7 - y4);
  646. x10 = x7 + alfa * (x4 - x7); y10 = y7 + alfa * (y4 - y7);
  647.  
  648. w = genRand.random();
  649. if (w < 0.146) {
  650. out.type = 2; out.col = col2;
  651. out.x1 = x4; out.y1 = y4;
  652. out.x2 = in.x2; out.y2 = in.y2;
  653. out.x3 = x5; out.y3 = y5;
  654. }
  655. else if (w < 0.236) {
  656. out.type = 1; out.col = col1;
  657. out.x1 = x4; out.y1 = y4;
  658. out.x2 = x5; out.y2 = y5;
  659. out.x3 = x9; out.y3 = y9;
  660. }
  661. else if (w < 0.382) {
  662. out.type = 2; out.col = col2;
  663. out.x1 = x10; out.y1 = y10;
  664. out.x2 = in.x1; out.y2 = in.y1;
  665. out.x3 = x4; out.y3 = y4;
  666. }
  667. else if (w < 0.472) {
  668. out.type = 1; out.col = col1;
  669. out.x1 = x7; out.y1 = y7;
  670. out.x2 = in.x1; out.y2 = in.y1;
  671. out.x3 = x10; out.y3 = y10;
  672. }
  673. else if (w < 0.618) {
  674. out.type = 2; out.col = col2;
  675. out.x1 = x9; out.y1 = y9;
  676. out.x2 = x5; out.y2 = y5;
  677. out.x3 = x7; out.y3 = y7;
  678. }
  679. else if (w < 0.764) {
  680. out.type = 2; out.col = col2;
  681. out.x1 = x6; out.y1 = y6;
  682. out.x2 = x5; out.y2 = y5;
  683. out.x3 = x7; out.y3 = y7;
  684. }
  685. else if (w < 0.854) {
  686. out.type = 1; out.col = col1;
  687. out.x1 = x7; out.y1 = y7;
  688. out.x2 = x6; out.y2 = y6;
  689. out.x3 = x8; out.y3 = y8;
  690. }
  691. else {
  692. out.type = 2; out.col = col2;
  693. out.x1 = x8; out.y1 = y8;
  694. out.x2 = x6; out.y2 = y6;
  695. out.x3 = in.x3; out.y3 = in.y3;
  696. }
  697. break;
  698. }
  699. }
  700.  
  701. private void devis(triangle t1, triangle t2) {
  702. switch (tiling) {
  703. case 1:
  704. fiveFoldDevis(t1,t2);
  705. break;
  706. case 2:
  707. trihexDevis(t1,t2);
  708. break;
  709. case 3:
  710. equiThirdsDevis(t1,t2);
  711. break;
  712. case 4:
  713. ortDevis(t1,t2);
  714. break;
  715. case 5:
  716. pinwheelDevis(t1,t2);
  717. break;
  718. case 6:
  719. goldDevis(t1,t2);
  720. break;
  721. }
  722. }
  723.  
  724. @Override
  725. public void init(FlameTransformationContext pContext, Layer pLayer, XForm pXForm, double pAmount) {
  726. orig = new triangle();
  727.  
  728. switch (tiling) {
  729. case 1:
  730. fiveFoldInit(t, orig);
  731. break;
  732. case 2:
  733. trihexInit(t, orig);
  734. break;
  735. case 3:
  736. equiThirdsInit(t, orig);
  737. break;
  738. case 4:
  739. ortInit(t, orig);
  740. break;
  741. case 5:
  742. pinwheelInit(t, orig);
  743. break;
  744. case 6:
  745. goldInit(t, orig);
  746. break;
  747. }
  748.  
  749. genRand = pContext.getRandGen();
  750. t1 = new triangle();
  751. t2 = new triangle();
  752. p = new XYZPoint();
  753. }
  754.  
  755. @Override
  756. public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
  757. /* extension of FiveFold by eralex61, https://eralex61.deviantart.com/art/Five-fold-example-of-finite-recurent-system-in-Apo-705813367 */
  758.  
  759. t1.assign(orig); t1.col = 0.25;
  760. t2.assign(orig); t2.col = 0.0;
  761.  
  762. int n = itt;
  763. int k = 1;
  764.  
  765. while (n > 0) {
  766. devis(t1, t2);
  767. t1.assign(t2);
  768.  
  769. if (on < 0.5) {
  770. if ((k == itt) && (t1.type != eq)) n = n + depth;
  771. }
  772. else {
  773. if ((k >= itt) && (k < itt + depth) && (t1.type != eq)) n = n + 1;
  774. }
  775. n = n - 1;
  776. k = k + 1;
  777. }
  778.  
  779. int m = 0;
  780. switch (t1.type) {
  781. case 1:
  782. n = itt1;
  783. k = 1;
  784. while (n > 0) {
  785. devis(t1, t2);
  786. t1.assign(t2);
  787. m = 2 * m + t2.type - 1;
  788. if (on1 < 0.5) {
  789. if ((k == itt1) && (t1.type != eq1)) n = n + depth1;
  790. }
  791. else {
  792. if ((k >= itt1) && (k < itt1 + depth1) && (t1.type != eq1)) n = n + 1;
  793. }
  794. n = n - 1;
  795. k = k + 1;
  796. }
  797. t1.col = discretNoise(m+43);
  798. break;
  799. case 2:
  800. n = itt2;
  801. k = 1;
  802. while (n > 0) {
  803. devis(t1, t2);
  804. t1.assign(t2);
  805. m = 2 * m + t2.type - 1;
  806. if (on2 < 0.5) {
  807. if ((k == itt2) && (t1.type != eq2)) n = n + depth2;
  808. }
  809. else {
  810. if ((k >= itt2) && (k < itt2 + depth2) && (t1.type != eq2)) n = n + 1;
  811. }
  812. n = n - 1;
  813. k = k + 1;
  814. }
  815. t1.col = discretNoise(m+31);
  816. break;
  817. }
  818.  
  819. t2.blur(p);
  820.  
  821. pVarTP.x += pAmount * p.x;
  822. pVarTP.y += pAmount * p.y;
  823. pVarTP.z += pAmount * p.z;
  824. pVarTP.color = fmod(t1.col + t2.col, 1.0);
  825.  
  826. }
  827.  
  828. @Override
  829. public String[] getParameterNames() {
  830. return paramNames;
  831. }
  832.  
  833. @Override
  834. public Object[] getParameterValues() {
  835. return new Object[] { tiling, t, col1, col2, on, itt, eq, depth, on1, itt1, eq1, depth1, on2, itt2, eq2, depth2 };
  836. }
  837.  
  838. @Override
  839. public String[] getParameterAlternativeNames() {
  840. return new String[] { "FiveFold_Tiling", "FiveFold_T", "FiveFold_Col1", "FiveFold_Col2", "FiveFold_On", "FiveFold_Itt", "FiveFold_Eq", "FiveFold_Depth", "FiveFold_On1", "FiveFold_Itt1", "FiveFold_Eq1", "FiveFold_Depth1", "FiveFold_On2", "FiveFold_Itt2", "FiveFold_Eq2", "FiveFold_Depth2" };
  841. }
  842.  
  843. @Override
  844. public void setParameter(String pName, double pValue) {
  845. if (PARAM_TILING.equalsIgnoreCase(pName))
  846. tiling = Tools.FTOI(pValue);
  847. else if (PARAM_T.equalsIgnoreCase(pName))
  848. t = Tools.FTOI(pValue);
  849. else if (PARAM_COL1.equalsIgnoreCase(pName))
  850. col1 = pValue;
  851. else if (PARAM_COL2.equalsIgnoreCase(pName))
  852. col2 = pValue;
  853. else if (PARAM_ON.equalsIgnoreCase(pName))
  854. on = pValue;
  855. else if (PARAM_ITT.equalsIgnoreCase(pName))
  856. itt = Tools.FTOI(pValue);
  857. else if (PARAM_EQ.equalsIgnoreCase(pName))
  858. eq = Tools.FTOI(pValue);
  859. else if (PARAM_DEPTH.equalsIgnoreCase(pName))
  860. depth = Tools.FTOI(pValue);
  861. else if (PARAM_ON1.equalsIgnoreCase(pName))
  862. on1 = pValue;
  863. else if (PARAM_ITT1.equalsIgnoreCase(pName))
  864. itt1 = Tools.FTOI(pValue);
  865. else if (PARAM_EQ1.equalsIgnoreCase(pName))
  866. eq1 = Tools.FTOI(pValue);
  867. else if (PARAM_DEPTH1.equalsIgnoreCase(pName))
  868. depth1 = Tools.FTOI(pValue);
  869. else if (PARAM_ON2.equalsIgnoreCase(pName))
  870. on2 = pValue;
  871. else if (PARAM_ITT2.equalsIgnoreCase(pName))
  872. itt2 = Tools.FTOI(pValue);
  873. else if (PARAM_EQ2.equalsIgnoreCase(pName))
  874. eq2 = Tools.FTOI(pValue);
  875. else if (PARAM_DEPTH2.equalsIgnoreCase(pName))
  876. depth2 = Tools.FTOI(pValue);
  877. else
  878. throw new IllegalArgumentException(pName);
  879. }
  880.  
  881. @Override
  882. public String getName() {
  883. return "dc_triTile";
  884. }
  885.  
  886. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement