From 2dfe064538a81b79d490ff258b4ccf3e275c844b Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott <micah@scanlime.org> Date: Thu, 14 Nov 2013 13:02:46 -0800 Subject: [PATCH] Add getPixel to OPC.pde --- doc/processing_opc_client.md | 8 ++++++++ examples/processing/grid24x8z_clouds/OPC.pde | 11 +++++++++++ examples/processing/grid24x8z_dot/OPC.pde | 11 +++++++++++ examples/processing/grid24x8z_flashy_rings/OPC.pde | 11 +++++++++++ examples/processing/grid24x8z_rings/OPC.pde | 11 +++++++++++ .../processing/grid24x8z_rings_leapmotion/OPC.pde | 11 +++++++++++ examples/processing/grid24x8z_sequencer/OPC.pde | 11 +++++++++++ examples/processing/grid24x8z_text/OPC.pde | 11 +++++++++++ examples/processing/grid24x8z_waves/OPC.pde | 11 +++++++++++ examples/processing/grid8x8_dot/OPC.pde | 11 +++++++++++ examples/processing/grid8x8_orbits/OPC.pde | 11 +++++++++++ examples/processing/strip64_dot/OPC.pde | 11 +++++++++++ examples/processing/strip64_flames/OPC.pde | 11 +++++++++++ examples/processing/strip64_unmapped/OPC.pde | 11 +++++++++++ examples/processing/template/OPC.pde | 11 +++++++++++ 15 files changed, 162 insertions(+) diff --git a/doc/processing_opc_client.md b/doc/processing_opc_client.md index 214ed49..f1300c5 100644 --- a/doc/processing_opc_client.md +++ b/doc/processing_opc_client.md @@ -144,6 +144,14 @@ This section lists all public methods available on the OPC object: ---- +* *color* = **opc.getPixel**(*index*) + * Retrieves the color stored for a single LED pixel. + * For LEDs mapped to on-screen pixels, this returns the color we sampled on the previous frame. + * **index**: The index number for this LED, starting with zero + * **color**: A Processing color object (24-bit) + +---- + * **opc.writePixels**() * Send all buffered pixels to the OPC server * If any pixels have been mapped on-screen, this happens automatically after every draw() diff --git a/examples/processing/grid24x8z_clouds/OPC.pde b/examples/processing/grid24x8z_clouds/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/grid24x8z_clouds/OPC.pde +++ b/examples/processing/grid24x8z_clouds/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/grid24x8z_dot/OPC.pde b/examples/processing/grid24x8z_dot/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/grid24x8z_dot/OPC.pde +++ b/examples/processing/grid24x8z_dot/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/grid24x8z_flashy_rings/OPC.pde b/examples/processing/grid24x8z_flashy_rings/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/grid24x8z_flashy_rings/OPC.pde +++ b/examples/processing/grid24x8z_flashy_rings/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/grid24x8z_rings/OPC.pde b/examples/processing/grid24x8z_rings/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/grid24x8z_rings/OPC.pde +++ b/examples/processing/grid24x8z_rings/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/grid24x8z_rings_leapmotion/OPC.pde b/examples/processing/grid24x8z_rings_leapmotion/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/grid24x8z_rings_leapmotion/OPC.pde +++ b/examples/processing/grid24x8z_rings_leapmotion/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/grid24x8z_sequencer/OPC.pde b/examples/processing/grid24x8z_sequencer/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/grid24x8z_sequencer/OPC.pde +++ b/examples/processing/grid24x8z_sequencer/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/grid24x8z_text/OPC.pde b/examples/processing/grid24x8z_text/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/grid24x8z_text/OPC.pde +++ b/examples/processing/grid24x8z_text/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/grid24x8z_waves/OPC.pde b/examples/processing/grid24x8z_waves/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/grid24x8z_waves/OPC.pde +++ b/examples/processing/grid24x8z_waves/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/grid8x8_dot/OPC.pde b/examples/processing/grid8x8_dot/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/grid8x8_dot/OPC.pde +++ b/examples/processing/grid8x8_dot/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/grid8x8_orbits/OPC.pde b/examples/processing/grid8x8_orbits/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/grid8x8_orbits/OPC.pde +++ b/examples/processing/grid8x8_orbits/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/strip64_dot/OPC.pde b/examples/processing/strip64_dot/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/strip64_dot/OPC.pde +++ b/examples/processing/strip64_dot/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/strip64_flames/OPC.pde b/examples/processing/strip64_flames/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/strip64_flames/OPC.pde +++ b/examples/processing/strip64_flames/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/strip64_unmapped/OPC.pde b/examples/processing/strip64_unmapped/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/strip64_unmapped/OPC.pde +++ b/examples/processing/strip64_unmapped/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. diff --git a/examples/processing/template/OPC.pde b/examples/processing/template/OPC.pde index 630fb68..917035d 100644 --- a/examples/processing/template/OPC.pde +++ b/examples/processing/template/OPC.pde @@ -283,6 +283,17 @@ public class OPC packetData[offset + 2] = (byte) c; } + // Read a pixel from the output buffer. If the pixel was mapped to the display, + // this returns the value we captured on the previous frame. + color getPixel(int number) + { + int offset = 4 + number * 3; + if (packetData == null || packetData.length < offset + 3) { + return 0; + } + return (packetData[offset] << 16) | (packetData[offset + 1] << 8) | packetData[offset + 2]; + } + // Transmit our current buffer of pixel values to the OPC server. This is handled // automatically in draw() if any pixels are mapped to the screen, but if you haven't // mapped any pixels to the screen you'll want to call this directly. -- GitLab