/*------------------------------------------------------------ Copyright (c) 2013, friends of Ed (An Apress Company) All rights reserved. The code provided here accompanies the book: Processing: Creative Coding and Generative Art in Processing 2 By Ira Greenberg, Dianna Xu, and Deepak Kumar friends of Ed (An APress Company), 2013 ISBN-13 978-1430244646 Please refer to the associated README for a full disclaimer. Sunset modification and other cosmetic changes by Michael Goldwasser, 2015 ------------------------------------------------------------*/ // imageMask.pde, chapter 10 // Masking out the sky in an image void setup() { //PImage img = loadImage("prinzipal.jpg"); PImage img = loadImage("http://mathcs.slu.edu/~goldwasser/144/activity/masking/prinzipal.jpg"); size(img.width*3, img.height); //Thrice the width so that we can display the result and the original side by side PImage msk = createImage(img.width, img.height, RGB); //the mask should be an image the same size as the original background(0); for (int y=0; y 650 || blue(c) > 190) { // cloud or sky msk.set(x,y,color(0)); } else { msk.set(x,y,color(255)); } } } image(img, 0, 0); img.mask(msk); image(img, img.width, 0); //PImage sunset = loadImage("sunset.jpg"); PImage sunset = loadImage("http://mathcs.slu.edu/~goldwasser/144/activity/masking/sunset.jpg"); PImage sunsetCropped = sunset.get(sunset.width-img.width, sunset.height-img.height, img.width, img.height); image(sunsetCropped, 2*img.width, 0); image(img, 2*img.width, 0); save("building.jpg"); } // end setup()