You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.6 KiB

6 years ago
<title>JavaScript <=> PaperScript example</title>
<code mode="text/html">
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="paper.js"></script>
<script type="text/paperscript" canvas="canvas">
var xstart = Math.random();
var ystart = Math.random();
var scale = 500;
var num_steps = 10;
var num_lines = 5;
var lines = [];
for(var i=0; i<num_lines; i++) {
var x = xstart + i*0.0001;
var y = ystart + i*0.0001;
var path = new Path({strokeWidth: 1, strokeColor: 'black'});
for(var s=0; s<num_steps; s++) {
x = (4*x*(1-x)) % 1;
y = (x+y) % 1;
var p = new Point(x*scale, y*scale);
path.add(p);
//console.log(p);
}
lines.push(path);
}
globals.get_svg = function() {
return project.exportSVG({asString: true});
}
</script>
<script type="text/javascript">
//document.addEventListener('DOMContentLoaded', function() {
window.globals = {}
window.onload = function() {
/*
draw();
document.getElementById('redraw').addEventListener('click', function() {
draw();
});
*/
paper.install(window);
console.log(window.globals);
document.getElementById('download-svg').addEventListener('click', function() {
var svgdata = 'data:image/svg+xml;utf8,' + encodeURIComponent(window.globals.get_svg());
var a = document.createElement('a');
a.download = 'export.svg';
a.href = svgdata;
document.body.appendChild(a);
a.click();
});
}
</script>
</head>
<body>
<button id="download-svg">download svg</button>
<canvas id="canvas" style="width: 500px; height: 500px;" resize></canvas>
</body>
</html>