// imagePuzzle // mikkel . crone . koser // sept. 23 2003 // // INSTRUCTIONS: // click, drag and release. // "r" resets the image // "w" loads a random image from the BEYONDTHREE.PHOTO archive // // an example of new BImage methods released with v. 0060 // // IMPLEMENTING NEW FEATURES: // background(BImage); // tint(int n, int nn); // BImage.get(int x, int y, int w, int h); // BImage.set(int x, int y, BImage); BImage bg; BImage resetImg; BImage crop; int cropH = 80; int cropW = 80; void setup(){ size(350, 350); // loads a random image from the BEYONDTHREE.PHOTO archive bg = loadImage("http://www.beyondthree.com/photo/archive/ph_" + (int)random(1, 49) + ".jpg"); resetImg = bg.get(0, 0, 350, 350); // makes a copy of the loadet image for resetting crop = bg.get(0, 0, cropH, cropW); // copies a piece of BImage "bg" into BImage "crop" background(bg); // sets the background to the BImage "bg" imageMode(CENTER_DIAMETER); } void loop(){ if(!mousePressed){ tint(255); background(bg); // sets the background to the BImage "bg" }else{ background(bg); // sets the background to the BImage "bg" tint(255, 125); // set the alpha channel of BImage's (white, alpha 125) image(crop, mouseX, mouseY); // displays the BImage "crop" at the position of the mouse } } void mousePressed(){ crop = bg.get(mouseX-(cropW/2), mouseY-(cropH/2), cropH, cropW); // copy a piece of the background } void mouseReleased(){ bg.set(mouseX-(cropW/2), mouseY-(cropH/2), crop); // paste BImage "crop" onto BImage "bg" at the mouse-position } void keyPressed(){ if(key == 'r'){ bg = resetImg.get(0, 0, 350, 350);; // reloads BImage "bg" with the original content }else if(key == 'w'){ // loads a random image from the BEYONDTHREE.PHOTO archive bg = loadImage("http://www.beyondthree.com/photo/archive/ph_" + (int)random(1, 49) + ".jpg"); resetImg = bg.get(0, 0, 350, 350); // makes a copy of the loadet image for resetting } }