04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

436<br />

Besides the set() function, it’s probably no surprise that there’s also a get() function.<br />

get() can return the color of a single pixel, an entire PImage, or a section of a PImage. This<br />

last case can be useful for creating a collage of image fragments (if that’s the sort of thing<br />

you enjoy doing). Here’s an example, shown in Figure 10-26, that copies four pieces of the<br />

image <strong>and</strong> pastes them in a stack on the right side of the display window. Please note that<br />

your image needs to be 650 (width) ✕ 450 pixels for this example to render properly.<br />

//Compositing<br />

size(650, 450);<br />

PImage img = loadImage("hong_kong.jpg");<br />

image(img, 0, 0);<br />

int w = width/5;<br />

int h = height/5;<br />

PImage[]frags = {<br />

get(130, 140, w, h),<br />

get(475, 220, w, h),<br />

get(220, 300, w, h),<br />

get(300, 205, w, h),<br />

get(100, 250, w, h)<br />

};<br />

for (int i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!