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 />

592<br />

To ensure that the sketch functions properly, please enter the following code into<br />

<strong>Processing</strong> in the exact order that I present it. As usual, the sketch begins with a title <strong>and</strong><br />

global variable declarations:<br />

/* Basic Drawing Application Example<br />

Ira Greenberg, April 17, 2006 */<br />

// fonts<br />

PFont titleFont, clearFont;<br />

The PFont variables were used for label text. I chose to dynamically generate a font by<br />

using <strong>Processing</strong>’s createFont() function. This function attempts to convert a typeface<br />

installed on your system into the format <strong>Processing</strong> needs. Later in the sketch, I specified<br />

Arial as the typeface to convert, as it’s a very common face. Don’t worry if you don’t have<br />

Arial installed on your system—you’ll be able to substitute a different face.<br />

// canvas background color<br />

color canvasBg = color(255);<br />

// paint color<br />

color paintColor;<br />

// palette<br />

color[]palette = new color[156];<br />

The palette array was initialized with 156 slots in memory, based on a table 6 swatches<br />

across <strong>and</strong> 26 swatches down (6 ✕ 26 = 156). This size was arbitrarily based on the size of<br />

the overall palette, as well as the size of each swatch.<br />

// create 3 icons<br />

PImage pencil, brush, eraser;<br />

I used imported images for the three tool buttons <strong>and</strong> <strong>Processing</strong>’s built-in PImage data<br />

type. These images need to live in <strong>Processing</strong>’s data directory. You can download these<br />

images from the Download section of the friends of ED web site (www.friendsofed.com/<br />

downloads.html).<br />

// panels coordinate arrays<br />

float[] menu, tools, canvas;<br />

// buttons coordinate arrays<br />

float[] pencilBtn, brushBtn, eraserBtn;<br />

Each section of the drawing interface, as well as the buttons, was broadly defined as a<br />

coordinate array (with a length of 4), holding each section/button’s x, y, width, <strong>and</strong> height<br />

values.<br />

//create button state colors<br />

color buttonUp = color(175, 175, 50, 150);<br />

color buttonOver = color(255, 130, 20, 175);<br />

color buttonSelected = color(250, 250, 30, 175);

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

Saved successfully!

Ooh no, something went wrong!