Hi, I'm currently writing a piece of code for visualising slices of a 3d object created from a depth map. The depth map is a 1024*1024 8 bit greyscale BMP file.
The problem I have is that the image() command which writes out the image does not seem to refresh the pixels rather, it waits in until the program has finished looping though all the frames before outputing the image, which contains every frame of animation.
I need it to fresh the screen at exactly 60hz.
regards
Gavin
import processing.opengl.*;
PImage img;
PImage destination;
int[] numbers = new int[25]; // Array of bit masks used to update individual color bit positions.
int h = 1;
void setup() {
frameRate(60);
noLoop();
size(1024, 1024, JAVA2D);
img = loadImage("seat.bmp");
destination = createImage(img.width, img.height, RGB);
numbers[0] = 0;
numbers[1] = 128 ;
numbers[2] = 64 ;
numbers[3] = 32 ; // blue
numbers[4] = 16 ;
numbers[5] = 8 ;
numbers[6] = 4 ;
numbers[7] = 2 ;
numbers[8] = 1 ;
numbers[9] = 8388608 ;
numbers[10] = 4194304 ;
numbers[11] = 2097152 ;
numbers[12] = 1048576 ; // red
numbers[13] = 524288 ;
numbers[14] = 262144 ;
numbers[15] = 131072 ;
numbers[16] = 65536 ;
numbers[17] = 32768 ;
numbers[18] = 16384 ;
numbers[19] = 8192 ;
numbers[20] = 4096 ; // green
numbers[21] = 2048 ;
numbers[22] = 1024 ;
numbers[23] = 512 ;
numbers[24] = 256 ;
}
void draw() {
loadPixels();
// Since we are going to access the image's pixels too
int z = 0;
img.loadPixels();
for (int l = 1;l < 240;l++) {
if (z > 240) {
z = z - 240;
}
h=h+1;
for (int x = 0; x < width; x++) {
int loc = x + z*width;
int bright = round(brightness(img.pixels[loc]));
float multi = 1;
int offset = round(bright * multi);
int lox = x + (240-offset)*width;
// destination.pixels[lox] = color(55,z,66);
destination.pixels[lox] = destination.pixels[lox] | (0x00FFFFFF & numbers[h]);
// output.pixels[i] = output.pixels[i] | (myMovie.pixels[i] & 0x00FFFFFF & numbers[framepos]);
}
if (h == 24) {
destination.updatePixels();
println("hello");
delay(40);
image(destination, 0, 0);
h = 0;
}
z = z + 7;
}
}
The problem I have is that the image() command which writes out the image does not seem to refresh the pixels rather, it waits in until the program has finished looping though all the frames before outputing the image, which contains every frame of animation.
I need it to fresh the screen at exactly 60hz.
regards
Gavin
import processing.opengl.*;
PImage img;
PImage destination;
int[] numbers = new int[25]; // Array of bit masks used to update individual color bit positions.
int h = 1;
void setup() {
frameRate(60);
noLoop();
size(1024, 1024, JAVA2D);
img = loadImage("seat.bmp");
destination = createImage(img.width, img.height, RGB);
numbers[0] = 0;
numbers[1] = 128 ;
numbers[2] = 64 ;
numbers[3] = 32 ; // blue
numbers[4] = 16 ;
numbers[5] = 8 ;
numbers[6] = 4 ;
numbers[7] = 2 ;
numbers[8] = 1 ;
numbers[9] = 8388608 ;
numbers[10] = 4194304 ;
numbers[11] = 2097152 ;
numbers[12] = 1048576 ; // red
numbers[13] = 524288 ;
numbers[14] = 262144 ;
numbers[15] = 131072 ;
numbers[16] = 65536 ;
numbers[17] = 32768 ;
numbers[18] = 16384 ;
numbers[19] = 8192 ;
numbers[20] = 4096 ; // green
numbers[21] = 2048 ;
numbers[22] = 1024 ;
numbers[23] = 512 ;
numbers[24] = 256 ;
}
void draw() {
loadPixels();
// Since we are going to access the image's pixels too
int z = 0;
img.loadPixels();
for (int l = 1;l < 240;l++) {
if (z > 240) {
z = z - 240;
}
h=h+1;
for (int x = 0; x < width; x++) {
int loc = x + z*width;
int bright = round(brightness(img.pixels[loc]));
float multi = 1;
int offset = round(bright * multi);
int lox = x + (240-offset)*width;
// destination.pixels[lox] = color(55,z,66);
destination.pixels[lox] = destination.pixels[lox] | (0x00FFFFFF & numbers[h]);
// output.pixels[i] = output.pixels[i] | (myMovie.pixels[i] & 0x00FFFFFF & numbers[framepos]);
}
if (h == 24) {
destination.updatePixels();
println("hello");
delay(40);
image(destination, 0, 0);
h = 0;
}
z = z + 7;
}
}
1