Sarah D at ITP

building dancing robots

[ICM] Interactive Painting Midterm: update

without comments

I’ve been playing with the code a bit, trying to create an array that will store the last 20-50 xpos and ypos of the accelerometer, allowing the ellipses to trail across the screen in a more systematic manner. I’ve been unsucessful with the following code:

import processing.serial.*;
Serial myPort;

Paint [] balls = new Paint[50];

void setup(){
size (1000, 600);
background(124,193,245);
smooth();
}

for (int i = 0, i < balls.length, i++){
balls[i] = new Paint(color(i*2), 0, i*2, i/20);
}

println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
}

void draw(){
for (int i = 0, i < balls.length, i++){
balls[i].move();
balls[i]display();
}
}

class Paint {
color c;
float xpos;
float ypos;

void serialEvent(Serial myPort) {
String myString = myPort.readStringUntil('\n');
if (myString != null) {

myString = trim(myString);

int sensors[] = int(split(myString, ','));

for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}

Paint(color c_, float xpos_, float ypos_, float xspeed_){
c = c_;

println();
if (sensors.length > 1) {
xpos = map(sensors[0],300,340,0,width);
ypos = map(sensors[1],300,330,0,height);
}
}

void display(){
noStroke();
fill(c);
ellipse(xpos, ypos, 40, 40);
}

void move()[
xpos = xpos + speed;
if (xpos > width){
xpos = 0;
}

Using my original code, I have been able to improve the visual aesthetic of the sketch.
interactive painting 1

interactive painting 2

interactive painting 3

My Processing code is as follows:
import processing.serial.*;
Serial myPort;

float xpos;
float ypos;

float r=0;
float g=0;
float b=255;

float diameter;

void setup() {
size(1000, 600);
background(124,193,245);

println(Serial.list());

myPort = new Serial(this, Serial.list()[1], 9600);

myPort.bufferUntil(‘\n’);
}

void draw(){
fill(r,g,b,2);
}

void serialEvent(Serial myPort) {
String myString = myPort.readStringUntil(‘\n’);
if (myString != null) {

myString = trim(myString);

int sensors[] = int(split(myString, ‘,’));

for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}

println();
if (sensors.length > 1) {
xpos = map(sensors[0],300,340,0,width);
ypos = map(sensors[1],300,330,0,height);
}

diameter=dist(xpos, ypos, width/2, height/2);
noStroke();
fill(xpos, ypos, diameter, 150);
ellipse(xpos, ypos, 40, 40);
}
}

Written by sarah

November 5th, 2009 at 2:36 am

Posted in ICM, PComp

Tagged with , ,

Leave a Reply