From 61233ae6c9eb9868891e22a40d5d66917483b45f Mon Sep 17 00:00:00 2001 From: Fisch Date: Sun, 14 Jan 2018 00:39:56 +0100 Subject: [PATCH] implement simulator in processing --- .../matrixsimulator_processing.pde | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 client_sw/matrixsimulator_processing/matrixsimulator_processing.pde diff --git a/client_sw/matrixsimulator_processing/matrixsimulator_processing.pde b/client_sw/matrixsimulator_processing/matrixsimulator_processing.pde new file mode 100644 index 0000000..1ed8bab --- /dev/null +++ b/client_sw/matrixsimulator_processing/matrixsimulator_processing.pde @@ -0,0 +1,109 @@ +import hypermedia.net.*; + +int pixelSize = 4; +int bitPerPixel = 2; +int width=160; +int height=144; +int windowWidth=width*pixelSize; +int windowHeight=height*pixelSize; + +UDP udp; + +byte[] emptyByteArray = new byte[0]; +byte receivedData[]=emptyByteArray; +byte imagebuffer[][]=new byte[width][height]; + +PImage led[]=new PImage[(int)pow(2,bitPerPixel)]; + +void settings() { + size(width*pixelSize, height*pixelSize,P2D); +} + +void setup() { + //Setup Graphics + + frameRate(30); + noSmooth(); + background(0); + noStroke(); + + //UDP + udp = new UDP( this, 2323 ); + //udp.log( true ); // <-- printout the connection activit + udp.listen( true ); + + //Precompute LED Images + for (byte b=0;b1){ + brightnessMultiplier=1; + } + + colorR*=brightnessMultiplier; + colorG*=brightnessMultiplier; + colorB*=brightnessMultiplier; + + led[b].pixels[py*pixelSize+px] = color(colorR,colorG,colorB); + } + } + led[b].updatePixels(); + } +} + +//draw event handler +void draw() { + //map byte data to imagebuffer + if (receivedData.length > 0){ //new data? + byte[] cachedData=receivedData; //cache data to free array for new data + receivedData = emptyByteArray; + + for (int i=0;i> (shift*bitPerPixel); //mask relevant bits for current pixel + + imagebuffer[x][y]=(byte)value; //write pixel value to image buffer + } + } + + } + + clear(); //clear screen + + //int timeA=millis(); + + //Draw leds + for (int x = 0; x < imagebuffer.length; x++){ + for (int y = 0; y < imagebuffer[x].length; y++){ + byte pixel=imagebuffer[x][y]; + + //fill(255/3*pixel,127/3*pixel,0); //set pixel color + //ellipse(x*pixelSize+pixelSize/2, y*pixelSize+pixelSize/2, pixelSize, pixelSize); //Very slow + //rect(x*pixelSize, y*pixelSize, pixelSize, pixelSize); //works fast enough + + image(led[pixel], x*pixelSize, y*pixelSize); //draw precomputed led image, as fast as rect but looks nicer + } + } + + //int timeB=millis()-timeA; + //println("Time="+(timeB)); + + +} + +//udp receive event handler +void receive( byte[] data, String ip, int port ) { + receivedData=data; //received data to buffer +} \ No newline at end of file