V&A processing code

import processing.serial.*;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
float ballX;
float ballY;
float speedX;
float speedY;
float noiseCoord;

void setup(){
size( 800, 800 );
background(0,0,0);
ballX = 200;
ballY = 200 ;
speedX=5;
speedY=5;
// I know that the first port in the serial list on my mac
// is Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you’re using.
String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);
}

void draw(){

if ( myPort.available() > 0)
{ // If data is available,
val = myPort.readStringUntil(‘\n’); // read it and store it in val
}
println(val); //print it out in the console
noStroke();
fill(ballX,ballY,80);
ballX = ballX + speedX;
ballY =ballY +speedY;
//ellipse( ballX , ballY, 10 , 10 );
text(int(random(0,9)), ballX,ballY );
//text (random(‘E’,’*’), ballX, ballY);
if( ballY >=800 ){
speedY=random(-4,-10);

}if(ballX>=800){
speedX=random(-2, -8);

}if(ballY<=0){
speedY=random(3,6);

}if(ballX<=0){
speedX=random(5,8);
}
}
void keyPressed(){
//if (key == CODED){
if (keyCode == UP){
speedX= speedX+random(10,20); speedY= speedY+random(10,20);
}
if (keyCode == DOWN){
speedX= speedX+random(-10,-20);
}
if (keyCode == LEFT){
speedY= speedY+random(10,20);
}
if (keyCode == RIGHT){
speedY= speedY+random(-10,-20);
}

}

Advertisements
V&A processing code