Make – Getting Started with Processing

Make – Getting Started with Processing
اسم المؤلف
Casey Reas and Ben Fry
التاريخ
المشاهدات
293
التقييم
(لا توجد تقييمات)
Loading...
التحميل

Make – Getting Started with Processing
Casey Reas and Ben Fry
SECOND EDITION
Contents
Preface . xi
1/Hello 1
Sketching and Prototyping . 2
Flexibility . 2
Giants 3
Family Tree . 4
Join In . 5
2/Starting to Code . 7
Your First Program . 8
Example 2-1: Draw an Ellipse . 9
Example 2-2: Make Circles . 9
Show . 10
Save and New 11
Share . 11
Examples and Reference . 11
3/Draw . 13
The Display Window . 13
Example 3-1: Draw a Window 14
Example 3-2: Draw a Point 14
Basic Shapes . 14
Example 3-3: Draw a Line . 16
Example 3-4: Draw Basic Shapes . 16
Example 3-5: Draw a Rectangle 16
Example 3-6: Draw an Ellipse 17
Example 3-7: Draw Part of an Ellipse 18
Example 3-8: Draw with Degrees . 19
Drawing Order 20
Example 3-9: Control Your Drawing Order 20
Example 3-10: Put It in Reverse 20
Shape Properties . 21
vExample 3-11: Set Stroke Weight . 21
Example 3-12: Set Stroke Caps 21
Example 3-13: Set Stroke Joins 22
Drawing Modes . 22
Example 3-14: On the Corner 23
Color . 23
Example 3-15: Paint with Grays 25
Example 3-16: Control Fill and Stroke . 25
Example 3-17: Draw with Color 26
Example 3-18: Set Transparency . 27
Custom Shapes . 28
Example 3-19: Draw an Arrow . 28
Example 3-20: Close the Gap 28
Example 3-21: Create Some Creatures 29
Comments . 30
Robot 1: Draw 32
4/Variables 35
First Variables 35
Example 4-1: Reuse the Same Values . 35
Example 4-2: Change Values . 36
Making Variables 36
Processing Variables 38
Example 4-3: Adjust the Size, See What Follows 38
A Little Math . 38
Example 4-4: Basic Arithmetic . 39
Repetition . 40
Example 4-5: Do the Same Thing Over and Over 41
Example 4-6: Use a for Loop . 41
Example 4-7: Flex Your for Loop’s Muscles . 43
Example 4-8: Fanning Out the Lines . 43
Example 4-9: Kinking the Lines . 44
Example 4-10: Embed One for Loop in Another . 44
Example 4-11: Rows and Columns 45
Example 4-12: Pins and Lines 46
Example 4-13: Halftone Dots 46
Robot 2: Variables 47
5/Response 49
Once and Forever . 49
Example 5-1: The draw() Function 49
Example 5-2: The setup() Function 50
vi ContentsExample 5-3: Global Variable 51
Follow . 51
Example 5-4: Track the Mouse . 51
Example 5-5: The Dot Follows You 52
Example 5-6: Draw Continuously . 53
Example 5-7: Set Line Thickness . 53
Example 5-8: Easing Does It . 54
Example 5-9: Smooth Lines with Easing . 55
Click 56
Example 5-10: Click the Mouse 57
Example 5-11: Detect When Not Clicked . 58
Example 5-12: Multiple Mouse Buttons 59
Location . 61
Example 5-13: Find the Cursor . 62
Example 5-14: The Bounds of a Circle . 63
Example 5-15: The Bounds of a Rectangle . 64
Type 66
Example 5-16: Tap a Key . 67
Example 5-17: Draw Some Letters 68
Example 5-18: Check for Specific Keys 68
Example 5-19: Move with Arrow Keys . 70
Map 70
Example 5-20: Map Values to a Range . 70
Example 5-21: Map with the map() Function 71
Robot 3: Response 72
6/Translate, Rotate, Scale 75
Translate 75
Example 6-1: Translating Location 76
Example 6-2: Multiple Translations 76
Rotate 77
Example 6-3: Corner Rotation 78
Example 6-4: Center Rotation 78
Example 6-5: Translation, then Rotation . 79
Example 6-6: Rotation, Then Translation . 80
Example 6-7: An Articulating Arm . 80
Scale . 82
Example 6-8: Scaling . 82
Example 6-9: Keeping Strokes Consistent 83
Push and Pop 83
Example 6-10: Isolating Transformations . 84
Robot 4: Translate, Rotate, Scale 85
Contents vii7/Media . 89
Images 90
Example 7-1: Load an Image . 90
Example 7-2: Load More Images . 91
Example 7-3: Mousing Around with Images . 92
Example 7-4: Transparency with a GIF . 93
Example 7-5: Transparency with a PNG 94
Fonts . 94
Example 7-6: Drawing with Fonts . 95
Example 7-7: Draw Text in a Box . 96
Example 7-8: Store Text in a String . 97
Shapes 97
Example 7-9: Draw with Shapes 98
Example 7-10: Scaling Shapes . 98
Example 7-11: Creating a New Shape . 99
Robot 5: Media 101
8/Motion . 103
Frames . 103
Example 8-1: See the Frame Rate . 103
Example 8-2: Set the Frame Rate 104
Speed and Direction 104
Example 8-3: Move a Shape 104
Example 8-4: Wrap Around . 105
Example 8-5: Bounce Off the Wall . 107
Tweening . 108
Example 8-6: Calculate Tween Positions 108
Random 109
Example 8-7: Generate Random Values . 109
Example 8-8: Draw Randomly . 109
Example 8-9: Move Shapes Randomly 110
Timers . 111
Example 8-10: Time Passes 112
Example 8-11: Triggering Timed Events 112
Circular 113
Example 8-12: Sine Wave Values 115
Example 8-13: Sine Wave Movement . 115
Example 8-14: Circular Motion 116
Example 8-15: Spirals . 116
Robot 6: Motion . 118
viii Contents9/Functions 121
Function Basics 122
Example 9-1: Roll the Dice . 122
Example 9-2: Another Way to Roll . 123
Make a Function . 124
Example 9-3: Draw the Owl . 124
Example 9-4: Two’s Company . 125
Example 9-5: An Owl Function 126
Example 9-6: Increasing the Surplus Population 128
Example 9-7: Owls of Different Sizes . 129
Return Values . 130
Example 9-8: Return a Value 130
Robot 7: Functions . 131
10/Objects 135
Fields and Methods 136
Define a Class . 137
Create Objects 142
Example 10-1: Make an Object 142
Example 10-2: Make Multiple Objects 143
Tabs . 145
Robot 8: Objects . 147
11/Arrays 149
From Variables to Arrays 149
Example 11-1: Many Variables 149
Example 11-2: Too Many Variables 150
Example 11-3: Arrays, Not Variables . 151
Make an Array . 152
Example 11-4: Declare and Assign an Array . 153
Example 11-5: Compact Array Assignment 154
Example 11-6: Assigning to an Array in One Go 154
Example 11-7: Revisiting the First Example 154
Repetition and Arrays . 155
Example 11-8: Filling an Array in a for Loop . 155
Example 11-9: Track Mouse Movements 156
Arrays of Objects 158
Example 11-10: Managing Many Objects 159
Example 11-11: A New Way to Manage Objects 159
Example 11-12: Sequences of Images 160
Robot 9: Arrays . 162
Contents ix12/Data 165
Data Summary 165
Tables 166
Example 12-1: Read the Table 168
Example 12-2: Draw the Table 168
Example 12-3: 29,740 Cities . 170
JSON 172
Example 12-4: Read a JSON File 173
Example 12-5: Visualize Data from a JSON File 174
Network Data and APIs . 176
Example 12-6: Parsing the Weather Data . 178
Example 12-7: Chaining Methods 179
Robot 10: Data 180
13/Extend 183
Sound 184
Example 13-1: Play a Sample . 185
Example 13-2: Listen to a Microphone 186
Example 13-3: Create a Sine Wave 188
Image and PDF Export 189
Example 13-4: Saving Images . 190
Example 13-5: Draw to a PDF . 191
Hello, Arduino . 193
Example 13-6: Read a Sensor . 194
Example 13-7: Read Data from the Serial Port . 195
Example 13-8: Visualizing the Data Stream 196
Example 13-9: Another Way to Look at the Data . 198
A/Coding Tips 201
B/Data Types . 207
C/Order of Operations . 209
D/Variable Scope 211
Index 213
Index
Symbols
!= (not equal to) operator, 42

(hashmark) symbol, 189

% (modulo) operator, 157
&& (logical AND) operator, 69
// (double slashes) for code comments, 30-31
< (less than or equal to) operator,
42
< (less than) operator, 42
= (equal to) operator, 42
== (equal to) operator, 58, 68

(greater than) operator, 42
= (greater than or equal to) operator, 42
|| (logical OR) operator, 69
A
alpha values, 27
analyze ( ) method, 187
animation, 103-119
bouncing shapes off wall,
107-107
circular motion, 113-116
drawing/moving shapes randomly, 109-111
frame rates, 103-104
image/PDF export, 189-192
moving shapes, 104-105
sine wave values/movement,
115-116
speed and direction, 104-107
spirals, 116
timers, 111-113
tween positions, 108-109
wrapping shapes around screen,
105-107
APIs (application programming
interfaces), 176-180
arc ( ) function, 18
Arduino, 193-199
overview, 193
reading data from serial port,
195-196
reading sensors, 194-195
visualizing data, 196-199
arithmetic operations, 38-40
arrays, 149-162
creating, 152-155
defined, 149
filling in a for loop, 155-156
of objects, 158-161
repetition and, 155-158
tracking mouse movements
with, 156-158
variables versus, 149-152
arrow keys, detecting, 70
arrows, drawing, 28
assignment operator, 39
B
background ( ) function, 23, 52-53,
202
beginShape ( ) function, 28
blocks, for loop, 41
boolean data, 56, 135, 207
bugs, detecting and fixing, 201-205
C
chaining methods, 179-180
char data, 207
char variables, 67
circles
cursor position relative to,
63-64
213drawing, 9
circular motion, 113-116
classes
of data, 166
of objects, 137-142, 166
clicks, mouse, 56-61
close parameter, 28
code
coding tips, 201-205
color coding, 203
comments, 203
functions and parameters,
202-203
modifying with variables, 47
order of operations, 209
repeating with for loops, 40-45
style, 204
color
color coding, 203
drawing with, 23-28
RGB, 26
columns and rows, creating with for
loops, 45
comments
adding to code with //, 30-31
tips for writing, 203
Console, 8
constrain ( ) function, 111
constructors, 138-139
contributed libraries, 184
core libraries, 184
cos ( ) and sin ( ) functions, 113-116
createShape ( ) function, 99
createWriter ( ) function, 180
CSV files, 167, 173
cursors, finding location of, 61-66
D
data, 165-182
and APIs, 176-180
boolean, 56, 135, 207
chaining methods, 179-180
char, 207
classes of, 166
data visualization, 165
float, 104, 131, 135, 207
int, 36, 135, 207
JSON, 172-176
JSONArray, 166
JSONObject, 166, 174
network (see see APIs (application programming interfaces))
overview, 165-166
PFont, 135, 166, 207
PImage, 135, 166, 207
PShape, 135, 166, 207
reading from serial port,
195-196
String, 135, 166, 207
Table, 166-172
visualizing, 196-199
data types, 36-38, 143, 165,
207-208
degree measurements, 19
Display Window, 13
dist ( ) function, 53
downloading Processing, 7-8
draw ( ) function, 49, 51, 103
drawing, 13-33
avoiding arrays with, 154
basic shapes, 14-19
circles, 9
with color, 23-28
complex shapes, 29-30
continuous lines, 53
custom shapes, 28-30
drawing modes, 22
ellipses, 9, 17-19, 22
with fonts, 95-97
lines, 14-16
order of, 20-21
points, 14
rectangles, 16, 22
saving to PDF, 191-192
shape properties, 21-22
with shapes, 98
shapes, randomly, 109
windows, 14
E
easing, 54-56
214 Indexelements, in arrays, 152
ellipseMode ( ) function, 22
ellipses, drawing, 9, 17-19
else blocks, 58-60
embedded for loops, 44
endshape ( ) function, 28
Examples and Reference, 11-12
exporting sketches, 11
expressions, 39
F
fields, 136, 138
fill ( ) function, 23, 25
float data, 104, 131, 135, 207
float variable, 37
fonts, 94-97
drawing text in a box, 96
drawing with, 95-97
for loops, 40-45
creating rows and columns with,
45
embedded, 44
filling arrays with values in,
155-156
for fanning out lines, 44
for halftone dots, 46
for kinking lines, 44
for pins and lines, 46
for quick code changes, 43
frame rates, 49, 103-104
frames, 103
functions, 121-133
basics of, 122-123
coding tips, 202
creating, 124-130
defined, 13
return values, 130
G
getFloat ( ) method, 168
getInt ( ) method, 168, 174
getString ( ) method, 174
getting help, xv
GIF image format, 93
gray values, 25
H
halftone dots, creating, 45
headers, in Table data, 170
I
if blocks, 57-60
image ( ) function, 90
images
drawing to screen, 90-92
formats, 93-94
image/PDF export, 189-192
resizing, 92-93
sequences of, 160-161
transparency , 93-94
working with multiple, 91
index values, 152
initialization statement, 41
int data, 135, 207
J
JPEG image format, 93
JSON data, and APIs, 177-180
JSON files, 172-176
K
key variables, 67
keyCode variable, 69
keypressed variable, 66-70
keys, tapping, 67-68
L
libraries
Library Manager, 184
Serial Library, 193
Sound audio library, 184
lines
drawing, 14-16
drawing continuous, 53
setting thickness of, 53-54
smoothing with easing, 55
Linux installation, 7
loadImage ( ) function, 90
loadTable ( ) function, 167
local variable, 211
Index 215lowercase/uppercase letters in
code, 203
M
Mac OS X installation, 7
map ( ) function, 70-72, 196
math (see arithmetic operations)
media, 89-102
downloading online example
files, 89-90
fonts, 94-97
(see also fonts)
images, 90-94
(see also images)
shapes, 97-100
(see also shapes)
sound, 184-189
(see also sound)
Message Area, 8
methods, 136, 139
methods, chaining, 179-180
microphones, 186
modularity, 121
motion (see animation)
mouse
clicks of, 56-61
easing movements of, 54-56
tracking movements with
arrays, 156-158
mouse tracking, 51-52
mousepressed variable, 56-58
mouseX/mouseY variables, 70, 92,
188
move ( ) method, 143
N
naming variables, 36
network data (see see APIs (application programming interfaces))
nf ( ) function, 161
noFill ( ) function, 25
noStroke function, 25
O
object-oriented programming
(OOP), 135
objects, 135-148
arrays of, 158-161
basic concepts, 135-136
classes of, 137-142, 166
creating, 142-145
fields and methods, 136
operators, 39
order of operations , 209
PEMDAS, 40
P
parameters, 13, 202
PDFs (see images)
PEMDAS acronym, 40
persistence of vision, 103
PFont data, 135, 166, 207
PImage data, 135, 166, 207
pins and lines, creating, 45
pixels, 13
PNG image format, 93-94
point ( ) function, 14
popMatrix ( ) function, 83
primitives, 165
println ( ) function, 49
PrintWriter class, 180
Processing
data folder, 89-90
downloading/launching, 7-8
evolution of, xi-xii
Examples and Reference, 11-12
flexibility of, 2
history of, 3
libraries, 183-191
related languages and program
development, 4-5
special variables in, 38
tabs feature, 145
website for sharing/networking,
5
Processing Development Environment (PDE), 8
PShape data, 135, 166, 207
216 IndexpushMatrix ( ) function, 83
R
radians, 18-20
random ( ) function, 109-111
random movements, 109-111
rectangles
cursor position relative to,
64-66
drawing, 16
rectMode ( ) function, 22
Reference and Examples, 11-12
relational expression, 42-43
relational operators, 42
RGB color, 26
robot programs (examples)
arrays of objects, 162-164
drawing P5 robot, 32-33
drawRobot function, 131-133
generating and reading data
files, 180-182
loading images from SVG/PNG
files, 101-102
modifying code with variables,
47-48
mouse-responding shapes,
72-74
objects, 147-148
random and circular movements, 118-119
translate, rotate, and scale in,
85-87
rotate ( ) function, 77
rotating coordinate system, 77-81
rows and columns, creating with for
loops, 45
rule of variable scope, 211
S
Save command, 11
saveFrame ( ) function, 189
scale ( ) function, 82
scaling shapes, 82-83
scope, variable, 211
sensors, reading, 194-195
Serial Library, 193
setup ( ) function, 50-51
shape ( ) function, 98
shapeMode ( ) function, 98
shapes, 97-100
creating new, 99-100
drawing basic, 14-19
drawing with, 98
moving (see animation)
properties, 21-22
scaling, 98-99
wrapping around screen,
105-107
sin ( ) and cos ( ) functions, 113-116
sine wave values/movement,
115-116
size ( ) function, 14, 38
sketching, 1-2
creating/saving sketches, 10-11
exporting sketches, 11
Sketch menu, 10
smoothing lines with easing, 55
sound, 184-189
fundamentals of, 187
microphones, 186-188
playing, 185-186
sine wave, 187-189
SoundFile class methods, 186
spirals, creating, 116
String data, 135, 166, 207
string values, 67
strings, storing text in, 97
stroke ( ) function, 23, 25
stroke weight consistency, 83
strokeCap ( ) function, 21
strokeJoin ( ) function, 22
strokeWeight ( ) function, 21
SVG format, vector shapes in, 93
T
Table data, 166-172
tabs, 145
test statement, 41-42
text
drawing in boxes, 96
storing in strings, 97
text ( ) function, 68, 95
Index 217Text Editor, 8
textSize ( ) function, 68, 95
timed events, triggering, 112-113
tracking, mouse, 51-52
transformation effects, isolating,
83
translate ( ) function, 75-77, 126
translating locations, 75-81
transparency control, 27
troublshooting (see bugs, detecting and fixing)
TSV files, 167
tweening, in animation, 108-109
U
update statement, 41
uppercase/lowercase letters in
code, 203
V
values
of variables, 36
variable scope rule, 211
variables, 35-48, 143
arrays versus, 149-152
changing, 36
creating, 36-38
data types, 36
declaring, 37
defined, 35
float variable, 37
local, 211
and repetition, 40-45
reusing identical values, 35
rule of variable scope, 211
vector shapes, 93, 97
vertex ( ) function, 28, 29
W
Windows installation, 7

كلمة سر فك الضغط : books-world.net
The Unzip Password : books-world.net

تحميل

يجب عليك التسجيل في الموقع لكي تتمكن من التحميل

تسجيل | تسجيل الدخول