We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › scrolling machine
Page Index Toggle Pages: 1
scrolling machine (Read 729 times)
scrolling machine
Nov 14th, 2007, 8:25am
 
Dear Discourse,

I am trying to get an elegant scrolling mechanism going with the pixels[] array. Trouble is there always seems to be one line (the first one) look still. How can this be avoided?
The scrolling action I have is here:

 loadPixels();
 for (int w = 0; w < (width*height); w = w+width ){
   arraycopy(pixels, w, scoot, 0, scoot.length);
   arraycopy(scoot, 0, pixels, max(0,w-1), scoot.length);
 }
 updatePixels();


Thanks, Greg
Re: scrolling machine
Reply #1 - Nov 16th, 2007, 10:07am
 
Hi Greg! I finally found a solution...

The problem is, your first line can't be moved to the left since max(0, w-1) returns 0. At each time step, the very first pixel of each line you want to scroll has to be moved at the end of the line.

This may be more explicit with a schema, but here is the code :

Code:
loadPixels();
for (int w = 0; w < (width*height); w += width ){
// pixels : ABCDEF
arraycopy(pixels, w+1, scoot, 0, scoot.length-1);
// scoot : BCDEF_
scoot[scoot.length-1] = pixels[w];
// scoot : BCDEFA
arraycopy(scoot, 0, pixels, w, scoot.length);
// pixels : BCDEFA
}
updatePixels();
Page Index Toggle Pages: 1