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 }