Kevin Wong's profile

Paradise Painter

Processing Code
/**
 * Data from multiple sensors / Processing
 * by BARRAGAN <http://barraganstudio.com>
 * based on Tom Igoe's example from Making Things Talk book
 *
 * read serial data until a linefeed character is found
 * data are values comma separated. Split the data and convert it
 * into numbers in an array for firther use.
 */
import processing.serial.*;
Serial myPort;
int linefeed = 10;   // Linefeed in ASCII
int numSensors = 3;  // we will be expecting for reading data from four sensors
int sensors[];       // array to read the 4 values
int pSensors[];      // array to store the previuos reading, usefur for comparing
// actual reading with the last one

//Timer variables
Timer timer;
//Pictures variables
PImage[] Pictures = new PImage[6];
int px;
int py;
int pn = 1;
int ssx, ssy, ssz;
float re, ge, be;
 
void setup() {
  size(1366, 768);
  background(255);
  // List all the available serial ports in the output pane.
  // You will need to choose the port that the Wiring board is
  // connected to from this list. The first port in the list is
  // port #0 and the third port in the list is port #2.
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  // read bytes into a buffer until you get a linefeed (ASCII 10):
  myPort.bufferUntil(linefeed);
  timer = new Timer(2000);
  timer.start();

  for (int i = 1; i < Pictures.length; i++) { //putting pictures into array
    Pictures [i] = loadImage(i + ".JPG");
    Pictures [i].resize(width, height);
  }
  px = width/2;
  py = height/2;
}// end setup
void draw() {
  if (timer.isFinished()) { //runs slideshow
    pn++;
    timer.start();
    //following if function creates loop at the beginning or end of the set.
    if (pn == 5) { //if function to allow loop back to case 0 of the case set
      pn = 1;
    }
    
  }
    //Controls
  ssx = sensors[0];
  ssy = sensors[1];
  ssz = sensors[2];
  if (ssz > 325) {
    py = py-1;
  }
  else if (ssz < 325) {
    py = py+1;
  }
  if (ssx < 335) {
    px = px-1;
  }  
  else if (ssx > 335) {
    px = px+1;
  }
  //Pointilism function
  int loc = ssx +ssy*Pictures[pn].width;
  loadPixels();
  float r = red(Pictures[pn].pixels[loc]);
  float g = green(Pictures[pn].pixels[loc]);
  float b = blue(Pictures[pn].pixels[loc]);
  re= r;
  ge=g;
  be=b;
}// end draw
void serialEvent(Serial myPort) {
  // read the serial buffer:
  String myString = myPort.readStringUntil(linefeed);
  // if you got any bytes other than the linefeed:
  if (myString != null) {
    myString = trim(myString);
    // split the string at the commas
    // and convert the sections into integers:
    pSensors = sensors;
    sensors = int(split(myString, ','));
  }
 
  fill(re, ge, be, 255);
  noStroke();
  ellipse(px, py, 20, 20);
}
 
 
void keyPressed() {  //Used to find the accelerometer values
  if (keyCode == UP) {
    // print out the values you got:
    for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
      print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
    } 
    // add a linefeed after all the sensor values are printed:
    println();
  }
}
 
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 10-5: Object-oriented timer
class Timer {
 
  int savedTime; // When Timer started
  int totalTime; // How long Timer should last
  
  Timer(int tempTotalTime) {
    totalTime = tempTotalTime;
  }
  
  // Starting the timer
  void start() {
    // When the timer starts it stores the current time in milliseconds.
    savedTime = millis(); 
  }
  
  // The function isFinished() returns true if 5,000 ms have passed. 
  // The work of the timer is farmed out to this method.
  boolean isFinished() { 
    // Check how much time has passed
    int passedTime = millis()- savedTime;
    if (passedTime > totalTime) {
      return true;
    } else {
      return false;
    }
  }
}
Arduino Code
/*
 ADXL3xx
 
 Reads an Analog Devices ADXL3xx accelerometer and communicates the
 acceleration to the computer.  The pins used are designed to be easily
 compatible with the breakout boards from Sparkfun, available from:
 http://www.sparkfun.com/commerce/categories.php?c=80
 
 http://www.arduino.cc/en/Tutorial/ADXL3xx
 
 The circuit:
 analog 0: accelerometer self test
 analog 1: z-axis
 analog 2: y-axis
 analog 3: x-axis
 analog 4: ground
 analog 5: vcc
 
 created 2 Jul 2008
 by David A. Mellis
 modified 30 Aug 2011
 by Tom Igoe 
 
 This example code is in the public domain.
 
 */
// these constants describe the pins. They won't change:
const int groundpin = 18;             // analog input pin 4 -- ground
const int powerpin = 19;              // analog input pin 5 -- voltage
const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis (only on 3-axis models)
void setup()
{
  // initialize the serial communications:
  Serial.begin(9600);
  // Provide ground and power by using the analog inputs as normal
  // digital pins.  This makes it possible to directly connect the
  // breakout board to the Arduino.  If you use the normal 5V and
  // GND pins on the Arduino, you can remove these lines.
  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW); 
  digitalWrite(powerpin, HIGH);
}
void loop()
{
  // print the sensor values:
  Serial.print(analogRead(xpin));
  // print a tab between values:
  Serial.print("\t");
  Serial.print(analogRead(ypin));
  // print a tab between values:
  Serial.print("\t");
  Serial.print(analogRead(zpin));
  Serial.println();
  // delay before next reading:
  delay(100);
}
Paradise Painter
Published:

Paradise Painter

Paradise Painter is a buildup of a previous project Black Haze and its theme Little Paradise. In Paradise Painter, I take the images from Black a Read More

Published: