Processing Second Edition
Processing Second Edition
Processing
Second edition
Reas_000.indd 1
7/16/2014 3:10:32 PM
Reas_000.indd 2
7/16/2014 3:10:32 PM
Processing:
a programming
handbook for
visual designers
and artists
Second edition
Casey Reas
Ben Fry
Reas_000.indd 3
7/16/2014 3:10:32 PM
2014016283
10 9 8 7 6 5 4 3 2 1
Reas_000.indd 4
7/16/2014 3:10:32 PM
Contents
ix
xi
xi
xii
xii
xiv
xv
4
4
6
6
Foreword
Preface
Contents
Acknowledgments
1. Processing ...
Software
Literacy
Open
Education
Network
Context
9 2. Using Processing
39 4. Color
40
Color by number
45
RGB, HSB
43
48
51
Data types
54
Variable names
52
55
56
58
59
61
62
Download, Install
65
10
Export
69
Environment
11
Example walk-through
16
Comments
16
17
17
19
19
20
20
Coding is writing
Functions
Expressions, Statements
Case sensitivity
Curves
35
77
79
81
Order of operations
Shortcuts
6. Flow
Looping
Relational expressions
Conditionals
Logical operators
Variables scope
89
28
34
72
Arithmetic
Reference
Coordinates
32
70
Processing variables
83 7. Interactivity
Console
21
32
65
Variables
Whitespace
21 3. Draw
23
Hexadecimal
51 5. Variables
9
9
Blend
Basic shapes
Drawing order
Gray values
Attributes
84
Mouse data
90
Keyboard data
93
94
94
97
98
100
Mouse buttons
Coded keys
Events
Mouse events
Key events
Event flow
Cursor icon
Modes
Reas_000.indd 5
7/16/2014 3:10:32 PM
173
104
174
103
Iterate
105
for loop
109
111
while loop
Loop and draw()
Nested loops
115 9. Synthesis 1
115
Sketching software
117
Examples
116
123
125
129
133
137
141
142
143
144
147
148
149
150
153
154
156
157
161
162
164
167
170
Programming techniques
Esthetique Programmee
LettError, RandomFont
173
176
176
177
181
182
185
185
187
188
189
192
Beowolf
197
Substrate
202
Characters
Words, Sentences
Draw text
197
204
209
213
213
216
218
219
221
Load media
225
Pixel fonts
226
Vector fonts
Text attributes
Typing
Display
Tint, Transparency
Mask
Filter
225
227
243
245
249
253
257
14. Transform
Translate
Controlling transformations
Rotate
Scale
Combining transformations
Vertex
Points, Lines
Geometry
Curves
Contours
16. 3D Drawing
3D form
Camera
Lights, Materials
Texture maps
17. Shapes
Display SVG
Display OBJ
Transform
Create
Modify
18. Synthesis 2
Iteration
Debugging
Examples
vi
Reas_000.indd 6
7/16/2014 3:10:32 PM
261
262
264
267
270
272
275
283
285
289
289
292
295
296
301
301
306
310
314
317
323
323
326
327
329
330
331
20. Calculate
Exponents, Roots
Normalize, Map
Simple curves
Constraining numbers
Distance
Easing
Angles, Waves
Circles, Spirals
Direction
21. Random
Unexpected values
355
355
358
368
370
371
373
377
377
377
378
Distributions
391
Noise
Random seed
22. Motion
Controlling motion
Kinetic typography
23. Time
24. Functions
Abstraction
Why functions?
393
399
403
407
411
413
414
416
419
422
425
427
428
431
334
Create functions
343
435
350
Recursion
438
342
345
Overload functions
Parameterize
432
436
440
441
443
444
25. Objects
Object-oriented programming
Classes and objects
Multiples files
Multiple constructors
Composite objects
Inheritance
26. Synthesis 3
Modularity, reusability
Algorithm
Examples
Define an array
Array functions
Arrays of objects
Two-dimensional arrays
29. Animation
Arrays of images
Orientation
Drawings in motion
Active tools
vii
Reas_000.indd 7
7/16/2014 3:10:32 PM
449
453
460
468
475
485
485
486
489
491
31. Simulate
Motion
Particle systems
Springs
Cellular automata
Autonomous agent
32. Data
514
516
519
525
525
529
530
531
536
540
543
543
544
548
550
555
555
558
562
565
569
XML
33. Interface
Rollover, Button
Drag and drop
Check boxes
Radio buttons
Scrollbar
Scriptographer
585
Curie
589
595
Strings
JSON
512
Data structure
500
506
581
593
Export files
Table
505
577
Format data
493
495
575
593
Extend Processing
595
597
599
615
623
Related Media
633
Index
629
Glossary
Read pixels
Write pixels
Copy pixels
Color components
Pixel array
Pixel components
35. Render Techniques
Renderers
Combine surfaces
36. Synthesis 4
Collage engine
Waves
3D letter
Noise landscape
Network
viii
Reas_000.indd 8
7/16/2014 3:10:32 PM