Skip to content

Commit

Permalink
draft of processing version of WeMakeColors
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobrianza committed Apr 14, 2016
1 parent c130058 commit 00cfb3c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions Processing/WMCP5/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package=""><uses-sdk android:minSdkVersion="15" android:targetSdkVersion="22"/><application android:debuggable="true" android:icon="@drawable/icon" android:label=""><activity android:name=".MainActivity">android:theme="@android:style/Theme.NoTitleBar"&gt;<intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity></application><uses-permission android:name="android.permission.INTERNET"/></manifest>
85 changes: 85 additions & 0 deletions Processing/WMCP5/WMCP5.pde
Original file line number Diff line number Diff line change
@@ -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];
}
2 changes: 2 additions & 0 deletions Processing/WMCP5/code/sketch.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mode=Java
mode.id=processing.mode.java.JavaMode

0 comments on commit 00cfb3c

Please sign in to comment.