Any way to speed up this simple script?
in
Contributed Library Questions
•
1 year ago
Hello! I'm pretty much a processing beginner but I've been working on this script that reads the pixels of a video file and draws a rectangle of the same color at a z height dependent on the pixel's brightness value. 2 questions for you processing masters out there: 1.) when drawing rectangles 1x1 pixels it skips frames and gets heavy. How can I make this script more efficient so as not to be so jerky. and 2.) the higher the size of the rectangle being drawn for each pixel, the more the frame of the video file is cut off. How can I rectify this so that I see the whole frame of the video no matter the size of the rectangle (named 'blocksize' in the script). The code has contributed libraries PeasyCam and GSVideo. Thank you in advance!!
- import peasy.*;
- import codeanticode.gsvideo.*;
- PeasyCam cam;
- int numPixels;
- int blockSize = 1;
- GSMovie myMovie;
- color myMovieColors[];
- void setup() {
- size(800, 600, P3D);
- frameRate(60);
- noStroke();
- rectMode(CENTER);
- background(0);
- myMovie = new GSMovie(this, "facade masked.mov"); // change movie file name here!!
- myMovie.loop();
- numPixels = width / blockSize;
- myMovieColors = new color[numPixels * numPixels];
- cam = new PeasyCam(this,width/2,height/2,0,1000);
- }
- // Read new values from movie
- void movieEvent(GSMovie m) {
- m.read();
- m.loadPixels();
- for (int j = 0; j < numPixels; j++) {
- for (int i = 0; i < numPixels; i++) {
- myMovieColors[j*numPixels + i] = m.get(i, j);
- }
- }
- }
- // Display values from movie
- void draw() {
- background(0);
- for (int j = 0; j < numPixels; j++) {
- for (int i = 0; i < numPixels; i++) {
- pushMatrix();
- float z = brightness(myMovieColors[j*numPixels + i]);
- translate(i,j,z);
- fill(myMovieColors[j*numPixels + i]);
- if ( brightness(myMovieColors[j*numPixels + i]) < 220) {
- rect(i, j, blockSize, blockSize);
- }
- popMatrix();
- }
- }
- //saveFrame("facade-####.tif");
- }
1