-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
draft of processing version of WeMakeColors
- Loading branch information
1 parent
c130058
commit 00cfb3c
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"><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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mode=Java | ||
mode.id=processing.mode.java.JavaMode |