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

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

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

Data Streams 365<br />

must be networked locally (via a router or hub, ethernet or wifi ) or on the internet. Th e IP address can be<br />

found in the network settings of your machine.<br />

fi g. 19.5 Examples 19-3, 19-4, and 19-5 all running <strong>to</strong>gether<br />

Example 19-4: Client reading values as background color<br />

// Import the net libraries<br />

import processing.net.*;<br />

// Declare a client<br />

Client client;<br />

// The data we will read from the server<br />

int data;<br />

void setup() {<br />

size(200,200);<br />

// Create the Client<br />

client = new Client(this, "127.0.0.1", 5204);<br />

}<br />

void draw() {<br />

if (client.available() > 0) {<br />

data = client.read(); // Read data<br />

}<br />

background(data);<br />

}<br />

The incoming data is used<br />

<strong>to</strong> color the background.

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

Saved successfully!

Ooh no, something went wrong!