/** * Simple Read * * Read data from the serial port and change the color of a rectangle * when a switch connected to a Wiring or Arduino board is pressed and released. * This example works with the Wiring / Arduino program that follows below. */ import processing.serial.*; // SERIAL Serial myPort; // Create object from Serial class int val; // Data received from the serial port int val_max; // Approximate range of sensor readings int val_mapped; // map sensor values from 1-9 int p; // rounded value // BUTTONS CircleButton circles_fill_button, circles_explode_button; // buttons for filled and exploded circles visualization RectButton lines_button; // button for lines visualization boolean locked = false; color currentcolor; // GRID int partsX = 20; // subdivisions of X axis int partsY = 20; //subdivisions of Y axis int partsX_half = partsX/2; // subdivisions in exploded circles visualization int partsY_half = partsY/2; // subdivisions in exploded circles visualization int parts = 10; // subdivisions in exploded circles visualization float step = TWO_PI /parts; // how much circles are exploded // ARRAYS OF RANDOM DEFORMATION PARAMETERS FOR EACH SPOT IN THE GRID // VISUALIZATION 1: LINES int[][] randomArrayY; int[][] randomArrayX; int[][] randomArrayClamp; // VISUALIZATION 2: FILLED CIRCLES int[][] randomArray; int[][] randomArrayAlpha; int[][] randomArrayTone; // VISUALIZATION 3: EXPLODED CIRCLES int[][] randomArrayA; //angle variances int[][] randomArrayR1; //radius 1 variances int[][] randomArrayR2; //radius 2 variances int[][] randomArrayCircle2A; //angle variances int[][] randomArrayCircle2R1; //radius 1 variances int[][] randomArrayCircle2R2; //radius 2 variances //SETUP void setup() { background(255,255,255); size(500, 500); noFill(); // String portName = Serial.list()[0]; // myPort = new Serial(this, portName, 9600); color buttoncolor = color(40,40,40); color highlight = color(255,0,0); lines_button = new RectButton(210, 470, 20, buttoncolor, highlight); buttoncolor = color(60,60,60); highlight = color(255,50,50); stroke(0); circles_fill_button = new CircleButton(250, 480, 20, buttoncolor, highlight); buttoncolor = color(80,80,80); highlight = color(255,100,100); stroke(0); circles_explode_button = new CircleButton(280, 480, 20, buttoncolor, highlight); } /**********************/ /*********DRAW*********/ /**********************/ void draw() { //if ( myPort.available() > 0) // If data is available, // { // val = myPort.read(); // read it and store it in val // val_mapped = map(val, 0, val_max, 0, 9); // map values from 0 to 9 // p = round(val_mapped); // round value to an integer from 0-9 p=2; update(mouseX, mouseY); lines_button.display(); circles_fill_button.display(); circles_explode_button.display(); // } delay(200); } void update(int x, int y) { if(locked == false) { lines_button.update(); circles_fill_button.update(); circles_explode_button.update(); } else { locked = false; } // if(mousePressed) // { if(lines_button.over()) { setup_lines(); draw_lines(p); } else if(circles_fill_button.over()) { setup_circlesFill(); draw_circlesFill(p); } else if( circles_explode_button.over()) { setup_circlesExplode(); draw_circlesExplode(p); // } } } /**********************/ /***DIFFERENT SETUPS***/ /**********************/ //Button 1 and 2: lines or points void setup_lines() { randomArrayX = new int[partsX][partsY]; // initiate array of x values randomArrayY = new int[partsX][partsY]; // initiate array of y values randomArrayClamp = new int[partsX][partsY]; // initiate array of values that define if the grid will be deformed for (int i=0;i= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } boolean overCircle(int x, int y, int diameter) { float disX = x - mouseX; float disY = y - mouseY; if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) { return true; } else { return false; } } } class CircleButton extends Button { CircleButton(int ix, int iy, int isize, color icolor, color ihighlight) { x = ix; y = iy; size = isize; basecolor = icolor; highlightcolor = ihighlight; currentcolor = basecolor; } boolean over() { if( overCircle(x, y, size) ) { over = true; return true; } else { over = false; return false; } } void display() { stroke(255); fill(currentcolor); ellipse(x, y, size, size); } } class RectButton extends Button { RectButton(int ix, int iy, int isize, color icolor, color ihighlight) { x = ix; y = iy; size = isize; basecolor = icolor; highlightcolor = ihighlight; currentcolor = basecolor; } boolean over() { if( overRect(x, y, size, size) ) { over = true; return true; } else { over = false; return false; } } void display() { stroke(255); fill(currentcolor); rect(x, y, size, size); } }