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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 10-27. Simple Image Encryption sketch<br />

This is actually a pretty dopey encryption, but hopefully it sparks some ideas. Also, the<br />

encryption fragmentation is based on the 600 ✕ 400 format. If you change that, you’ll<br />

likely get an “array out of bounds” error. The basic encryption works by cutting the image<br />

into fragments that are used to create an array of PImages of all the fragments. At that<br />

point, you could write any sorting algorithm you’d like to encrypt (reorder) the fragments.<br />

I simply reversed the order with the following expression:<br />

imgs2[abs(i-(imgs.length-1))] = imgs[i];<br />

The function abs() always returns a positive value, allowing me to load the image fragments<br />

in imgs[] in reverse order into imgs2[]. Upon reviewing the code, If you have<br />

trouble seeing why this works, run the following line in the for loop within the encrypt<br />

function:<br />

println("i = "+i+", abs(i-(imgs.length-1)) = " + ➥<br />

abs(i-(imgs.length-1)));<br />

One minor caution—if you’re on an older computer (sorry), be careful running the<br />

VERY_HIGH option, it might take a while.<br />

If you’ve been looking through the imaging section of the <strong>Processing</strong> reference, you may<br />

have found some comm<strong>and</strong>s with duplicate names. For example, if you click on the<br />

PImage link, you’ll see that a number of the method names are the same as function<br />

names grouped under the Pixels heading in the language reference. The comm<strong>and</strong>s are<br />

actually different, although functionally they do some similar things. Here’s how to keep<br />

this stuff all straight.<br />

COLOR AND IMAGING<br />

439<br />

10

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

Saved successfully!

Ooh no, something went wrong!