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)
   screen/pixels vs. alpha channels
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: screen/pixels vs. alpha channels  (Read 277 times)
elout

12747371274737 WWW
screen/pixels vs. alpha channels
« on: Jan 25th, 2004, 8:04pm »

I started today to do a 2004 remake of my old 'zab0' applet. This time in processing & the first thing to do was; doing 'my draw the screen onto the screen trick', with a little different offset...
 
And I just noticed, the huge difference between
 
doing;  
my_imagebuffer.pixels=pixels;
 
or;
System.arraycopy(pixels, 0, my_imagebuffer.pixels, 0, width*height);  
 
I guess it has to do somehow with the alpha channels.
Any insight in this one?
 
 
Code:

// zabnulvier v.001 - elout de kok - www.xs4all.nl/~elout/
// compiled in processing v.0067 www.processing.org
//  25 jan 2004
 
BImage my_imagebuffer;
int midx,midy;
int noisefactor=30; // make this bigger --> for more noise fun
 
void setup()
{  
  size(600, 300);
  my_imagebuffer = new BImage(width, height);
  midx=width/2;
  midy=height/2;
}
 
void loop()
{  
  //draw something
  stroke(random(255),random(255),random(255),90);
  fill(random(255),random(255),random(255),90);
  quad(midx-10,0,  midx+10,0, midx+10,height, midx-10,height);  
  quad(0,midy-10,  width,midy-10, width,midy+10, 0,midy+10);  
   
  //now copy the screen to my screenbuffer -- 2 options;
  my_imagebuffer.pixels=pixels;
  //System.arraycopy(pixels, 0, my_imagebuffer.pixels, 0, width*height);  
  // arraycopy -- source,start, destiny,start , size
   
  //my old trick; draw the same screen onto the same screen
  // with a slighty different offset
  image(my_imagebuffer, random(noisefactor)-noisefactor/2,random(noisefactor)-noisefactor/2 );
}

 
my favourites until now;
using  
- my_imagebuffer.pixels=pixels;
and setting noise factor around 100
- int noisefactor=100;
 
online sample..
http://www.xs4all.nl/~elout/proce55ing/zabnulvier/
« Last Edit: Jan 26th, 2004, 2:55am by elout »  
benelek

35160983516098 WWW Email
Re: screen/pixels vs. alpha channels
« Reply #1 on: Jan 27th, 2004, 1:23am »

Hi elout,
 
from a quick look at your code, i don't think it's related to alpha. there's a subtle difference between using the equals sign and using the copy method when using arrays.
 
try the following:
 
Code:
int[] array1 = new int[100];
int[] array2 = new int[200];
 
//System.arraycopy(array2,0,array1,0,array1.length);
//array1=array2;
 
println(array1.length);

 
when you use the equals sign, array1 actually becomes a reference to array2, and therefore has the same length as array2. if you modify array2 afterwards, array1 would automatically feel those changes.
 
however, when you use arraycopy(), array1 simply becomes a copy of array2, with all its values. however, it is still an independant array and is not updated until you do it yourself.
 
with regards to your sketch, because the pixel array of my_imagebuffer is a reference to pixels, when you write to pixels - by using image(my_imagebuffer) - the changes are made immediately to my_imagebuffer so there's a bit more of a feedback loop than you had originally.
 
 
~jacob
 
elout

12747371274737 WWW
Re: screen/pixels vs. alpha channels
« Reply #2 on: Jan 29th, 2004, 5:39pm »

Thanks, I understand now,
If I do; my_imagebuffer.pixels=pixels;
everytime 'pixels' changes;  
the array my_imagebuffer[] will change as well.
 
Anyway I updated my 'zabzero 2004' edition.
http://www.xs4all.nl/~elout/proce55ing/zabnulvier/
 
Best played with some drum&bass in the background,
and will add some extra animations in the near future.
As a VJ I know, if you make the animation faster than the music, the visuals will look like they sync with the music.
 
Pages: 1 

« Previous topic | Next topic »