Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
scratchbook
scratchbook's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
How to mirror Colortracking
[0 Replies]
20-Jun-2012 11:00 AM
Forum:
Core Library Questions
For a school assignment i need to make a color tracking game with a ball.
A managed to make the color tracking part, but the rectangle is going the wrong way.
How can i mirror the tracking?
Code:
import processing.video.*;
PImage spiegel; // zorgt ervoor dat het beeld wordt gespiegeld
Capture cam;
color trackColor; //tracked eerste color
float x = 10;
float y = 0;
float posx = random (4);
float snl = 5; //snelheid van object
float zwrt = 0.1; //zwaartekracht
// Slaghout
int slaghout_width = 10;
int slaghout_height = 60;
//--SETUP--//
void setup() {
size(1024, 480);
rectMode(RADIUS);
cam = new Capture(this, 512, 480);
spiegel = createImage(512, 480, RGB);
}
//--DRAW--//
void draw () {
colorMode(RGB, 255);
if (cam.available()) {
cam.read();
image(spiegel, 0, 0, width, height); // Draw the webcam video onto the screen
int objx = 0;
int objy = 0;
// for each pixel in the yth row, compute each pixel's index in the video
cam.loadPixels();
int index = 0;
for (int y = 0; y < cam.height; y++) {
for (int x = 0; x < cam.width; x++) {
// Get the color stored in the pixel
int pixelValue = cam.pixels[index];
// Determine the brightness of the pixel
// float pixelB = brightness(pixelValue);
float pixelG = green( pixelValue);
float pixelR = red( pixelValue);
// If that value is brighter than any previous, then store the
// brightness of that pixel, as well as its (x,y) location
if ((pixelG > 120) && (pixelR < 30) ){// && ( pixelHUE < 120)) {
objy = y;
objx = x;
}
index++;
}
}
if (cam.available() == true) {
cam.read();
}
// dit is het spiegeleffect
cam.loadPixels();
for (int i = 0; i <cam.pixels.length; i++) {
spiegel.pixels[i] = cam.pixels[cam.width + (cam.width*(i/cam.width)) - 1 - i%cam.width];
}
background(#C6B182);
spiegel.updatePixels();
image(spiegel, 0, 0);
y = y + snl;
x = x + posx;
snl = snl + zwrt;
if (y > height) {
snl = snl * -0.82;
}
if ((x > width) || (x < 0)) {
posx = posx * -1;
}
if (x >= 555 && x <= 610 && y >= 555 && y <=610) {
posx = posx *-1;
}
fill(1);
stroke(1);
//rect(500,200,55,55);
fill(#ffffff);
noStroke();
ellipseMode(CENTER);
ellipse(x,y,20,20);
// Draw a large, yellow circle at the brightest pixel
fill(255);
rect(objx, objy, slaghout_width, slaghout_height);
}
}
void mouseClicked(){
int c = get(mouseX, mouseY);
println(green(c));
println(red(c));
println(blue(c));
}
«Prev
Next »
Moderate user : scratchbook
Forum