mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
js mode examples cleanup, automated import of included examples in getExampleCategoryFolders()
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* <form><input type="file" id="file-input"/></form>
|
||||
*
|
||||
* No Safari support.
|
||||
*/
|
||||
|
||||
PImage img = null;
|
||||
|
||||
void setup ()
|
||||
{
|
||||
size(300, 200);
|
||||
}
|
||||
|
||||
void draw ()
|
||||
{
|
||||
background(255);
|
||||
if ( img != null ) image(img, 0,0, width,height);
|
||||
}
|
||||
|
||||
void newImageAvailable ( Image i )
|
||||
{
|
||||
img = new PImage( i );
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
window.onload = function () {
|
||||
tryFindSketch();
|
||||
}
|
||||
|
||||
function tryFindSketch() {
|
||||
var sketch = Processing.instances[0];
|
||||
if ( sketch == undefined )
|
||||
return setTimeout(tryFindSketch, 200); // retry soon
|
||||
|
||||
sketch.console = console;
|
||||
initUploader(sketch);
|
||||
}
|
||||
|
||||
function initUploader ( sketch ) {
|
||||
var uploadField = document.getElementById("file-input");
|
||||
|
||||
uploadField.onchange = function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var file = uploadField.files[0];
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function (event) {
|
||||
var img = new Image();
|
||||
img.onload = function (event2) {
|
||||
sketch.newImageAvailable(img);
|
||||
}
|
||||
img.src = event.target.result;
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user