Interactive Mondrian painting
in
Integration and Hardware
•
1 year ago
Hello everybody
I have to project a Mondrian painting on one of the Bauhaus' facades.
I'm using a triple-axis accelerometer to control the rectangles. Mondrian used 4 colors for this painting. What I need is to control each color independantly from the others. What I would like to do is to move one color, put it anywhere I want, and let it on this place. Then, take another color, move it, and let it where it is, and so on... And I want to be able to take a color I've already moved and move it again.
My only problem is I don't know what to say to the squares: "hey guys, stay here!"
Do you know what is the order to tell them?
Thank you
Here is the code I use:
-
import processing.serial.*;import cc.arduino.*;Arduino arduino;
//coordsint cordx;int cordy;int cordz;
//floats_easingfloat x = cordx;float y = cordy;float z = cordz;float targetX, targetY, targetZ;float easing = 0.1;
int active;
void setup(){println(Arduino.list());arduino = new Arduino(this, Arduino.list()[1], 57600);size(1430,820);noStroke();smooth();}
void draw(){
background(0);translate (300,120);
cordx = arduino.analogRead(1);cordy = arduino.analogRead(2);cordz = arduino.analogRead(3);
println("cordx=" +cordx);println("cordy=" +cordy);println("cordz=" +cordz);
targetX = cordx-354;float dx = targetX - x;if(abs(dx)>1) {x+= dx * easing;}targetY = cordy-343;float dy= targetY - y;if(abs(dy) >1) {y += dy * easing;}targetZ = cordz-320;float dz = targetZ - z;if(abs(dz)>1) {z+= dz * easing;}
//white
fill(240);if ( active == 1 ) {rect(10-x,10-y, 38, 93);rect(56-x, 10-y, 293, 24);rect(358-x, 10-y, 338, 24);rect(358-x, 42-y, 119, 61);rect(704-x, 10-y, 42, 262);rect(56-x, 111-y, 88, 236);rect(10-x, 356-y, 38, 152);rect(10-x, 516-y, 177, 44);rect(195-x, 111-y, 112, 161);rect(314-x, 111-y, 35, 161);rect(485-x, 281-y, 160, 66);rect(653-x, 281-y, 43, 66);rect(240-x, 355-y, 193, 118);rect(441-x, 355-y, 133, 118);rect(704-x, 355-y, 86, 118);rect(582-x, 481-y, 208, 79);}else{rect(10,10, 38, 93);rect(56, 10, 293, 24);rect(358, 10, 338, 24);rect(358, 42, 119, 61);rect(704, 10, 42, 262);rect(56, 111, 88, 236);rect(10, 356, 38, 152);rect(10, 516, 177, 44);rect(195, 111, 112, 161);rect(314, 111, 35, 161);rect(485, 281, 160, 66);rect(653, 281, 43, 66);rect(240, 355, 193, 118);rect(441, 355, 133, 118);rect(704, 355, 86, 118);rect(582, 481, 208, 79);}
//bluefill(0, 0, 120);if ( active == 2 ) {rect(56-x*2, 42-y*2, 293, 61);rect(485-x*2, 42-y*2, 211, 61);rect(358-x*2, 281-y*2, 119, 66);rect(582-x*2, 355-y*2, 63, 118);}else {rect (56,42,293,61);rect(485, 42, 211, 61);rect(358, 281, 119, 66);rect(582, 355, 63, 118);}//yellowfill(250, 210, 0);if ( active == 3 ) {rect(195-x*4, 281-0.5*y, 37, 66);rect(195-x*4, 355-0.5*y, 37, 205);rect(358-x*4, 111-0.5*y, 119, 161);rect(653-x*4, 355-0.5*y, 43, 118);rect(754-x*4, 10-0.5*y, 36, 262);}else {rect(754, 10, 36, 262);rect(195, 281, 37, 66);rect(195, 355, 37, 205);rect(358, 111, 119, 161);rect(653, 355, 43, 118);}
//redfill(200, 0, 0);if ( active == 4 ) {rect(240+x, 481+y, 107, 79);rect(240+x, 281+y, 109, 66);rect(56+x, 355+y, 88, 152);rect(485+x, 111+y, 160, 161);rect(653+x, 111+y, 43, 161);}else {rect(240, 481, 107, 79);rect(240, 281, 109, 66);rect(56, 355, 88, 152);rect(485, 111, 160, 161);rect(653, 111, 43, 161);}}
void keyPressed() {if (key == 'w' || key == 'W') {active = active==1?0:1;}if (key == 'b' || key == 'B') {active = active==2?0:2;}if (key == 'y' || key == 'Y') {active = active==3?0:3;}if (key == 'r' || key == 'R') {active = active==4?0:4;}}
1