Browse Source

add redraw button

master
Fr3deric 6 years ago
parent
commit
b70188ae2f
  1. 12
      baumgen.html
  2. 3
      baumgen.js

12
baumgen.html

@ -12,10 +12,13 @@
<script type="text/javascript"> <script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
console.log('ready'); draw();
var el = document.getElementById('download-svg');
console.log(el); document.getElementById('redraw').addEventListener('click', function() {
el.addEventListener('click', function() { draw();
});
document.getElementById('download-svg').addEventListener('click', function() {
var svgdata = 'data:image/svg+xml;utf8,' + encodeURIComponent(paper.project.exportSVG({asString: true})); var svgdata = 'data:image/svg+xml;utf8,' + encodeURIComponent(paper.project.exportSVG({asString: true}));
var a = document.createElement('a'); var a = document.createElement('a');
a.download = 'baumgen.svg'; a.download = 'baumgen.svg';
@ -28,6 +31,7 @@ document.addEventListener('DOMContentLoaded', function() {
</head> </head>
<body> <body>
<button id="redraw">redraw</button>
<button id="download-svg">download svg</button> <button id="download-svg">download svg</button>
<canvas id="canvas" resize></canvas> <canvas id="canvas" resize></canvas>
</body> </body>

3
baumgen.js

@ -223,7 +223,7 @@ class Branch {
} }
window.onload = function() { function draw() {
var canvas = document.getElementById('canvas'); var canvas = document.getElementById('canvas');
paper.setup(canvas); paper.setup(canvas);
@ -234,5 +234,4 @@ window.onload = function() {
var br = new Branch(gen_tree(new Point(50 + x*80, 150 + y*160))); var br = new Branch(gen_tree(new Point(50 + x*80, 150 + y*160)));
} }
} }
} }

Loading…
Cancel
Save