We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
i found a code i'm working on and it basically draws a trail of one's movement (cam). I've been trying to change something but i wasn't able to do it on my own. What i want is the dots to fade in but also to fade out after a certain amount of time. (Let's say 2minutes)
I'd be grateful if anyone could help me with that. Here's the original code: (Works in Processing 1.5.1)
import processing.video.*;
Capture video;
int numPixels;
int[] previousFrame;
int[][] diffPoints;
int diffAmount = 0;
int particleMin = 2;
int particleAlpha = 100;
void setup()
{
size(640, 480);
background (255);
noStroke();
frameRate(30);
fill(100);
smooth();
video = new Capture(this, width, height, 30);
numPixels = width * height;
previousFrame = new int[numPixels];
diffPoints = new int[height][width];
}
void captureEvent(Capture video) {
video.read();
}
void draw()
{
diffAmount = 0;
for (int i = 0; i < numPixels; i++)
{
diffPoints[abs(i / width)][i % width] = 0;
color currColor = video.pixels[i];
color prevColor = previousFrame[i];
// Extract the red, green, and blue components from current pixel
int currR = (currColor >> 16) & 0xFF; // Like red(), but faster
int currG = (currColor >> 8) & 0xFF;
int currB = currColor & 0xFF;
// Extract red, green, and blue components from previous pixel
int prevR = (prevColor >> 16) & 0xFF;
int prevG = (prevColor >> 8) & 0xFF;
int prevB = prevColor & 0xFF;
// Compute the difference of the red, green, and blue values
int diffR = abs(currR - prevR);
int diffG = abs(currG - prevG);
int diffB = abs(currB - prevB);
// Render the difference image to the screen
color diff = color(diffR, diffG, diffB);
int isPointDiff = 0;
if (diff > -15000000) //-16777216
{
isPointDiff = 1;
++diffAmount;
}
diffPoints[abs(i / width)][i % width] = isPointDiff;
}
checkForNewPoint(diffAmount);
arraycopy(video.pixels, previousFrame);
}
void checkForNewPoint(int diffAmount)
{
if(diffAmount > 100000)
{
return;
}
float milliseconds = millis();
if (milliseconds < 1000) return;
if (diffAmount < 40) return;
int blocks = 0;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if(i > 1 && j > 1 && diffPoints[i][j] == 1)
{
if(diffPoints[i - 1][j] == 1 && diffPoints[i - 2][j] == 1
|| diffPoints[i][j - 1] == 1 && diffPoints[i][j - 2] == 1)
{
++blocks;
int randNum = 10;
int randX = int((randNum / 2) - random(randNum));
int randY = int((randNum / 2) - random(randNum));
color c = previousFrame[(i * width) + j];
fill(c, particleAlpha);
int particleSize = diffAmount / 700;
if(random(particleSize) > (particleSize - (.9999999 / particleSize)))
{
ellipse(j, i, particleMin + particleSize, particleMin + particleSize);
}
}
}
}
}
}
void mousePressed() {
fill(255);
rect(0, 0, width, height);
}