Hope this helps a little bit more here is my code;
Code:
// Reference appropriate
import processing.video.*;
PImage black, white, blue, green, pink, dark, light, lighter, people, street2, streetcar2, crowd, lightcrowd, car; //define all the colour variable names we're to use here
Capture video;
int sx, sy;
int cellsizeX,cellsizeY;
float density;
int[][][] world;
// define temp variables for image co-ordinates
int tempX,tempY;
void setup()
{
frameRate (1);
size(1440, 990);
//println(width + ", " + height);
cellsizeY = 28;
cellsizeX = 33;
density = 0.5;
sx = width/cellsizeX;
sy = height/cellsizeY;
world = new int[sx][sy][2];
video = new Capture(this, width, height, 30);
noStroke();
smooth();
// preload images
black = loadImage("black.jpg");
white = loadImage("white.jpg");
blue = loadImage("blue.jpg");
green = loadImage("green.jpg");
pink = loadImage("pink.jpg");
dark = loadImage("darksmall.jpg");
light = loadImage("light.jpg");
lighter = loadImage("lighter.jpg");
people = loadImage("people.jpg");
street2 = loadImage("street2.jpg");
streetcar2 = loadImage("streetcar2.jpg");
crowd = loadImage("crowd.gif");
lightcrowd = loadImage("lightcrowd.jpg");
car = loadImage("car.jpg");
}
void draw()
{
imageMode(CENTER);
video.read();
image(video, 0, 0, width, height); // Draw webcam feed to screen
video.loadPixels(); // Load pixels
int index = 0; // Index defines which pixel is referred to (sequentially, rather than with an x and y value)
background(0);
for (int x = 1; x <= width; x +=cellsizeX)
{
for (int y = 1; y <= height; y +=cellsizeY)
{
index = (((y+1)*width)-x); // Convert x and y values of the pixel in focus to the sequential format of 'index'
color pixelValue = video.pixels[index]; // Retrieve colour value of current pixel
int colour = int(abs(red(pixelValue)-0)+abs(green(pixelValue)-255)+abs(blue(pixelValue)-0)); // Convert the colour value to something I understand, in the range 0.0 (white) to 510.0 (black)... I think
int loc = (video.width + x + 1) - y*video.width; //trying to Reversing x to mirror the image
// what co-ordinates are we using? variables defined in case we need to mess with them.
tempX = x;
tempY = y;
// map colour to a smaller scale
colour = int(map(colour,255,500,0,100));
println(colour); // Output colour value to the console
switch (colour) { // check using switch - it's faster!
case 0: // the blackests of the blacks.
case 1:
case 2:
case 3:
case 4:
image(dark,tempX,tempY);
break;
case 5: // the blackests of the blacks.
case 6:
case 7:
case 8:
case 9:
image(dark,tempX,tempY);
break;
// etc for more cases.
}
}
}
}
and
Code:
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int sensorPin = 0;
int sensorValue;
void setup() {
// size(470, 280);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 115200);
arduino.pinMode(sensorValue, Arduino.INPUT);
}
void draw() {
sensorValue = arduino.analogRead(sensorPin);
//map sensor value, smaller scale
sensorValue = int(map(sensorValue,0,500,0,25)); //short-range sensor
println(sensorValue);
delay(1000);
}