moving an sliced image with copy(), but first column goes wrong...
in
Programming Questions
•
6 months ago
Hi, I can't figure out why the first column inside screen keeps repeating the first slice of image while picture still entering the screen... I've tried to go backwards in the for() thinking it was a drawing order issue, but no luck... What am I missing?
- int slice_w, SLICES = 40;
- int img_w, img_h;
- PImage img;
- int offset = 0;
- int n =0;
- public void setup() {
- size(1000, 350, P2D);
- frameRate(60);
- while(img == null)
- img = loadImage("http://www.saudek.com/photos/03-15.jpg");
- img_w = img.width;
- img_h = img.height;
- slice_w = img_w/SLICES;
- //println(img_w+"/"+SLICES+" "+slice_w);
- }
- void draw() {
- offset =frameCount;
- for (int i = 0 ; i < SLICES; i++) {
- for (int j = 0 ; j < SLICES; j++) {
- //n=int(random(0, 6));
- int source_x = i * (slice_w) + i;
- int source_y = j * (slice_w) + j ;
- int source_w = slice_w;
- int source_h = slice_w;
- int dest_x = -img_w + offset + source_x ;
- int dest_y = source_y ;
- int dest_w = slice_w;
- int dest_h = source_h;
- copy(img, source_x, source_y, source_w, source_h, dest_x, dest_y, dest_w, dest_h);
- /*
- print("source_x= " + source_x);
- print(" source_y= " + source_y);
- print( " source_w= " + source_w );
- print(" source_h= " + source_h);
- print(" dest_x= " + dest_x);
- print(" dest_y= " + dest_y);
- print(" dest_w= " + dest_w);
- println(" dest_h= " + dest_h);
- */
- }
- }
- }
1