working tree with 27 cubes

This commit is contained in:
Philipp Kramer 2019-12-02 17:05:02 +01:00
commit 0a931362ca

136
wuerfelbaum.pde Normal file
View file

@ -0,0 +1,136 @@
import processing.serial.*;
static int FRAMERATE=20;
int fadetime=1000/FRAMERATE /10 *4; //fadetime in centiseconds SMOOOOTH
Serial sPort;
//int boxnum = 1+2+3+4+5+6+7;
int boxnum=50;
color box[] = new color[boxnum];
int boxid[] = new int[boxnum];
int MAXTREEWIDTH=7;
int MAXTREEHEIGHT=7;
int boxiTree[][] = new int[MAXTREEWIDTH][MAXTREEHEIGHT];
color colorTree[][] = new int[MAXTREEWIDTH][MAXTREEHEIGHT];
float testcolorhue=0;
float time=0;
void setup() {
size(200, 200);
frameRate(FRAMERATE);
/*for (int i=0;i<boxnum;i++) {
boxid[i]=i;
box[i] = color(100,255,255);
}*/
/*
28
22
21,15,6
24,10,25,13
5,1,18,19,3
23,9,4,16,17,29
8,12,7,30,27,20,2
*/
int _theight=MAXTREEHEIGHT-1;
boxiTree[0][_theight] = 28; _theight--;
boxiTree[0][_theight] = 22; _theight--;
boxiTree[0][_theight] = 21; boxiTree[1][_theight] = 15; boxiTree[2][_theight] = 6; _theight--;
boxiTree[0][_theight] = 24; boxiTree[1][_theight] = 10; boxiTree[2][_theight] = 25; boxiTree[3][_theight] = 13; _theight--;
boxiTree[0][_theight] = 5; boxiTree[1][_theight] = 1; boxiTree[2][_theight] = 18; boxiTree[3][_theight] = 19; boxiTree[4][_theight] = 3; _theight--;
boxiTree[0][_theight] = 23; boxiTree[1][_theight] = 9; boxiTree[2][_theight] = 4; boxiTree[3][_theight] = 16; boxiTree[4][_theight] = 17; boxiTree[5][_theight] = 29; _theight--;
boxiTree[0][_theight] = 8; boxiTree[1][_theight] = 12; boxiTree[2][_theight] = 7; boxiTree[3][_theight] = 30; boxiTree[4][_theight] = 27; boxiTree[5][_theight] = 20; boxiTree[6][_theight] = 2; _theight--;
String portName = Serial.list()[0];
sPort = new Serial(this, portName, 115200);
colorMode(HSB, 255);
}
void draw() {
testcolorhue+=4;
testcolorhue%=256;
/*
for (int i=0;i<boxnum;i++) {
box[i] = color(int(testcolorhue),255,255);
}*/
//effect_rainbow();
effect_tree();
sendToTree();
}
void effect_rainbow() {
for (int y=0;y<MAXTREEHEIGHT;y++) {
for (int x=0;x<MAXTREEWIDTH;x++) {
colorTree[y][x] = color(int( (testcolorhue+10*(y*MAXTREEWIDTH+x))%256),255,255);
}
}
}
void effect_tree() {
time+=0.1;
float candleflickerscale=80;
colorMode(RGB, 255);
for (int y=0;y<MAXTREEHEIGHT;y++) {
for (int x=0;x<MAXTREEWIDTH;x++) {
colorTree[x][y] = color(15,200,30); //base color green
}
}
colorTree[0][MAXTREEHEIGHT-1]=color(255,210,0);
color candlecolor[] = new color[7];
colorMode(HSB, 255);
for (int i=0;i<candlecolor.length;i++) {
int _h=0,_s=255,_b=255;
_h+=noise(time+i*10)*candleflickerscale-candleflickerscale/2;
if (_h<0) {
_h=256-_h;
}
candlecolor[i] = color(_h%256,_s,_b); //candle
}
int _theight=MAXTREEHEIGHT-3;
colorTree[1][_theight] = candlecolor[0];
_theight--;
colorTree[2][_theight] = candlecolor[1];
_theight--;
colorTree[0][_theight] = candlecolor[2]; colorTree[2][_theight] = candlecolor[3];
_theight--;
colorTree[5][_theight] = candlecolor[4];
_theight--;
colorTree[2][_theight] = candlecolor[5]; colorTree[5][_theight] = candlecolor[6];
}
void sendToWuerfels() {
for (int i=0;i<boxnum;i++) {
//print(str(i)+"="+str(brightness(box[i]))+", ");
sPort.write("B,"+str(boxid[i])+","+str(fadetime)+","+int(red(box[i]))+","+int(green(box[i]))+","+int(blue(box[i]))+"\n");
print("B,"+str(boxid[i])+","+str(fadetime)+","+int(red(box[i]))+","+int(green(box[i]))+","+int(blue(box[i]))+"\n");
}
println();
}
void sendToTree() {
for (int y=0;y<MAXTREEHEIGHT;y++) {
for (int x=0;x<MAXTREEWIDTH;x++) {
//print(str(i)+"="+str(brightness(box[i]))+", ");
sPort.write("B,"+str(boxiTree[x][y])+","+str(fadetime)+","+int(red(colorTree[x][y]))+","+int(green(colorTree[x][y]))+","+int(blue(colorTree[x][y]))+"\n");
//print("B,"+str(boxiTree[x][y])+","+str(fadetime)+","+int(red(colorTree[x][y]))+","+int(green(colorTree[x][y]))+","+int(blue(colorTree[x][y]))+"\n");
}
}
println();
}