Spaz Cat

Submitted by jmscott212 on Wed, 02/27/2013 - 01:38

Description

For this assignment, I imported an image of a cat I photoshopped into the Processing program, and then created an animated sequence of fast movement.  I then merged the ball code into the image animation code, making it seem in an abstract sense that the cat was chasing the ball.  As the program dictates, the ball increases or decreases in size based on the pressure placed on the FSR.  I also changed the color of the ball as well as the background (reset) to blue.  The FSR is also connected to an LED light.  

 

Components

1 Arduino-Uno

2 Resistors

1 LED light

1 Force Sensing Resistor (FSR)

Wires and USB cable

Software: Processing

 

Processing Code

// Declaring a variable of type PImage
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbmodem1411"; // or "COM5"
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
PImage img;  
void setup() {
   // Make a new instance of a PImage by loading an image file
  img = loadImage("cat1.jpg");
   size(500,500);
  frameRate(50);
  smooth();
  background(40,40,40);
  noStroke();
  port = new Serial(this, portname, 9600);
  size(1200,1200);
}
void draw() {
}
void keyPressed() {
  if(key == ' ') {
  }
  else {
    int x = int(random(0,width));
    int y = int(random(0,height));
    drawball(x,y, 90);
  }
}
// draw balls
void drawball(int x, int y, int r) {
  for (int i=0; i<100; i++ ) {
    fill(220-i,i,100);
    ellipse(x,y,r,r);
  }

}
// 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);
    println("val="+val);
    int x = int(random(0,width));
    int y = int(random(0,height));
    drawball(x,y,val);
    buf = "";
image(img,-700,100); image(img,700,300);image(img,-1000,0);
 image(img,-600,400);image(img,600,200);image(img,600,200);
 image(img,300,700); image(img,-300,500); image(img,-200,600);
 image(img,-400,600); image(img,400,400); image(img,-700,100);
  image(img,-1000,0);image(img,1000,-200);image(img,-200,600);
  image(img,900,100);image(img,-900,-100);image(img,600,200);
  image(img,-800,200);  image(img,800,0);image(img,-300,500);
       background(0,750,400);
  image(img,700,300);image(img,-700,100);image(img,1000,-200);
  image(img,-600,400);image(img,600,200);image(img,600,200);
  image(img,500,500);image(img,-500,300);image(img,-900,-100);
  image(img,-400,600); image(img,400,400); image(img,-700,100);
  image(img,300,700); image(img,-300,500); image(img,-200,600);
  image(img,-200,600); image(img,-200,600); image(img,-400,600);
  image(img,-300,500); image(img,-200,600); image(img,-1000,0);
  image(img,400,400); image(img,-400,600); image(img,-600,400);
  image(img,-500,300); image(img,500,500);image(img,-800,200);
  image(img,600,200); image(img,-600,400); image(img,-400,600);
  image(img,-700,100); image(img,700,300);image(img,-1000,0);
  image(img,800,0); image(img,-800,200); image(img,-600,400);
  image(img,-900,-100);image(img,900,100);image(img,300,700);
  image(img,1000,-200);image(img,-1000,0);image(img,300,700);
   
 
    
  }
  }


 

0
Your rating: None
Drupal theme by Kiwi Themes.