Hello,
I would like to track different location from my screen.
The aim is to send this r, g, b data to an Arduino and modulate 8 strip Led with 8 led.
In my example I have 3 ellipse, I would like to track the center of them.
I manage to track 3 location, but I would like mixing pixel with just a gray layer because im my program I don’t know what I’m really doing
Thanks for helping!
/**
* Mixture Grid
* modified from an example by Simon Greenwold.
*
* Display a 2D grid of boxes with three different kinds of lights.
*/
float count = 0;
color ligne = color(204, 153, 0);// not used
int colAve = color(12);
int col2Ave = color(12);
int col3Ave = color(12);
void setup() {
size(640, 360, P3D);
colorMode (RGB, 255, 255, 255);
noStroke();
frameRate(10);
}
void draw() {
count+=0.05;
defineLights();
background(0);
for (int x = 0; x <= width; x += 60) {
for (int y = 0; y <= height; y += 60) {
pushMatrix();
translate(x, y);
// stroke (count%=255);
// fill (75, 50, 100);
/*
rotateY(map(mouseX, 0, width, 0, PI));
rotateX(map(mouseY, 0, height, 0, PI));
*/
//rotateX(map(140, 0, width, 0, PI));
// rotateY(map(140, 0, height, 0, PI));
rotateY(map(180*cos(count)+height/2, 0, height, 0, PI));
rotateX(map(180*cos(count)+width/2, 0, width, 0, PI));
box(90);
popMatrix();
}
}
loadPixels();
int sqW = 20;
int xMin = mouseX - sqW;
int xMax = mouseX + sqW;
int yMin = mouseY - sqW;
int yMax = mouseY + sqW;
int redAve = 0;
int greenAve = 0;
int blueAve = 0;
int redAve2 = 0;
int greenAve2 = 0;
int blueAve2 = 0;
int redAve3 = 0;
int greenAve3 = 0;
int blueAve3 = 0;
for (int x = xMin; x < xMax; x++)
{
// Loop through every pixel row
for (int y = yMin; y < yMax; y++)
{
// Use the formula to find the 1D location
int loc = x + y * width; //why this formula?
if (loc>0 && loc<pixels.length)
{
if((x-mouseX)*(x-mouseX) + (y-mouseY)*(y-mouseY) < sqW*sqW)
{
//print(hex(pixels[loc]), " ");
//count++;
// redAve += red(pixels[loc]);
greenAve += green(pixels[loc]);
// blueAve += blue(pixels[loc]);
colAve =int (int (redAve/1) | (greenAve) | (blueAve));
// println(hex(redAve), hex(greenAve), hex(blueAve));
if (frameCount%1==0){
println ( " pixel " + get(mouseX, mouseY) + " ");
println ( " pix60 " + get(mouseX + 60, mouseY) + " ");
println ( " ave00 " +(redAve) ,(greenAve), (blueAve));
}
set(x, y, (int) (colAve));
println( " col0 " + colAve);
}
}
// Use the formula to find the 1D location
int loc2 = x+60 + y * width; //why this formula?
if (loc2>0 && loc2<pixels.length+ 60)
{
if((x-mouseX)*(x-mouseX) + (y-mouseY)*(y-mouseY) < sqW*sqW)
{
redAve2 += red(pixels[loc2]);
// greenAve2 += green(pixels[loc2]);
// blueAve2 += blue(pixels[loc2]);
col2Ave = redAve2 | (greenAve2) | (blueAve2);
// println(hex(redAve), hex(greenAve), hex(blueAve));
if (frameCount%1==0)
{
println ( " pixe2 " + get(mouseX, mouseY) + " ");
println ( " pix62 " + get(mouseX + 60, mouseY) + " ");
println ( " ave22 " +(redAve2) ,(greenAve2), (blueAve2));
}
set(x+60, y, col2Ave);
println ( " col2 " + col2Ave);
}
}
int loc3 = x+120 + y * width; //why this formula?
if (loc3>0 && loc3<pixels.length+ 120)
{
if((x-mouseX)*(x-mouseX) + (y-mouseY)*(y-mouseY) < sqW*sqW)
{
// redAve3 += red(pixels[loc3]);
// greenAve2 += green(pixels[loc3]);
blueAve3 += blue(pixels[loc3]);
col3Ave = redAve3 | (greenAve3) | (blueAve3);
// println(hex(redAve), hex(greenAve), hex(blueAve));
if (frameCount%1==0)
{
println ( " pixe3 " + get(mouseX, mouseY) + " ");
println ( " pix33 " + get(mouseX + 60, mouseY) + " ");
println ( " ave33 " +(redAve3) ,(greenAve3), (blueAve3));
}
set(x+120, y, col3Ave);
println ( " col3 " + col3Ave);
}
}
}
}
}
void defineLights() {
// Orange point light on the right
pointLight(150, 100, 0, // Color
200, -150, 0); // Position
// Blue directional light from the left
directionalLight(0, 102, 255, // Color
1, 0, 0); // The x-, y-, z-axis direction
// Yellow spotlight from the front
spotLight(255, 255, 109, // Color
0, 40, 200, // Position
0, -0.5, -0.5, // Direction
PI / 2, 2); // Angle, concentration
}