Ka-POW!!
I created a visualization allows you to be your own superhero! When you punch a balloon a visualization appears in the processing window. Inside the visualization are the words Ka-Pow!!
Materials: analog force sensor, red balloon, paper, markers
Video: http://www.youtube.com/watch?v=xt-Aj8pfngY
Code:
/*
* Arduino Ball Paint
* (Arduino Ball, modified 2011)
* ----------------------
*
* Receives an ASCII number over the serial port,
* terminated with a carriage return (ascii 13) then newline (10).
*
* This matches what Arduino's " Serial.println(val)" function
* puts out.
*
* Created 25 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbserial-A7006yVX"; // or "COM5"
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
void setup() {
size(300,300);
frameRate(10);
smooth();
background(40,40,40);
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
}
void keyPressed() {
if(key == ' ') {
background(40,40,40); // erase screen
}
else {
int x = int(random(0,width));
int y = int(random(0,height));
}
}
// draw Kapow
void kapow(int val){
float i =random(100);
float j =random(50);
stroke(255);
fill(255,i,j);
if (val > 0){
val = int (val/10);
beginShape();
vertex(20*val,10*val);
vertex(60*val,30*val); //1
vertex(80*val,20*val); //2
vertex(60*val,40*val); //3
vertex(90*val,50*val); //4
vertex(70*val,60*val); //5
vertex(90*val,90*val); //6
vertex(60*val,60*val); //7
vertex(50*val,80*val); //8
vertex(40*val,60*val); //9
vertex(20*val,50*val); //11
vertex(40*val,50*val); //12
vertex(10*val,40*val); //13
vertex(40*val,35*val); //14
vertex(20*val,10*val); //14
endShape(CLOSE) ;
fill(255);
// int textsize = int(14*val);
// textSize(textsize);
text("Ka-POW!",45*val,45*val);
}
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
int val = int(buf);
if (val != 0) {
println("val="+val);
}
int x = int((width/2));
int y = int((height/2));
// drawball(x,y,val);
kapow(val);
buf = "";
}
}