/*************************************/ /* Arduino meets Processing via Wifi */ /* Processing Sever side sketch */ /*************************************/ import processing.net.*; int port = 5555; //Sever TCP-Port number int x = 200; int y = 200; int z = 0; Server server; String strdata = "0"; void setup(){ size(400,400,P3D); server = new Server(this, port); noStroke(); colorMode(RGB, 1); } void draw(){ Client client = server.available(); // /* Draw ColorCube */ background(0); pushMatrix(); translate(x,y,z); rotateX(PI/4); float r = float(strdata); rotateZ(PI*r/512.0-0.75); colorcube(80); popMatrix(); /* Communication with client */ if(client != null){ // if client is connecting client.write("\n"); if((strdata=client.readString()) != null){ strdata=trim(strdata); // println(strdata); } } delay(10); } /* When a client is connected */ void serverEvent(Server s, Client c){ println("Client connect - IP:"+c.ip()); // show IP } /* Draw ColorCube function */ void colorcube(int s){ scale(s); beginShape(QUADS); fill(0, 1, 1); vertex(-1, 1, 1); fill(1, 1, 1); vertex( 1, 1, 1); fill(1, 0, 1); vertex( 1, -1, 1); fill(0, 0, 1); vertex(-1, -1, 1); fill(1, 1, 1); vertex( 1, 1, 1); fill(1, 1, 0); vertex( 1, 1, -1); fill(1, 0, 0); vertex( 1, -1, -1); fill(1, 0, 1); vertex( 1, -1, 1); fill(1, 1, 0); vertex( 1, 1, -1); fill(0, 1, 0); vertex(-1, 1, -1); fill(0, 0, 0); vertex(-1, -1, -1); fill(1, 0, 0); vertex( 1, -1, -1); fill(0, 1, 0); vertex(-1, 1, -1); fill(0, 1, 1); vertex(-1, 1, 1); fill(0, 0, 1); vertex(-1, -1, 1); fill(0, 0, 0); vertex(-1, -1, -1); fill(0, 1, 0); vertex(-1, 1, -1); fill(1, 1, 0); vertex( 1, 1, -1); fill(1, 1, 1); vertex( 1, 1, 1); fill(0, 1, 1); vertex(-1, 1, 1); fill(0, 0, 0); vertex(-1, -1, -1); fill(1, 0, 0); vertex( 1, -1, -1); fill(1, 0, 1); vertex( 1, -1, 1); fill(0, 0, 1); vertex(-1, -1, 1); endShape(); } /* End of Sever side sketch */ /* Copyright by Kimio Kosaka 2008.08.20 */