Star Pixellation on webcam
Hello. I am a processing beginner.
I have made code interacting with webcam and sound.
This code makes webcam image to star pixel but it works too slow.
I used PShape star and createShape();.
I think if I limit the number of star objects appear on webcam, it might be faster,
but I don't know how to.
Is there any other way that I can make star pixel, works fast?
or can you please fix this code for me?
Please show me an example code.
- import processing.video.*;
import krister.Ess.*;
FFT myfft;
AudioInput myinput;
int bufferSize=512;
import processing.video.*; - int n =1;
// Size of each cell in the grid
int cellSize = 10;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;
PShape star; - int status = 0;
int ready = 0;
int count = 0; - void setup() {
size(1920,900, P3D);
// Set up columns and rows
cols = width/2 / cellSize;
rows = height/2 / cellSize;
colorMode(RGB, 255, 255, 255, 70);
ellipseMode(CENTER);
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, 640, 480);
video.start();
frameRate(45);
filter(BLUR,30);
smooth(); - Ess.start(this);
myinput=new AudioInput(bufferSize);
myfft=new FFT(bufferSize*2);
myinput.start(); - myfft.damp(.5);
myfft.equalizer(true);
myfft.limits(.005,.01);
}
void draw() {
float percent= myfft.averages[0];- if (video.available()) {
video.read();
video.loadPixels();
background(0,0,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 + cellSize/2;
int y = j*cellSize + cellSize/2;
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 = ((percent)*5000/ float(width)) * brightness(video.pixels[loc]) + 20.0;
float sy = brightness(video.pixels[loc])+20.0;
pushMatrix();
println("percent : "+percent);
translate(x , y , sz);
fill(c);
noStroke();
star = createShape(); - star.vertex(0, -16);
star.vertex(4, -7);
star.vertex(11, -5);
star.vertex(5, 2);
star.vertex(7, 10);
star.vertex(0, 6);
star.vertex(-7, 10);
star.vertex(-5, 2);
star.vertex(-11, -5);
star.vertex(-4, -7);
star.end(CLOSE);
shape(star);
popMatrix();
}
}
}
}
public void audioInputData(AudioInput theInput) {
myfft.getSpectrum(myinput);
}