From 00cfb3cc40a54ecaaf839b8b68c6aeb84e9e1ece Mon Sep 17 00:00:00 2001 From: Marco Brianza Date: Thu, 14 Apr 2016 14:58:03 +0200 Subject: [PATCH] draft of processing version of WeMakeColors --- Processing/WMCP5/AndroidManifest.xml | 1 + Processing/WMCP5/WMCP5.pde | 85 +++++++++++++++++++++++++ Processing/WMCP5/code/sketch.properties | 2 + 3 files changed, 88 insertions(+) create mode 100644 Processing/WMCP5/AndroidManifest.xml create mode 100644 Processing/WMCP5/WMCP5.pde create mode 100644 Processing/WMCP5/code/sketch.properties diff --git a/Processing/WMCP5/AndroidManifest.xml b/Processing/WMCP5/AndroidManifest.xml new file mode 100644 index 0000000..928e6a2 --- /dev/null +++ b/Processing/WMCP5/AndroidManifest.xml @@ -0,0 +1 @@ +android:theme="@android:style/Theme.NoTitleBar"> \ No newline at end of file diff --git a/Processing/WMCP5/WMCP5.pde b/Processing/WMCP5/WMCP5.pde new file mode 100644 index 0000000..6634026 --- /dev/null +++ b/Processing/WMCP5/WMCP5.pde @@ -0,0 +1,85 @@ + + +import mqtt.*; + int MAX_C=16; + +int MSG_SIZE=3; +byte c[]=new byte[MSG_SIZE]; + +color newC; + +color[] colors = new color[9]; + +MQTTClient client; + +String clientID= "processingColor2"; +String mqttURL="mqtt://net.marcobrianza.it"; + +void setup() { + size(100,900); + client = new MQTTClient(this); + client.connect(mqttURL, clientID); + client.subscribe("/WeMakeColors/color"); + noStroke(); +} + +void draw() { +} + +void mousePressed() { + byte r=byte(random(0,MAX_C)); + byte g=byte(random(0,MAX_C)); + byte b=byte(random(0,MAX_C)); + + c[0]=r; + c[1]=g; + c[2]=b; + + println(r,g,b); + client.publish("/WeMakeColors/color", c); +} + + +void connectionLost() { + println("### connection lost ##"); +} + +void messageReceived(String topic, byte[] payload) { + print("new message: " + topic + " - "+ payload.length+" - "); + int r, g, b; + if (payload.length==MSG_SIZE){ + r=payload[0]& 0xff; + g=payload[1]& 0xff; + b=payload[2]& 0xff; + + println(r, g, b); + int R=cal_lut(r); + int G=cal_lut(g); + int B=cal_lut(b); + + newC=color(R,G,B); + newColor(newC); + } +} + +void newColor(color c){ + int i; + for(i=8; i>0;i--){ + colors[i]=colors[i-1]; + } + colors[0]=c; + + for(i=0; i<9;i++){ + fill(colors[i]); + rect(0,i*100,100,100); + } + +} + + + +int cal_lut(int c){ + if (c>15) c=15; + int[] lut = {0, 11, 14, 17, 21, 27, 34, 42, 53, 66,83, 104, 130, 163, 204, 255}; + return lut[c]; +} \ No newline at end of file diff --git a/Processing/WMCP5/code/sketch.properties b/Processing/WMCP5/code/sketch.properties new file mode 100644 index 0000000..5d0c318 --- /dev/null +++ b/Processing/WMCP5/code/sketch.properties @@ -0,0 +1,2 @@ +mode=Java +mode.id=processing.mode.java.JavaMode