add flipdot simulator
This commit is contained in:
parent
6576356cb3
commit
7f6cfebf98
|
@ -0,0 +1,65 @@
|
||||||
|
import mqtt.*;
|
||||||
|
|
||||||
|
MQTTClient client;
|
||||||
|
|
||||||
|
static int pixeldistance=16;
|
||||||
|
static int pixelsize=14;
|
||||||
|
static int displaywidth=75;
|
||||||
|
static int displayheight=16;
|
||||||
|
static float pixelcornerradius=3;
|
||||||
|
static float pixelborderweight=1;
|
||||||
|
|
||||||
|
color colorWhite=color(240,255,150);
|
||||||
|
color colorBlack=color(50,50,50);
|
||||||
|
|
||||||
|
String lastDataReceived="";
|
||||||
|
|
||||||
|
PGraphics pg;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
size(1300,300);
|
||||||
|
pg = createGraphics(int(displaywidth*pixeldistance+pixelborderweight/2),int(displayheight*pixeldistance+pixelborderweight/2));
|
||||||
|
background(127);
|
||||||
|
client = new MQTTClient(this);
|
||||||
|
client.connect("mqtt://192.168.1.6", "processing-flipdot");
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw() {
|
||||||
|
pg.beginDraw();
|
||||||
|
pg.clear();
|
||||||
|
for (int y=0;y<displayheight;y++){
|
||||||
|
for (int x=0;x<displaywidth;x++){
|
||||||
|
pg.strokeWeight(pixelborderweight);
|
||||||
|
if (int(random(3))==0) {
|
||||||
|
pg.stroke(0,0,0);
|
||||||
|
pg.fill(colorWhite);
|
||||||
|
}else{
|
||||||
|
pg.stroke(0,0,0);
|
||||||
|
pg.fill(colorBlack);
|
||||||
|
}
|
||||||
|
pg.rect(x*pixeldistance+(pixeldistance-pixelsize)/2,y*pixeldistance+(pixeldistance-pixelsize)/2, pixelsize,pixelsize, pixelcornerradius) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pg.endDraw();
|
||||||
|
image(pg,5,5);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean getPixelFromString(int x,int y){
|
||||||
|
return lastDataReceived.charAt(x*displayheight+y)=='1';
|
||||||
|
}
|
||||||
|
|
||||||
|
void clientConnected() {
|
||||||
|
println("client connected");
|
||||||
|
|
||||||
|
client.subscribe("testflipdot/display/data/set");
|
||||||
|
}
|
||||||
|
|
||||||
|
void messageReceived(String topic, byte[] payload) {
|
||||||
|
//println("new message: " + topic + " - " + new String(payload));
|
||||||
|
println("new message: " + topic + " len= " + (new String(payload)).length());
|
||||||
|
lastDataReceived=new String(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
void connectionLost() {
|
||||||
|
println("connection lost");
|
||||||
|
}
|
Loading…
Reference in New Issue