/* built with Studio Sketchpad: * https://sketchpad.cc * * observe the evolution of this sketch: * https://studio.sketchpad.cc/sp/pad/view/ro.UknqpSuvGiq/rev.70 * * authors: * GoToLoop * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * https://creativecommons.org/licenses/by-sa/3.0/ */ /** * Sliced Image (v3.04) * by MatzeWagner (2013/Oct) * mod GoToLoop * * forum.processing.org/two/discussion/586/slicing-image-to-array * studio.processingtogether.com/sp/pad/export/ro.9$MTikWt80-9w/latest */ /* @pjs pauseOnBlur = "true"; preload = "/static/uploaded_resources/p.6273/searichter.jpg"; */ final static int FPS = 30, FREQ = 2*FPS; final static int GRID = 10, NUM = GRID*GRID; final PImage[] pieces = new PImage[NUM]; PImage bg; int jigX, jigY; boolean isShuffling = true; final static String HOST = "http:/" + "/3.bp.blogspot.com"; //final static String PATH = "/-fGkhXK9efpM/TmaRMG2mQpI/AAAAAAAAB5w/zEjlbty8zGM/s1600/"; final static String PATH = "/static/uploaded_resources/p.6273/"; final static String NAME = "searichter.jpg"; void setup() { size(806, 809); frameRate(FPS); //final PImage img = loadImage(HOST + PATH + NAME); final PImage img = loadImage(PATH + NAME); //final PImage img = loadImage(NAME); jigX = img.width/GRID >> 0; // >> 0 forces integer division for JS! jigY = img.height/GRID | 0; // | 0 forces integer division for JS! // << 0 and ~~ forces integer conversion for JS as well. for ( int i = 0; i != NUM; pieces[i] = img.get(~~(i/GRID) * jigX, i++ % GRID * jigY, jigX, jigY) ); bg = img; // initial bg is the original loaded image. } void draw() { if (frameCount % FREQ == 0) { // either recreate tiles each FREQ frames. if (isShuffling) for ( int i = 0; i != NUM; image( pieces[i++], (int) random(GRID)*jigX, (int) random(GRID)*jigY) ); else for ( int i = 0; i != NUM; image( pieces[i], (i/GRID << 0) * jigX, i++ % GRID * jigY) ); bg = get(); // gets a hard-copy of current canvas! } //else background(bg); // or clear canvas using previous BG snapshot. else image(bg, 0, 0); // JS patched version! // Put the rest of drawings below: } void mousePressed() { isShuffling = !isShuffling; } void keyPressed() { mousePressed(); }