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

594<br />

The createFont() function dynamically generates a font based on the typeface name<br />

argument passed to the function. Again, I used Arial as it’s a very common face, <strong>and</strong> is<br />

likely installed on your computer. If you don’t have Arial (or if you dislike it), you can substitute<br />

it with any face installed on your computer. If you’re not sure what faces are<br />

installed, you can run the comm<strong>and</strong> println(PFont.list()); in <strong>Processing</strong>, which will<br />

output all your installed fonts.<br />

// create icons<br />

pencil = loadImage("pencil_cursor.png");<br />

brush = loadImage("brush_cursor.png");<br />

eraser = loadImage("eraser_cursor.png");<br />

To load the cursor PNG images, you need to first import them into the sketch’s data directory<br />

using the Add File comm<strong>and</strong>, found under the Sketch menu.<br />

// create panel coordinate arrays<br />

menu = new float[]{<br />

0, 0, width, 25 };<br />

tools = new float[]{<br />

0, menu[3], 50, 165 };<br />

canvas = new float[]{<br />

tools[2], menu[3], width-tools[2], height-menu[3]+1 };<br />

// create button coordinate arrays<br />

pencilBtn = new float[]{<br />

tools[0]+5, tools[1]+10, tools[2]-11, 45 };<br />

brushBtn = new float[]{<br />

tools[0]+5, pencilBtn[1]+ pencilBtn[3]+5, tools[2]-11, 45 };<br />

eraserBtn = new float[]{<br />

tools[0]+5, brushBtn[1]+ brushBtn[3]+5, tools[2]-11, 45 };<br />

// create slider coordinate arrays<br />

sliderBar = new float[]{<br />

width-150, menu[1]+menu[3]/2, 75, menu[1]+menu[3]/2 };<br />

sliderH<strong>and</strong>le = new float[]{<br />

sliderBar[0]+sliderBar[2]/2, sliderBar[1]-3, 6, 6 };<br />

// create clear button coordinate array<br />

clearBtn = new float[]{<br />

width-45, 6, 31, 13 };<br />

I initialized the coordinate arrays, using existing interface elements as references in defining<br />

the specific coordinate values. Laying out an application based on these types of relationships<br />

adds flexibility to the GUI. For example, if three buttons are sized <strong>and</strong> placed<br />

based on the width of the tool pane, it doesn’t matter if the application window eventually<br />

scales up or down—the buttons will resize appropriately <strong>and</strong> remain in the correct place<br />

in the interface. In this sketch, I didn’t follow this rule religiously, but rather used it when<br />

it seemed convenient. Although laying elements relative to each other adds flexibility, it

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

Saved successfully!

Ooh no, something went wrong!