Skip to content

Commit

Permalink
add dataurl example
Browse files Browse the repository at this point in the history
  • Loading branch information
zenozeng committed Sep 14, 2015
1 parent fc789f2 commit 1181460
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 59 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ [email protected] (requires [email protected])

- add p5.prototype.registerSVGFilter

- add p5.prototype.getSerializedSVG
- add p5.prototype.getDataURL

## v0.4.3

Expand Down
13 changes: 8 additions & 5 deletions dist/p5.svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2025,13 +2025,16 @@ module.exports = function(p5) {
// so that it won't make preload mess
setTimeout(function() {
if (path.indexOf(';base64,') > -1) {
successCallback(atob(svg));
svg = atob(svg);
} else {
successCallback(decodeURIComponent(svg));
svg = decodeURIComponent(svg);
}
successCallback(svg);
}, 1);
return svg;
} else {
this.httpGet(path, successCallback);
return null;
}
};

Expand Down Expand Up @@ -2064,7 +2067,7 @@ module.exports = function(p5) {
// cause preload to wait
p5.prototype._preloadMethods.loadSVG = p5.prototype;

p5.prototype.getSerializedSVG = function() {
p5.prototype.getDataURL = function() {
return this._graphics.elt.toDataURL('image/svg+xml');
};
};
Expand Down Expand Up @@ -2187,9 +2190,9 @@ module.exports = function(p5) {
}
this._setGCFlag(element);
var g = this.drawingContext.__closestGroupOrSvg();
console.log(g, element);
g.appendChild(element);
console.log(g);
// window.g = g;
// window.x = element;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/RendererSVG.html
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/SVGElement.html
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/element.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/filters.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
11 changes: 7 additions & 4 deletions doc/reference/io.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,16 @@ <h1 class="page-title">Source: io.js</h1>
// so that it won't make preload mess
setTimeout(function() {
if (path.indexOf(';base64,') > -1) {
successCallback(atob(svg));
svg = atob(svg);
} else {
successCallback(decodeURIComponent(svg));
svg = decodeURIComponent(svg);
}
successCallback(svg);
}, 1);
return svg;
} else {
this.httpGet(path, successCallback);
return null;
}
};

Expand Down Expand Up @@ -312,7 +315,7 @@ <h1 class="page-title">Source: io.js</h1>
// cause preload to wait
p5.prototype._preloadMethods.loadSVG = p5.prototype;

p5.prototype.getSerializedSVG = function() {
p5.prototype.getDataURL = function() {
return this._graphics.elt.toDataURL('image/svg+xml');
};
};
Expand All @@ -332,7 +335,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
6 changes: 3 additions & 3 deletions doc/reference/p5.RendererSVG.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ <h1 class="page-title">Source: p5.RendererSVG.js</h1>
}
this._setGCFlag(element);
var g = this.drawingContext.__closestGroupOrSvg();
console.log(g, element);
g.appendChild(element);
console.log(g);
// window.g = g;
// window.x = element;
};

/**
Expand Down Expand Up @@ -197,7 +197,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/p5.SVGFilters.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions doc/reference/p5.html
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ <h4 class="name" id="loadSVG"><span class="type-signature"></span>loadSVG<span c

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="io.js.html">io.js</a>, <a href="io.js.html#line258">line 258</a>
<a href="io.js.html">io.js</a>, <a href="io.js.html#line261">line 261</a>
</li></ul></dd>


Expand Down Expand Up @@ -1574,7 +1574,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion doc/reference/rendering.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RendererS
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 21:59:52 GMT+0800 (CST)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Mon Sep 14 2015 22:45:00 GMT+0800 (CST)
</footer>

<script> prettyPrint(); </script>
Expand Down
26 changes: 0 additions & 26 deletions examples/examples/click.js

This file was deleted.

31 changes: 31 additions & 0 deletions examples/examples/dataurl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var graphics;
function setup() {
graphics = createCanvas(600, 200, SVG); // Create SVG Canvas
fill('#ED225D');
noStroke();
window.mouseClickedFlag = false;
}

function draw() {
if (window.mouseClickedFlag) {
var dataURL = getDataURL();
// Note that because draw is in setTimeout, if we call noLoop inside mouseClicked, draw will still be called one more time
noLoop();
// draw the dataurl
var svg = loadSVG(dataURL, function(svg) {
image(svg, 50, 50, 600, 200);
});
} else {
clear();
var a = min(frameCount, 1200);
var b = min(frameCount, 400);
ellipse(0, 0, a, b);
if (frameCount > 1200) {
noLoop();
}
}
}

function mouseClicked() {
window.mouseClickedFlag = true;
}
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1>Examples for p5.SVG</h1>
<li><a href="#graphics">SVG Graphics</a></li>
<li><a href="#exporting">Exporting SVG</a></li>
<li><a href="#manipulating">Manipulating Existing SVG</a></li>
<li><a href="#click">Open Current SVG dataURL onclick</a></li>
<li><a href="#dataurl">Convert to dataURL and draw dataURL</a></li>
</ul>
<h2>The SVG Canvas</h2>
<div id="canvas"></div>
Expand Down
5 changes: 2 additions & 3 deletions examples/lib/demo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var route = function() {
var section = window.location.hash;
section = section.replace(/#/g, "");
if (["basic", "element", "manipulating", "filters", "graphics", "exporting", "click"].indexOf(section) === -1) {
if (["basic", "element", "manipulating", "filters", "graphics", "exporting", "dataurl"].indexOf(section) === -1) {
window.location.hash = "basic";
return;
}
Expand Down Expand Up @@ -37,7 +37,6 @@ var route = function() {
route();

window.onhashchange = function() {
route();
window.noLoop && window.noLoop();
window.location.reload();
};

9 changes: 6 additions & 3 deletions src/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,16 @@ module.exports = function(p5) {
// so that it won't make preload mess
setTimeout(function() {
if (path.indexOf(';base64,') > -1) {
successCallback(atob(svg));
svg = atob(svg);
} else {
successCallback(decodeURIComponent(svg));
svg = decodeURIComponent(svg);
}
successCallback(svg);
}, 1);
return svg;
} else {
this.httpGet(path, successCallback);
return null;
}
};

Expand Down Expand Up @@ -284,7 +287,7 @@ module.exports = function(p5) {
// cause preload to wait
p5.prototype._preloadMethods.loadSVG = p5.prototype;

p5.prototype.getSerializedSVG = function() {
p5.prototype.getDataURL = function() {
return this._graphics.elt.toDataURL('image/svg+xml');
};
};
2 changes: 0 additions & 2 deletions src/p5.RendererSVG.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ module.exports = function(p5) {
}
this._setGCFlag(element);
var g = this.drawingContext.__closestGroupOrSvg();
console.log(g, element);
g.appendChild(element);
console.log(g);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion test/bower_components/p5.js/p5.js
Original file line number Diff line number Diff line change
Expand Up @@ -27071,4 +27071,4 @@ p5.prototype.year = function() {
module.exports = p5;

},{"../core/core":47}]},{},[38])(38)
});
});

0 comments on commit 1181460

Please sign in to comment.