762 lines
26 KiB
JavaScript
762 lines
26 KiB
JavaScript
var footstring2 = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
|
|
|
<svg
|
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
xmlns:cc="http://creativecommons.org/ns#"
|
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
xmlns:svg="http://www.w3.org/2000/svg"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
|
width="210mm"
|
|
height="297mm"
|
|
viewBox="0 0 210 297"
|
|
version="1.1"
|
|
id="svg7002"
|
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
|
sodipodi:docname="chairleg2.svg">
|
|
<defs
|
|
id="defs6996" />
|
|
<sodipodi:namedview
|
|
id="base"
|
|
pagecolor="#ffffff"
|
|
bordercolor="#666666"
|
|
borderopacity="1.0"
|
|
inkscape:pageopacity="0.0"
|
|
inkscape:pageshadow="2"
|
|
inkscape:zoom="0.35"
|
|
inkscape:cx="-115.71429"
|
|
inkscape:cy="560"
|
|
inkscape:document-units="mm"
|
|
inkscape:current-layer="layer1"
|
|
showgrid="false"
|
|
inkscape:window-width="1920"
|
|
inkscape:window-height="1050"
|
|
inkscape:window-x="0"
|
|
inkscape:window-y="0"
|
|
inkscape:window-maximized="1" />
|
|
<metadata
|
|
id="metadata6999">
|
|
<rdf:RDF>
|
|
<cc:Work
|
|
rdf:about="">
|
|
<dc:format>image/svg+xml</dc:format>
|
|
<dc:type
|
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
|
<dc:title></dc:title>
|
|
</cc:Work>
|
|
</rdf:RDF>
|
|
</metadata>
|
|
<g
|
|
inkscape:label="Layer 1"
|
|
inkscape:groupmode="layer"
|
|
id="layer1">
|
|
<g
|
|
id="layer1-2-0-3"
|
|
inkscape:label="Layer 1"
|
|
transform="translate(538.86519,131.45315)"
|
|
style="fill:#c83737">
|
|
<path
|
|
sodipodi:nodetypes="ccsccccccccccccccccccccccccccccccccccccccsccccccccccccsccsccccc"
|
|
inkscape:connector-curvature="0"
|
|
id="rect929-7-9-6"
|
|
transform="scale(0.26458333)"
|
|
d="m -2285.8789,560.54102 h 1366.09571 c 0,0 256.17054,-354.30681 241.07225,-499.82227 -0.4423,-4.262873 -2.67383,-12.576172 -2.67383,-12.576172 l -3.02343,-14.230469 -3.41602,-16.070312 c -1.48093,-6.967208 -8.28274,-11.3852308 -15.25,-9.904297 l -196.66406,41.802734 c -6.96726,1.480933 -11.38523,8.282793 -9.9043,15.25 l 3.41602,16.070313 3.02539,14.232422 2.67187,12.576171 c 0.75886,3.57249 -1.52146,7.08391 -5.09375,7.84375 -3.57316,0.76008 -7.0859,-1.52053 -7.8457,-5.09375 l -269.87505,57.36328 c 0.7589,3.57248 -1.5214,7.08389 -5.0937,7.84375 -3.5732,0.76008 -7.0859,-1.52053 -7.8457,-5.09375 l -2.6719,-12.57617 -3.0254,-14.23047 -3.416,-16.07226 c -1.4809,-6.96721 -8.2828,-11.38327 -15.25,-9.90235 l -196.664,41.80274 c -6.9673,1.48093 -11.3853,8.28279 -9.9043,15.25 l 3.416,16.07031 3.0254,14.23047 2.6738,12.57617 12.3496,-2.62305 -12.3496,2.625 c 0.7588,3.57311 -1.5226,7.08482 -5.0957,7.84375 -3.5725,0.75889 -7.084,-1.52144 -7.8438,-5.09375 l -282.1875,59.98047 c -0.2099,0.0446 -0.411,-0.0266 -0.5586,-0.16016 -9.2045,3.59809 -19,5.44552 -28.8828,5.44727 -39.4214,-0.0388 -72.8399,-29.00516 -78.4765,-68.02148 l -107.1133,-265.115238 c -3.3865,1.367887 -7.2408,-0.26807 -8.6094,-3.654297 -1.3692,-3.387063 0.267,-7.242714 3.6543,-8.611328 l 11.9199,-4.816406 13.4903,-5.449219 15.2343,-6.154297 c 6.6042,-2.668271 9.7718,-10.134044 7.1036,-16.738281 l -75.3184,-186.417964 c -2.6683,-6.60421 -10.1321,-9.77374 -16.7363,-7.10547 l -15.2344,6.15429 -13.4883,5.45118 -11.9219,4.8164 c -3.387,1.3676 -7.2415,-0.26931 -8.6093,-3.65625 -1.3679,-3.38652 0.2681,-7.24075 3.6543,-8.60937 l -103.3555,-255.81446 v 0 c -3.3865,1.36782 -7.2407,-0.26812 -8.6093,-3.65429 -1.3692,-3.38706 0.267,-7.24272 3.6543,-8.61133 l 11.9218,-4.81641 13.4903,-5.44922 15.2324,-6.15429 c 6.6042,-2.66827 9.7738,-10.13413 7.1055,-16.73828 L -2159,-769.68359 c -2.6683,-6.60424 -10.1341,-9.77374 -16.7383,-7.10547 l -15.2324,6.15429 -13.4902,5.45118 -11.9063,4.81054 -0.016,0.006 c -93.0715,33.85033 -69.4957,1320.90807 -69.4957,1320.90807 z"
|
|
style="opacity:1;vector-effect:none;fill:#c83737;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
|
</g>
|
|
</g>
|
|
</svg>
|
|
`;
|
|
|
|
var footstring = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
|
|
|
<svg
|
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
xmlns:cc="http://creativecommons.org/ns#"
|
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
xmlns:svg="http://www.w3.org/2000/svg"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
|
width="26.457907mm"
|
|
height="22.513216mm"
|
|
viewBox="0 0 26.457907 22.513216"
|
|
version="1.1"
|
|
id="svg8"
|
|
inkscape:version="0.92.3 (2405546, 2018-03-11)"
|
|
sodipodi:docname="chair_foot.svg">
|
|
<defs
|
|
id="defs2" />
|
|
<sodipodi:namedview
|
|
id="base"
|
|
pagecolor="#ffffff"
|
|
bordercolor="#666666"
|
|
borderopacity="1.0"
|
|
inkscape:pageopacity="0.0"
|
|
inkscape:pageshadow="2"
|
|
inkscape:zoom="0.24748738"
|
|
inkscape:cx="1176.0282"
|
|
inkscape:cy="684.08403"
|
|
inkscape:document-units="mm"
|
|
inkscape:current-layer="layer1"
|
|
showgrid="false"
|
|
inkscape:snap-bbox="true"
|
|
inkscape:snap-bbox-edge-midpoints="true"
|
|
inkscape:snap-bbox-midpoints="true"
|
|
inkscape:bbox-nodes="true"
|
|
inkscape:window-width="2560"
|
|
inkscape:window-height="1377"
|
|
inkscape:window-x="-8"
|
|
inkscape:window-y="-8"
|
|
inkscape:window-maximized="1" />
|
|
<metadata
|
|
id="metadata5">
|
|
<rdf:RDF>
|
|
<cc:Work
|
|
rdf:about="">
|
|
<dc:format>image/svg+xml</dc:format>
|
|
<dc:type
|
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
|
<dc:title />
|
|
</cc:Work>
|
|
</rdf:RDF>
|
|
</metadata>
|
|
<g
|
|
inkscape:label="Layer 1"
|
|
inkscape:groupmode="layer"
|
|
id="layer1"
|
|
transform="translate(595.6009,-125.79659)">
|
|
<path
|
|
style="opacity:1;vector-effect:none;fill:#0000ff;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
|
d="m -594.50431,148.30981 h 19.17899 c 0,0 6.42898,-5.96024 6.17499,-8.40814 -0.007,-0.0717 -0.045,-0.21156 -0.045,-0.21156 l -0.0509,-0.23939 -0.0575,-0.27034 c -0.0249,-0.1172 -0.13933,-0.19152 -0.25654,-0.16661 l -3.30833,0.70322 c -0.11721,0.0249 -0.19153,0.13933 -0.16661,0.25653 l 0.0575,0.27034 0.0509,0.23943 0.0449,0.21155 c 0.0128,0.0601 -0.0256,0.11917 -0.0857,0.13195 -0.0601,0.0128 -0.1192,-0.0256 -0.13198,-0.0857 l -4.53991,0.96498 c 0.0128,0.0601 -0.0256,0.11916 -0.0857,0.13195 -0.0601,0.0128 -0.11921,-0.0256 -0.13199,-0.0857 l -0.0449,-0.21156 -0.0509,-0.23939 -0.0575,-0.27037 c -0.0249,-0.11721 -0.13934,-0.1915 -0.25654,-0.16658 l -3.30834,0.70321 c -0.1172,0.0249 -0.19152,0.13934 -0.16661,0.25654 l 0.0575,0.27034 0.0509,0.23939 0.045,0.21156 0.20775,-0.0441 -0.20775,0.0442 c 0.0128,0.0601 -0.0256,0.11919 -0.0857,0.13195 -0.0601,0.0128 -0.11917,-0.0256 -0.13195,-0.0857 l -4.74703,1.00901 c -0.004,7.5e-4 -0.007,-4.5e-4 -0.009,-0.003 -0.15484,0.0605 -0.31962,0.0916 -0.48588,0.0916 -0.66315,-6.5e-4 -1.22533,-0.48793 -1.32015,-1.14427 l -1.80189,-4.45984 c -0.057,0.023 -0.1218,-0.005 -0.14483,-0.0615 -0.023,-0.057 0.005,-0.12184 0.0615,-0.14487 l 0.20052,-0.081 0.22694,-0.0917 0.25627,-0.10353 c 0.1111,-0.0449 0.16438,-0.17047 0.1195,-0.28157 l -1.26703,-3.13597 c -0.0449,-0.1111 -0.17044,-0.16442 -0.28154,-0.11953 l -0.25628,0.10353 -0.2269,0.0917 -0.20055,0.081 c -0.057,0.023 -0.12182,-0.005 -0.14483,-0.0615 -0.023,-0.057 0.005,-0.1218 0.0615,-0.14483 l -1.73867,-4.30337 v 0 c -0.057,0.023 -0.12181,-0.005 -0.14483,-0.0615 -0.023,-0.057 0.004,-0.12184 0.0615,-0.14486 l 0.20055,-0.081 0.22693,-0.0917 0.25625,-0.10353 c 0.1111,-0.0449 0.16441,-0.17048 0.11953,-0.28158 l -1.26706,-3.13597 c -0.0449,-0.1111 -0.17048,-0.16441 -0.28158,-0.11953 l -0.25624,0.10353 -0.22694,0.0917 -0.20029,0.0809 -2.7e-4,1e-4 c -1.56567,0.56944 0.51315,22.22066 0.51315,22.22066 z"
|
|
id="rect929"
|
|
inkscape:connector-curvature="0"
|
|
sodipodi:nodetypes="ccsccccccccccccccccccccccccccccccccccccccsccccccccccccsccsccccc" />
|
|
</g>
|
|
</svg>
|
|
`;
|
|
|
|
var seatstring = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
|
|
|
<svg
|
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
xmlns:cc="http://creativecommons.org/ns#"
|
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
xmlns:svg="http://www.w3.org/2000/svg"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
|
width="210mm"
|
|
height="297mm"
|
|
viewBox="0 0 210 297"
|
|
version="1.1"
|
|
id="svg38141"
|
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
|
sodipodi:docname="chairseat.svg">
|
|
<defs
|
|
id="defs38135" />
|
|
<sodipodi:namedview
|
|
id="base"
|
|
pagecolor="#ffffff"
|
|
bordercolor="#666666"
|
|
borderopacity="1.0"
|
|
inkscape:pageopacity="0.0"
|
|
inkscape:pageshadow="2"
|
|
inkscape:zoom="0.35"
|
|
inkscape:cx="-115.71429"
|
|
inkscape:cy="560"
|
|
inkscape:document-units="mm"
|
|
inkscape:current-layer="layer1"
|
|
showgrid="false"
|
|
inkscape:window-width="1920"
|
|
inkscape:window-height="1050"
|
|
inkscape:window-x="0"
|
|
inkscape:window-y="0"
|
|
inkscape:window-maximized="1" />
|
|
<metadata
|
|
id="metadata38138">
|
|
<rdf:RDF>
|
|
<cc:Work
|
|
rdf:about="">
|
|
<dc:format>image/svg+xml</dc:format>
|
|
<dc:type
|
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
|
<dc:title></dc:title>
|
|
</cc:Work>
|
|
</rdf:RDF>
|
|
</metadata>
|
|
<g
|
|
inkscape:label="Layer 1"
|
|
inkscape:groupmode="layer"
|
|
id="layer1">
|
|
<path
|
|
style="opacity:1;vector-effect:none;fill:#a05a2c;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
|
d="m -95.394613,430.4764 c 40.10306,0 72.38889,-32.28531 72.38887,-72.38839 v -255.2237 c 0,-40.103049 -32.28581,-72.388329 -72.38887,-72.388329 H -350.61829 c -40.10307,0 -72.38787,32.28528 -72.38787,72.388329 v 255.2237 c 0,40.10308 32.2848,72.38839 72.38787,72.38839 z m -18.361127,-78.25005 a 1.7499995,1.7499997 0 0 1 -1.74977,-1.74974 h -14.00018 a 1.7499995,1.7499997 0 0 1 -1.74977,1.74974 1.7499995,1.7499997 0 0 1 -1.75027,-1.74974 1.7499995,1.7499997 0 0 1 0.0238,-0.2739 c -0.0148,-0.0418 -0.0238,-0.086 -0.0238,-0.13279 v -59.18711 c 0,-0.0456 0.009,-0.0884 0.0228,-0.12917 a 1.7499995,1.7499997 0 0 1 -0.0228,-0.27699 1.7499995,1.7499997 0 0 1 1.75027,-1.7503 1.7499995,1.7499997 0 0 1 1.74977,1.7503 h 14.00018 a 1.7499995,1.7499997 0 0 1 1.74977,-1.7503 1.7499995,1.7499997 0 0 1 1.75028,1.7503 1.7499995,1.7499997 0 0 1 -0.0238,0.27387 c 0.0138,0.0417 0.0238,0.0856 0.0238,0.13229 v 59.18711 c 0,0.0458 -0.009,0.0891 -0.0233,0.1302 a 1.7499995,1.7499997 0 0 1 0.0233,0.27649 1.7499995,1.7499997 0 0 1 -1.75028,1.74974 z m -201.00014,0 a 1.7499995,1.7499997 0 0 1 -1.74977,-1.74974 h -14.00017 a 1.7499995,1.7499997 0 0 1 -1.74977,1.74974 1.7499995,1.7499997 0 0 1 -1.75028,-1.74974 1.7499995,1.7499997 0 0 1 0.0238,-0.2739 c -0.0148,-0.0418 -0.0238,-0.086 -0.0238,-0.13279 v -59.18711 c 0,-0.0459 0.009,-0.0891 0.0233,-0.1302 a 1.7499995,1.7499997 0 0 1 -0.0233,-0.27596 1.7499995,1.7499997 0 0 1 1.75028,-1.7503 1.7499995,1.7499997 0 0 1 1.74977,1.7503 h 14.00017 a 1.7499995,1.7499997 0 0 1 1.74977,-1.7503 1.7499995,1.7499997 0 0 1 1.75028,1.7503 1.7499995,1.7499997 0 0 1 -0.0238,0.27387 c 0.0148,0.0417 0.0238,0.0856 0.0238,0.13229 v 59.18711 c 0,0.0455 -0.009,0.0884 -0.0227,0.12917 a 1.7499995,1.7499997 0 0 1 0.0227,0.27752 1.7499995,1.7499997 0 0 1 -1.75028,1.74974 z m 201.00014,-139.99972 a 1.7499995,1.7499998 0 0 1 -1.74977,-1.75027 h -14.00018 a 1.7499995,1.7499998 0 0 1 -1.74977,1.75027 1.7499995,1.7499998 0 0 1 -1.75027,-1.75027 1.7499995,1.7499998 0 0 1 0.0238,-0.2739 c -0.0148,-0.0417 -0.0238,-0.086 -0.0238,-0.13279 v -59.18658 c 0,-0.0452 0.009,-0.0882 0.0228,-0.1292 a 1.7499995,1.7499998 0 0 1 -0.0228,-0.27749 1.7499995,1.7499998 0 0 1 1.75027,-1.74977 1.7499995,1.7499998 0 0 1 1.74977,1.74977 h 14.00018 a 1.7499995,1.7499998 0 0 1 1.74977,-1.74977 1.7499995,1.7499998 0 0 1 1.75028,1.74977 1.7499995,1.7499998 0 0 1 -0.0238,0.27337 c 0.0148,0.0419 0.0238,0.0863 0.0238,0.13332 v 59.18658 c 0,0.0458 -0.009,0.0891 -0.0233,0.13022 a 1.7499995,1.7499998 0 0 1 0.0233,0.27647 1.7499995,1.7499998 0 0 1 -1.75028,1.75027 z m -201.00014,0 a 1.7499996,1.7499998 0 0 1 -1.74977,-1.75027 h -14.00017 a 1.7499996,1.7499998 0 0 1 -1.74977,1.75027 1.7499996,1.7499998 0 0 1 -1.75028,-1.75027 1.7499996,1.7499998 0 0 1 0.0238,-0.2739 c -0.0148,-0.0417 -0.0238,-0.086 -0.0238,-0.13279 v -59.18658 c 0,-0.0463 0.009,-0.0892 0.0233,-0.13023 a 1.7499996,1.7499998 0 0 1 -0.0233,-0.27646 1.7499996,1.7499998 0 0 1 1.75028,-1.74977 1.7499996,1.7499998 0 0 1 1.74977,1.74977 h 14.00017 a 1.7499996,1.7499998 0 0 1 1.74977,-1.74977 1.7499996,1.7499998 0 0 1 1.75028,1.74977 1.7499996,1.7499998 0 0 1 -0.0238,0.27337 c 0.0148,0.0419 0.0238,0.0863 0.0238,0.13332 v 59.18658 c 0,0.0455 -0.009,0.0884 -0.0227,0.12919 a 1.7499996,1.7499998 0 0 1 0.0227,0.2775 1.7499996,1.7499998 0 0 1 -1.75028,1.75027 z"
|
|
id="rect1011-0-7"
|
|
inkscape:connector-curvature="0" />
|
|
</g>
|
|
</svg>`;
|
|
|
|
|
|
|
|
paper.install(window);
|
|
window.onload = function() {
|
|
// Setup directly from canvas id:
|
|
paper.setup('myCanvas');
|
|
|
|
Leaf.veinArea = new Path();
|
|
Leaf.auxinArea = new Path();
|
|
Leaf.size = 100; //200;
|
|
Leaf.auxinR = 13;
|
|
Leaf.veinR = Leaf.auxinR;
|
|
Leaf.auxinNr = 30;
|
|
Leaf.veinGrowRate = 2;
|
|
Leaf.leafGrowRate = 2; //1.04;
|
|
Leaf.maxGrowIters = 100;
|
|
//Leaf.maxSize = 1338*0.75; //legs
|
|
//Leaf.maxSize = 1511*0.75; //seat
|
|
Leaf.maxSize = 500;
|
|
Leaf.branches = [];
|
|
Leaf.auxin = [];
|
|
Leaf.color = Color.random();
|
|
|
|
Leaf.finishedShape = new Path();
|
|
Leaf.finished = false;
|
|
Leaf.final = false;
|
|
|
|
Leaf.mouse = new Path.Circle(new Point(0,0),10);
|
|
|
|
Leaf.uniform = true;
|
|
|
|
|
|
var leaf = new Leaf(new Point(view.bounds.width/2,view.bounds.height-100));
|
|
Leaf.trycount = 10;
|
|
|
|
/*view.onMouseDown = function(event){
|
|
|
|
//leaf.iteration();
|
|
//console.log(leaf.veins);
|
|
}
|
|
|
|
view.onMouseMove = function(event){
|
|
|
|
//Leaf.mouse.position = event.point;
|
|
//var b = leaf.veins.getClosestBranch(event.point);
|
|
//Leaf.mouse.fillColor = b.path.strokeColor;
|
|
//console.log(leaf.veins);
|
|
}*/
|
|
|
|
view.onClick = function(event){
|
|
var svg = project.exportSVG({ asString: true });
|
|
var svgBlob = new Blob([svg], {type:"image/svg+xml;charset=utf-8"});
|
|
var svgUrl = URL.createObjectURL(svgBlob);
|
|
var downloadLink = document.createElement("a");
|
|
downloadLink.href = svgUrl;
|
|
downloadLink.download = "growth.svg";
|
|
document.body.appendChild(downloadLink);
|
|
downloadLink.click();
|
|
document.body.removeChild(downloadLink);
|
|
}
|
|
|
|
view.onFrame = function(event) {
|
|
// On each frame, rotate the path by 3 degrees:
|
|
|
|
if(leaf.shape.bounds.height<Leaf.maxSize){
|
|
leaf.iteration();
|
|
}else{
|
|
|
|
if(!Leaf.finished){
|
|
|
|
leaf.iteration();
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
if(!Leaf.final){
|
|
console.log('finalize');
|
|
leaf.removeSmallVeins();
|
|
|
|
leaf.sortChildbranches();
|
|
leaf.rearrangeBranches();
|
|
leaf.calcWidth();
|
|
leaf.shape.remove();
|
|
Leaf.final = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class Auxin{
|
|
constructor(point, closestVein){
|
|
this.pos = point;
|
|
this.closest = closestVein;
|
|
this.drawNode(this.pos);
|
|
Leaf.auxin.push(this);
|
|
}
|
|
|
|
drawNode(point){
|
|
this.node = new Path.Circle(point,3);
|
|
this.node.fillColor = 'red';
|
|
}
|
|
|
|
remove(){
|
|
this.node.remove();
|
|
//this.node.fillColor = 'pink';
|
|
}
|
|
|
|
scale(perc, pos){
|
|
this.node.scale(perc, pos);
|
|
this.pos = this.node.position;
|
|
}
|
|
|
|
}
|
|
|
|
class Leaf{
|
|
|
|
|
|
|
|
constructor(startpoint) {
|
|
this.pos = startpoint;
|
|
|
|
//this.shape = new Path.Circle(new Point(this.pos.x-Leaf.size,this.pos.y-Leaf.size),Leaf.size);
|
|
|
|
/*this.shape = new Path();
|
|
this.shape.add(new Segment(new Point(this.pos.x, this.pos.y), new Point(Leaf.size,0), new Point(-Leaf.size,0)));
|
|
this.shape.add(new Point(this.pos.x, this.pos.y-Leaf.size));
|
|
this.shape.closed = true;
|
|
*/
|
|
|
|
var rect = new Rectangle(new Point(startpoint.x-Leaf.size/2, startpoint.y-Leaf.size), new Size(Leaf.size, Leaf.size));
|
|
this.shape = new Path.Rectangle(rect,10);
|
|
|
|
//this.shape = new Path.RegularPolygon(new Point(this.pos.x, this.pos.y-Leaf.size), 3, 50);
|
|
|
|
|
|
//this.shape = project.importSVG(footstring2);
|
|
//this.shape = project.importSVG(seatstring);
|
|
|
|
//this.shape = this.shape.children[1];
|
|
|
|
this.shape.strokeColor = 'black';
|
|
this.shape.strokeWidth = 3;
|
|
this.shape.fillColor = 'blue';
|
|
|
|
|
|
//this.shape.position = new Point(this.pos.x, this.pos.y);
|
|
this.shape.position = new Point(this.pos.x, this.pos.y);
|
|
this.shape.scale(Leaf.size/this.shape.bounds.height, this.pos);
|
|
//this.shape.translate(new Point(-this.shape.bounds.width/2+Leaf.veinR/2,-this.shape.bounds.height/3+Leaf.veinR/2));
|
|
|
|
|
|
|
|
this.veins = new VeinGraph(this.pos);
|
|
this.auxin = [];
|
|
this.growCount = 0;
|
|
}
|
|
|
|
iteration(){
|
|
|
|
this.growVeins();
|
|
this.removeConsumedAuxin();
|
|
if(this.shape.bounds.height<Leaf.maxSize){
|
|
this.growLeaf();
|
|
}
|
|
if(!this.placeAuxin()){
|
|
Leaf.trycount--;
|
|
}else{
|
|
Leaf.trycount = 10;
|
|
}
|
|
if(Leaf.trycount==0){
|
|
Leaf.finished = true;
|
|
}
|
|
this.attractVeins();
|
|
}
|
|
|
|
placeAuxin(){
|
|
var f = false;
|
|
for(var i = 0; i<Leaf.auxinNr; i++){
|
|
var point = new Point(this.shape.bounds.width, this.shape.bounds.height).multiply(Point.random()).add(this.shape.bounds.topLeft);
|
|
|
|
if(this.shape.contains(point) && this.veins.getDist(point)>Leaf.veinR && !this.auxinTooClose(point)){
|
|
//if(this.isEmptyAuxinNeighbourhood(point) && this.isEmptyVeinNeighbourhood(point)){
|
|
this.auxin.push(new Auxin(point));
|
|
f = true;
|
|
|
|
|
|
//tmp.fillColor = 'green';
|
|
//Leaf.auxinArea.strokeColor = 'red';
|
|
|
|
//}
|
|
}
|
|
}
|
|
return f;
|
|
}
|
|
|
|
auxinTooClose(point){
|
|
for(var i = 0; i<Leaf.auxin.length; i++){
|
|
if(Leaf.auxin[i].pos.getDistance(point)<Leaf.auxinR){
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
removeConsumedAuxin(){
|
|
var newauxin = []
|
|
for(var i = 0; i<this.auxin.length; i++){
|
|
if(this.veins.getDist(this.auxin[i].pos)>Leaf.veinR){
|
|
newauxin.push(this.auxin[i]);
|
|
}else{
|
|
this.auxin[i].remove();
|
|
}
|
|
}
|
|
this.auxin = newauxin;
|
|
}
|
|
|
|
attractVeins(){
|
|
for(var i = 0; i<this.auxin.length; i++){
|
|
//var closestNode = this.veins.getClosest(this.auxin[i]);
|
|
var n = this.veins.getClosestNode(this.auxin[i].pos);
|
|
//var p = this.veins.getClosestNodePoint(this.auxin[i].pos);
|
|
var b = this.veins.getClosestBranch(this.auxin[i].pos);
|
|
n.setInfluence(this.auxin[i]);
|
|
//var line = new Path.Line(p, this.auxin[i].pos);
|
|
//line.strokeColor = 'grey';
|
|
|
|
this.auxin[i].node.fillColor = b.path.strokeColor;
|
|
|
|
}
|
|
}
|
|
|
|
growVeins(){
|
|
this.veins.grow();
|
|
}
|
|
|
|
growLeaf(){
|
|
var perc = (this.shape.bounds.height+Leaf.leafGrowRate)/this.shape.bounds.height;
|
|
this.shape.scale(perc, this.pos)
|
|
if(Leaf.uniform){
|
|
this.scaleAuxin(perc);
|
|
this.scaleBranches(perc);
|
|
}
|
|
}
|
|
|
|
scaleAuxin(perc){
|
|
for(var i = 0; i<Leaf.auxin.length; i++){
|
|
Leaf.auxin[i].scale(perc, this.pos);
|
|
}
|
|
}
|
|
|
|
scaleBranches(perc){
|
|
for(var i = 0; i<Leaf.branches.length; i++){
|
|
Leaf.branches[i].scale(perc, this.pos);
|
|
}
|
|
}
|
|
|
|
removeSmallVeins(){
|
|
this.veins.removeSmallVeins();
|
|
}
|
|
|
|
calcWidth(){
|
|
this.veins.calcWidth();
|
|
}
|
|
|
|
sortChildbranches(){
|
|
this.veins.sortChildbranches();
|
|
}
|
|
|
|
rearrangeBranches(){
|
|
this.veins.rearrangeBranches();
|
|
}
|
|
|
|
}
|
|
|
|
class VeinGraph{
|
|
|
|
constructor(point) {
|
|
this.root = new VeinBranch(point);
|
|
this.root.addConnection(new Point(point.x, point.y-10));
|
|
}
|
|
|
|
getClosestNode(point){
|
|
var b = this.getClosestBranch(point);
|
|
|
|
return b.getClosestNode(point);
|
|
}
|
|
|
|
getClosestNodePoint(point){
|
|
var b = this.getClosestBranch(point);
|
|
|
|
return b.getClosestNodePoint(point);
|
|
}
|
|
|
|
getClosestBranch(point){
|
|
//var b = this.root.getClosestBranch(point, this.root);
|
|
var b = this.root;
|
|
var dist = this.root.path.getNearestPoint(point).getDistance(point);
|
|
var dist2 = 0;
|
|
for(var i = 0; i<Leaf.branches.length; i++){
|
|
|
|
dist2 = Leaf.branches[i].path.getNearestPoint(point).getDistance(point);
|
|
|
|
if(dist2<dist){
|
|
|
|
dist = dist2;
|
|
b = Leaf.branches[i];
|
|
}
|
|
}
|
|
|
|
return b;
|
|
}
|
|
|
|
getDist(point){
|
|
var b = this.getClosestBranch(point);
|
|
var p = b.getClosestPoint(point);
|
|
return p.getDistance(point);
|
|
}
|
|
|
|
|
|
grow(){
|
|
this.root.grow();
|
|
}
|
|
|
|
removeSmallVeins(){
|
|
this.root.removeSmallVeins();
|
|
}
|
|
|
|
calcWidth(){
|
|
this.root.calcWidth();
|
|
}
|
|
|
|
sortChildbranches(){
|
|
this.root.sortChildbranches();
|
|
}
|
|
|
|
rearrangeBranches(){
|
|
this.root.rearrangeBranches();
|
|
}
|
|
|
|
}
|
|
|
|
class VeinBranch{
|
|
constructor(point) {
|
|
this.path = new Path();
|
|
//var col = Color.random();
|
|
//this.path.strokeColor = col;
|
|
this.path.strokeColor = 'black';
|
|
this.path.strokeCap = 'round';
|
|
this.path.strokeWidth = 3;
|
|
this.nodes = [];
|
|
this.childBranches = [];
|
|
if(point){
|
|
this.addConnection(point);
|
|
}
|
|
|
|
Leaf.branches.push(this);
|
|
}
|
|
|
|
rearrangeBranches(){
|
|
if(this.childBranches.length>0){
|
|
var newPath = this.path.splitAt(this.path.getLocationOf(this.childBranches[0].path.firstSegment.point));
|
|
//newPath.strokeColor = Color.random();
|
|
|
|
var newBranch = new VeinBranch();
|
|
newBranch.path = newPath;
|
|
console.log(newBranch.childBranches);
|
|
for(var i = 1; i<this.childBranches.length; i++){
|
|
newBranch.childBranches.push(this.childBranches[i]);
|
|
}
|
|
|
|
|
|
this.childBranches = [this.childBranches[0]];
|
|
this.childBranches.push(newBranch);
|
|
console.log(this);
|
|
|
|
this.childBranches[0].rearrangeBranches();
|
|
this.childBranches[1].rearrangeBranches();
|
|
}
|
|
|
|
}
|
|
|
|
sortChildbranches(){
|
|
//console.log(this.childBranches);
|
|
this.childBranches.sort((a, b) => (this.path.getOffsetOf(a.path.firstSegment.point) > this.path.getOffsetOf(b.path.firstSegment.point)) ? 1 : -1)
|
|
//console.log(this.childBranches);
|
|
for(var i = 0; i<this.childBranches.length; i++){
|
|
this.childBranches[i].sortChildbranches();
|
|
}
|
|
}
|
|
|
|
addConnection(point){
|
|
this.path.add(point);
|
|
this.nodes.push(new VeinNode());
|
|
}
|
|
|
|
addBranch(point1, point2){
|
|
var b = new VeinBranch(point1);
|
|
b.addConnection(point2);
|
|
this.childBranches.push(b);
|
|
}
|
|
|
|
getClosestPoint(point){
|
|
|
|
var p = this.path.getNearestPoint(point);
|
|
|
|
return p;
|
|
}
|
|
|
|
getClosestNode(point){
|
|
|
|
var dist = this.path.firstSegment.point.getDistance(point);
|
|
var node = 0;
|
|
for( var i = 1; i<this.path.segments.length; i++){
|
|
var compdist = this.path.segments[i].point.getDistance(point);
|
|
if(compdist<dist){
|
|
node = i;
|
|
dist = compdist;
|
|
}
|
|
}
|
|
return this.nodes[node];
|
|
}
|
|
|
|
getClosestNodePoint(point){
|
|
var dist = this.path.firstSegment.point.getDistance(point);
|
|
var node = 0;
|
|
for( var i = 1; i<this.path.segments.length; i++){
|
|
var compdist = this.path.segments[i].point.getDistance(point);
|
|
if(compdist<dist){
|
|
node = i;
|
|
dist = compdist;
|
|
}
|
|
}
|
|
return this.path.segments[node].point;
|
|
}
|
|
|
|
/*getClosestBranch(point, veinbranch){
|
|
|
|
var p = this.path.getNearestPoint(point);
|
|
var compdist = point.getDistance(p);
|
|
var pvb = veinbranch.path.getNearestPoint(point);
|
|
var dist = point.getDistance(pvb);
|
|
|
|
var smallest = this;
|
|
if(dist<compdist){
|
|
smallest = veinbranch;
|
|
compdist = dist;
|
|
}
|
|
for(var i = 0; i<this.childBranches.length; i++){
|
|
|
|
var b = this.childBranches[i].getClosestBranch(point,smallest);
|
|
p = b.path.getNearestPoint(point);
|
|
dist = point.getDistance(p);
|
|
if(dist<compdist){
|
|
smallest = this.childBranches[i];
|
|
compdist = dist;
|
|
}
|
|
}
|
|
return smallest;
|
|
|
|
}*/
|
|
|
|
grow(){
|
|
for(var i = 0; i<this.nodes.length; i++){
|
|
var n = this.nodes[i].grow(this.path.segments[i].point);
|
|
if(n!=null){
|
|
var newpoint = this.path.segments[i].point.add(n);
|
|
if(i==this.nodes.length-1){
|
|
this.addConnection(newpoint);
|
|
}else{
|
|
this.addBranch(this.path.segments[i].point,newpoint);
|
|
}
|
|
}
|
|
}
|
|
for(var i=0; i<this.childBranches.length; i++){
|
|
this.childBranches[i].grow();
|
|
}
|
|
}
|
|
|
|
scale(perc, pos){
|
|
this.path.scale(perc, pos);
|
|
}
|
|
|
|
remove(){
|
|
this.path.remove();
|
|
}
|
|
|
|
removeSmallVeins(){
|
|
for(var i = this.childBranches.length-1; i>=0; i--){
|
|
if(this.childBranches[i].path.length<Leaf.auxinR && this.childBranches[i].childBranches.length==0){
|
|
this.childBranches[i].remove();
|
|
this.childBranches.splice(i,1);
|
|
}else{
|
|
this.childBranches[i].removeSmallVeins();
|
|
}
|
|
}
|
|
}
|
|
|
|
calcWidth(){
|
|
if(this.childBranches.length==0){
|
|
//this.path.strokeWidth = 10;
|
|
//return 10;
|
|
this.path.strokeWidth = Leaf.auxinR-2;
|
|
this.path.strokeColor = Leaf.color;
|
|
return Leaf.auxinR-2;
|
|
}
|
|
this.path.bringToFront();
|
|
var wid = 0;
|
|
for(var i = 0; i<this.childBranches.length; i++){
|
|
var w = this.childBranches[i].calcWidth();
|
|
wid = wid + Math.pow(w,4);
|
|
}
|
|
wid = Math.pow(wid, 1/4);
|
|
this.path.strokeWidth = wid;
|
|
this.path.strokeColor = Leaf.color;
|
|
this.path.strokeColor.hue += wid;
|
|
return wid;
|
|
}
|
|
}
|
|
|
|
class VeinNode{
|
|
|
|
constructor() {
|
|
this.auxinInfluence = [];
|
|
}
|
|
|
|
grow(pos){
|
|
//
|
|
if(this.auxinInfluence.length>0){
|
|
var direction = new Point(0,0);
|
|
var oldDists = [];
|
|
for(var i = 0; i<this.auxinInfluence.length; i++){
|
|
var dir = this.auxinInfluence[i].pos.subtract(pos).normalize();
|
|
direction = direction.add(dir);
|
|
|
|
oldDists.push(this.auxinInfluence[i].pos.getDistance(pos));
|
|
}
|
|
if(direction.length<1){
|
|
return null;
|
|
}
|
|
direction = direction.normalize(Leaf.veinGrowRate);
|
|
this.auxinInfluence = [];
|
|
return direction;
|
|
|
|
}
|
|
|
|
this.auxinInfluence = [];
|
|
return null;
|
|
}
|
|
|
|
setInfluence(point){
|
|
this.auxinInfluence.push(point);
|
|
}
|
|
}
|
|
|
|
|
|
|