Created
November 6, 2009 04:50
-
-
Save sgallese/227718 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.core.*; | |
import processing.video.*; | |
import oscP5.*; | |
import netP5.*; | |
public class PalmReading extends PApplet { | |
Points[] heart; | |
Points[] head; | |
Points[] life; | |
Points[] fate; | |
int totalCurves = 4; | |
Capture video; | |
OscP5 oscP5; | |
NetAddress myRemoteLocation; | |
PImage b; | |
int _brightPointX = 0; | |
int _brightPointY = 0; | |
public void setup(){ | |
size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480 | |
frameRate(3); | |
noFill(); | |
fill(255); | |
/* start oscP5, listening for incoming messages at port 12000 */ | |
oscP5 = new OscP5(this,5555); | |
myRemoteLocation = new NetAddress("128.148.91.46",5555); | |
// Uses the default video input, see the reference if this causes an error | |
video = new Capture(this, width, height, 30); | |
noStroke(); | |
smooth(); | |
b = loadImage("palmcropscale.jpg"); | |
int pointsInCurve = 11; | |
heart = new Points[pointsInCurve]; | |
for (int i = 0; i < heart.length; i++){ | |
heart[i]= new Points(); | |
} | |
head = new Points[pointsInCurve]; | |
for (int i = 0; i < head.length; i++){ | |
head[i]= new Points(); | |
} | |
life = new Points[pointsInCurve]; | |
for (int i = 0; i < life.length; i++){ | |
life[i]= new Points(); | |
} | |
fate = new Points[pointsInCurve]; | |
for (int i = 0; i < fate.length; i++){ | |
fate[i]= new Points(); | |
} | |
int steps = 10; | |
for (int i = 0; i <= steps; i++) { | |
float t = (float)i / steps; | |
float x = bezierPoint(465, 300, 300, 410, t); | |
float y = bezierPoint(20, 300, 300, 470, t); | |
ellipse(x, y, 5, 5); | |
life[i].setX(x); | |
life[i].setY(y); | |
} | |
for (int i = 0; i <= steps; i++) { | |
float t = (float)i / steps; | |
float x = bezierPoint(465, 180, 180, 35, t); | |
float y = bezierPoint(90, 150, 180, 250, t); | |
ellipse(x, y, 5, 5); | |
heart[i].setX(x); | |
heart[i].setY(y); | |
} | |
for (int i = 0; i <= steps; i++) { | |
float t = (float)i / steps; | |
float x = bezierPoint(465, 180, 250, 155, t); | |
float y = bezierPoint(90, 150, 300, 540, t); | |
ellipse(x, y, 5, 5); | |
head[i].setX(x); | |
head[i].setY(y); | |
} | |
for (int i = 0; i <= steps; i++) { | |
float t = (float)i / steps; | |
float x = bezierPoint(330, 300, 210, 420, t); | |
float y = bezierPoint(65, 180, 300, 540, t); | |
ellipse(x, y, 5, 5); | |
fate[i].setX(x); | |
fate[i].setY(y); | |
} | |
} | |
public void draw(){ | |
if (video.available()) { | |
video.read(); | |
image(video, 0, 0, width, height); // Draw the webcam video onto the screen | |
int brightestX = 0; // X-coordinate of the brightest video pixel | |
int brightestY = 0; // Y-coordinate of the brightest video pixel | |
float brightestValue = 0; // Brightness of the brightest video pixel | |
// Search for the brightest pixel: For each row of pixels in the video image and | |
// for each pixel in the yth row, compute each pixel's index in the video | |
video.loadPixels(); | |
int index = 0; | |
for (int y = 0; y < video.height; y++) { | |
for (int x = 0; x < video.width; x++) { | |
// Get the color stored in the pixel | |
int pixelValue = video.pixels[index]; | |
// Determine the brightness of the pixel | |
float pixelBrightness = brightness(pixelValue); | |
// If that value is brighter than any previous, then store the | |
// brightness of that pixel, as well as its (x,y) location | |
if (pixelBrightness > brightestValue) { | |
brightestValue = pixelBrightness; | |
brightestY = y; | |
brightestX = x; | |
_brightPointX = x; | |
_brightPointY = y; | |
} | |
index++; | |
} | |
} | |
// Draw a large, yellow circle at the brightest pixel | |
fill(255, 204, 0, 128); | |
//ellipse(brightestX, brightestY, 200, 200); | |
} | |
tint(255,255,255,230); | |
int closestDistanceLife = 900; | |
for (int i = 0; i < life.length; i++){ | |
int tempDistance = (int)dist(life[i].getX(), life[i].getY(), _brightPointX, _brightPointY); | |
if (closestDistanceLife > tempDistance){ | |
closestDistanceLife = tempDistance; | |
} | |
} | |
closestDistanceLife = 150 - closestDistanceLife; | |
if (closestDistanceLife< 0){ | |
closestDistanceLife = 0; | |
} | |
int closestDistanceHeart = 900; | |
for (int i = 0; i < heart.length; i++){ | |
int tempDistance = (int)dist(heart[i].getX(), heart[i].getY(), _brightPointX, _brightPointY); | |
if (closestDistanceHeart > tempDistance){ | |
closestDistanceHeart = tempDistance; | |
} | |
} | |
closestDistanceHeart = 150 - closestDistanceHeart; | |
if (closestDistanceHeart< 0){ | |
closestDistanceHeart = 0; | |
} | |
int closestDistanceHead = 900; | |
for (int i = 0; i < head.length; i++){ | |
int tempDistance = (int)dist(head[i].getX(), head[i].getY(), _brightPointX, _brightPointY); | |
if (closestDistanceHead > tempDistance){ | |
closestDistanceHead = tempDistance; | |
} | |
} | |
closestDistanceHead = 150 - closestDistanceHead; | |
if (closestDistanceHead< 0){ | |
closestDistanceHead = 0; | |
} | |
int closestDistanceFate = 900; | |
for (int i = 0; i < fate.length; i++){ | |
int tempDistance = (int)dist(fate[i].getX(), fate[i].getY(), _brightPointX, _brightPointY); | |
if (closestDistanceFate > tempDistance){ | |
closestDistanceFate = tempDistance; | |
} | |
} | |
closestDistanceFate = 150 - closestDistanceFate; | |
if (closestDistanceFate< 0){ | |
closestDistanceFate = 0; | |
} | |
image(b, 0, 0); | |
for (int i = 0; i < life.length; i++){ | |
fill(0,255,0); | |
ellipse(life[i].getX(), life[i].getY(), 5, 5); | |
} | |
for (int i = 0; i < heart.length; i++){ | |
fill(255,0,0); | |
ellipse(heart[i].getX(), heart[i].getY(), 5, 5); | |
} | |
for (int i = 0; i < head.length; i++){ | |
fill(0,0,255); | |
ellipse(head[i].getX(), head[i].getY(), 5, 5); | |
} | |
for (int i = 0; i < fate.length; i++){ | |
fill(100,0,255); | |
ellipse(fate[i].getX(), fate[i].getY(), 5, 5); | |
} | |
OscMessage myMessage = new OscMessage( "processing" ); | |
System.out.println("Life: "+closestDistanceLife+", Heart: "+closestDistanceHeart+", Head: "+closestDistanceHead+", Fate: "+closestDistanceFate); | |
myMessage.add(new int[] { 1, closestDistanceLife, 2, closestDistanceHeart, 3, closestDistanceHead, 4, closestDistanceFate}); | |
/* send the message */ | |
oscP5.send(myMessage, myRemoteLocation); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Points { | |
float _x; | |
float _y; | |
public void Points(){ | |
_x = 0; | |
_y = 0; | |
} | |
public float getX() { | |
return _x; | |
} | |
public void setX(float x) { | |
_x = x; | |
} | |
public float getY() { | |
return _y; | |
} | |
public void setY(float y) { | |
_y = y; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment