We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Pixelated Mirror w/Trails
Page Index Toggle Pages: 1
Pixelated Mirror w/Trails (Read 727 times)
Pixelated Mirror w/Trails
Mar 2nd, 2007, 1:06am
 
I am playing with the pixelated mirror sketch from http://www.shiffman.net/teaching/workshop/, but have a question about adding 'trails' to the video.

Currently, pixels are being displayed by brightness of the pixel in the video, so brighter spots appear as bigger pixels, which is great, but if a pixel go from bright to dim quickly, the pixel size just shrinks down as quickly as it can in the draw loop.

I would like to add some nifty 'trails' to the video, so if, for example, you wave a bright hand in front of the cam, the pixel sizes would reduce at a slower rate, thus leaving a trail of sorts behind all the motion in the video.

Does that make sense?  Any idea how I could modify the code to achieve something like this?  Code pasted in reply...

Many thanks...
Re: Pixelated Mirror w/Trails
Reply #1 - Mar 2nd, 2007, 1:06am
 
Code:

// Mirror1
// Daniel Shiffman <http://www.shiffman.net>

// Each pixel from the video source is drawn as a
// rectangle with size based on brightness.

// Created 2 May 2005

import processing.video.*;

// Size of each cell in the grid
int cellsize = 15;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;

void setup()
{
size(640, 480);
frameRate(30);
//set up columns and rows
cols = width/cellsize;
rows = height/cellsize;
colorMode(RGB,255,255,255,100);

// Using the default capture device
video = new Capture(this, 640, 480, 15);

background(0);

}

void captureEvent(Capture camera)
{
camera.read();
}

void draw()
{
background(0);

// Begin loop for columns
for ( int i = 0; i < cols;i++) {
// Begin loop for rows
for ( int j = 0; j < rows;j++) {

// Where are we, pixel-wise?
int x = i*cellsize;
int y = j*cellsize;
int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image

// Each rect is colored white with a size determined by brightness
color c = video.pixels[loc];
float sz = (brightness(c)/255.0f)*(cellsize);
//rectMode(CENTER);
ellipseMode(CENTER);
fill(round(brightness(c)));
noStroke();
//rect(x+cellsize/2,y+cellsize/2,sz,sz);
ellipse(x+cellsize,y+cellsize/2,sz,sz);
smooth();
}
}
}
Re: Pixelated Mirror w/Trails
Reply #2 - Mar 2nd, 2007, 12:01pm
 
I am not sure but if you want cells to have some memmory effect you could try calculating the average of current sz and the last sz at that location and showing that sized circle. last size would also be accumulation of it and previous ones..

you would need an array of last values and then you could calculate. With some math you could also set how big the influence of the past is..
Page Index Toggle Pages: 1