FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Simple pixel buffer problem
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Simple pixel buffer problem  (Read 346 times)
Dan

WWW
Simple pixel buffer problem
« on: Jan 27th, 2003, 3:17pm »

Ok, I'm creating a class called "environment" that's going to be a pixel buffer for use within some other experiments.  As you'll see from the code below it's not got very far, but for some reason p5 won't even run the program - with no errors!?
 
I'm sure it's something stupid...
 
 
Code:
//===============================================================
//   Pixel Buffer Test
//   by Daniel Pupius (http://pupius.co.uk)
//
//   Created: 27 January 2003
//   Revised: Never
//===============================================================
 
//constants
int WIDTH = 300;
int HEIGHT = 300;
 
//global variables
environment env = new environment(0, 50, 0);;
 
 
//===============================================================
void setup() {
  size(WIDTH, HEIGHT);
  colorMode(RGB,100);
  background(100);
}
void loop() {
  env.paint();
}
 
 
//===============================================================
class environment {
  int[][] pixel_buffer = new int[WIDTH][HEIGHT];
 
  environment(int r,int g,int b) {
    //set base colour of all pixels
    for(int i=0;i<WIDTH;i++) for(int j=0;j<HEIGHT;j++) this.pixel_buffer[i][j] = color(r,g,b);
  }
 
  void paint() {
    //Loop through all pixels and set windows' colours
    for(int x=0;x<WIDTH;x++) for(int y=0;y<WIDTH;y++) pixels[x+y*WIDTH] = this.pixel_buffer[x][y];
  }
 
}
 
 
//===============================================================
 
REAS


WWW
Re: Simple pixel buffer problem
« Reply #1 on: Jan 27th, 2003, 9:03pm »

I think it's a problem with Proce55ing. I couldn't track it down precisely, but this works as a starting point for continuing your program:
 
Code:

//===============================================================  
//   Pixel Buffer Test  
//   by Daniel Pupius (http://pupius.co.uk)  
//  
//   Created: 27 January 2003  
//   Revised: Never  
//===============================================================  
 
//global variables  
Environment env;  
 
//===============================================================  
 
void setup()  
{  
  size(300, 300);  
  colorMode(RGB,100);  
  background(100);  
  env = new Environment(255, 204, 102, width, height);  
}  
 
void loop()  
{  
  env.paint();  
}  
 
 
//===============================================================  
class Environment  
{  
  int[][] pixel_buffer; //= new int[width][height];  
  int ewidth, eheight;
 
  Environment(int r, int g, int b, int w, int h) {
    ewidth = w;
    eheight = h;
    pixel_buffer = new int[ewidth][eheight];  
    //set base colour of all pixels  
    for(int i=0; i<ewidth; i++) {
 for(int j=0; j<eheight; j++) {
   //pixel_buffer[i][j] = color(r,g,b);
   pixel_buffer[i][j] = r << 16 | g << 8 | b & 0xFF;
 }
    }  
  }  
 
  void paint() {  
    //Loop through all pixels and set windows' colours
    for(int x=0; x<ewidth; x++) {
 for(int y=0; y<eheight; y++) {
   pixels[x+y*ewidth] = pixel_buffer[x][y];
 }
    }  
  }  
 
}  
 
fry


WWW
Re: Simple pixel buffer problem
« Reply #2 on: Jan 27th, 2003, 9:32pm »

i think it's the same compiler bug that won't let you use any p5-specific functions in the constructor of another class. this one is really getting to be a problem, it would seem.
 
Dan

WWW
Re: Simple pixel buffer problem
« Reply #3 on: Jan 28th, 2003, 7:47pm »

Thanks guys, that seems to have fixed it.  Now on with the experimentation!
 
Pages: 1 

« Previous topic | Next topic »