06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

372 <strong>Learning</strong> <strong>Processing</strong><br />

If you are working on a multi-user project, you most<br />

likely want <strong>to</strong> run the servers and clients on separate<br />

computers. After all, this is the point of creating multiuser<br />

applications in the fi rst place. However, for testing<br />

and development purposes, it is often convenient <strong>to</strong> run<br />

all the elements from one computer. In this case, the<br />

server IP address will be “ localhost ” or 127.0.0.1 (note<br />

this is the IP address used in this chapter’s examples).<br />

As will be covered in Section 21.3, <strong>Processing</strong> ’s “ export <strong>to</strong><br />

application ” feature will allow you <strong>to</strong> export a stand-alone<br />

application for your server, which you can then run in the<br />

background while you develop your client in <strong>Processing</strong> .<br />

Details as <strong>to</strong> how “ export <strong>to</strong> application ” works can be<br />

found in Chapter 18. You can also run multiple copies<br />

of a stand-alone application <strong>to</strong> simulate an environment<br />

with more than one client. Figure 19.6 shows the server<br />

running with two client instances.<br />

19.8<br />

Exercise 19-4: Expand the whiteboard <strong>to</strong> allow for color. Each client should send a red,<br />

green, and blue value in addition <strong>to</strong> the XY location. You will not need <strong>to</strong> make any changes<br />

<strong>to</strong> the server for this <strong>to</strong> work.<br />

Exercise 19-5: Create a two-player game of Pong played over the network. Th is is a complex<br />

assignment, so build it up slowly. For instance, you should get Pong <strong>to</strong> work fi rst without<br />

networking (if you are stuck, an example is provided at the book’s web site). You will also<br />

need <strong>to</strong> make changes <strong>to</strong> the server; specifi cally, the server will need <strong>to</strong> assign the players a<br />

paddle as they connect (left or right).<br />

Serial Communication<br />

fi g. 19.6 Examples 19-6 and 19-7 running <strong>to</strong>gether<br />

A nice reward for learning the ins and outs of networked communication is that it makes serial<br />

communication in <strong>Processing</strong> a breeze. Serial communication involves reading bytes from the computer’s<br />

serial port. Th ese bytes might come from a piece of hardware you purchase (a serial joystick, for example)<br />

or one that you design yourself by building a circuit and programming a microcontroller.<br />

Th is book does not cover the external hardware side of serial communication. However, if you are<br />

interested in learning more about physical computing, I recommend the book Physical Computing: Sensing<br />

and Controlling the Physical World with Computers (Course Technology PTR) by Dan O’Sullivan and Tom<br />

Igoe as well as Making Th ings Talk: Practical Methods for Connecting Physical Objects (Make Books) by Tom<br />

Igoe. Th e Arduino ( http://www.arduino.cc/ ) and Wiring ( http://wiring.org.co/ ) web sites are also excellent<br />

resources. Wiring and Arduino are two open-source physical computing platforms developed at the<br />

Interaction Design Institute Ivrea with a programming language modeled after <strong>Processing</strong> . I will provide<br />

some accompanying Arduino code for your reference, but the material in this book will only cover what<br />

<strong>to</strong> do once the data has already arrived in <strong>Processing</strong> .

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

Saved successfully!

Ooh no, something went wrong!