From c00638eac490a8961ab74c13a753aac312cc105d Mon Sep 17 00:00:00 2001 From: Robert Plummer Date: Fri, 8 Jun 2018 09:43:58 -0400 Subject: [PATCH 1/2] Correct documentation --- README.md | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 989bacca..9b04f270 100644 --- a/README.md +++ b/README.md @@ -203,9 +203,13 @@ const myFunc = gpu.createKernel(function(image) { }) .setGraphical(true) .setOutput([100]); - -myFunc([1, 2, 3]); -// Result: colorful image + +const image = new document.createElement('img'); +image.src = 'my/image/source.png'; +image.onload = () => { + myFunc(image); + // Result: colorful image +}; ``` An Array of HTML Images: @@ -217,9 +221,22 @@ const myFunc = gpu.createKernel(function(image) { }) .setGraphical(true) .setOutput([100]); - -myFunc([1, 2, 3]); -// Result: colorful image + +const image1 = new document.createElement('img'); +image1.src = 'my/image/source1.png'; +const image2 = new document.createElement('img'); +image2.src = 'my/image/source2.png'; +const image3 = new document.createElement('img'); +image3.src = 'my/image/source3.png'; +const totalImages = 3; +let loadedImages = 0; +const onload = () => { + loadedImages++; + if (loadedImages === totalImages) { + myFunc([image1, image2, image3]); + // Result: colorful image composed of many images + } +}; ``` ## Graphical Output From 20b0ffe71fb8297d9df33f58ff1096644215eb17 Mon Sep 17 00:00:00 2001 From: Robert Plummer Date: Fri, 8 Jun 2018 09:47:03 -0400 Subject: [PATCH 2/2] Use onload for images example --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b04f270..198599cb 100644 --- a/README.md +++ b/README.md @@ -224,13 +224,16 @@ const myFunc = gpu.createKernel(function(image) { const image1 = new document.createElement('img'); image1.src = 'my/image/source1.png'; +image1.onload = onload; const image2 = new document.createElement('img'); image2.src = 'my/image/source2.png'; +image2.onload = onload; const image3 = new document.createElement('img'); image3.src = 'my/image/source3.png'; +image3.onload = onload; const totalImages = 3; let loadedImages = 0; -const onload = () => { +function onload() { loadedImages++; if (loadedImages === totalImages) { myFunc([image1, image2, image3]);