Preface |
|
ix | |
1 Hello |
|
1 | (6) |
|
Sketching and Prototyping |
|
|
2 | (1) |
|
|
3 | (1) |
|
|
3 | (2) |
|
|
5 | (1) |
|
|
5 | (2) |
2 Starting to Code |
|
7 | (6) |
|
|
8 | (1) |
|
|
9 | (1) |
|
Example 2-1: Draw an Ellipse |
|
|
9 | (1) |
|
Example 2-2: Make Circles |
|
|
10 | (1) |
|
|
10 | (1) |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
12 | (1) |
3 Draw |
|
13 | (22) |
|
|
13 | (1) |
|
Example 3-1: Draw a Window |
|
|
14 | (1) |
|
Example 3-2: Draw a Point |
|
|
14 | (1) |
|
|
14 | (6) |
|
|
16 | (1) |
|
Example 3-4: Draw Basic Shapes |
|
|
16 | (1) |
|
Example 3-5: Draw a Rectangle |
|
|
16 | (1) |
|
Example 3-6: Draw an Ellipse |
|
|
17 | (1) |
|
Example 3-7: Draw Part of an Ellipse |
|
|
18 | (1) |
|
Example 3-8: Draw with Degrees |
|
|
19 | (1) |
|
|
20 | (1) |
|
Example 3-9: Control Your Drawing Order |
|
|
20 | (1) |
|
Example 3-10: Put It in Reverse |
|
|
20 | (1) |
|
|
21 | (1) |
|
Example 3-11: Set Stroke Weight |
|
|
21 | (1) |
|
Example 3-12: Set Stroke Caps |
|
|
21 | (1) |
|
Example 3-13: Set Stroke Joins |
|
|
22 | (1) |
|
|
22 | (1) |
|
Example 3-14: On the Corner |
|
|
23 | (1) |
|
|
23 | (5) |
|
Example 3-15: Paint with Grays |
|
|
25 | (1) |
|
Example 3-16: Control Fill and Stroke |
|
|
25 | (1) |
|
Example 3-17: Draw with Color |
|
|
26 | (1) |
|
Example 3-18: Set Transparency |
|
|
27 | (1) |
|
|
28 | (2) |
|
Example 3-19: Draw an Arrow |
|
|
28 | (1) |
|
Example 3-20: Close the Gap |
|
|
28 | (1) |
|
Example 3-21: Create Some Creatures |
|
|
29 | (1) |
|
|
30 | (1) |
|
|
31 | (4) |
4 Variables |
|
35 | (12) |
|
|
35 | (1) |
|
Example 4-1: Reuse the Same Values |
|
|
35 | (1) |
|
Example 4-2: Change Values |
|
|
36 | (1) |
|
|
36 | (1) |
|
|
37 | (1) |
|
Example 4-3: Adjust the Size, See What Follows |
|
|
37 | (1) |
|
|
37 | (2) |
|
Example 4-4: Basic Arithmetic |
|
|
38 | (1) |
|
|
39 | (6) |
|
Example 4-5: Do the Same Thing Over and Over |
|
|
39 | (1) |
|
Example 4-6: Use a for Loop |
|
|
40 | (1) |
|
Example 4-7: Flex Your for Loop's Muscles |
|
|
41 | (1) |
|
Example 4-8: Fanning Out the Lines |
|
|
41 | (1) |
|
Example 4-9: Kinking the Lines |
|
|
42 | (1) |
|
Example 4-10: Embed One for Loop in Another |
|
|
42 | (1) |
|
Example 4-11: Rows and Columns |
|
|
43 | (1) |
|
Example 4-12: Pins and Lines |
|
|
44 | (1) |
|
Example 4-13: Halftone Dots |
|
|
44 | (1) |
|
|
45 | (2) |
5 Response |
|
47 | (26) |
|
|
47 | (2) |
|
Example 5-1: The draw() Function |
|
|
47 | (1) |
|
Example 5-2: The setup() Function |
|
|
48 | (1) |
|
Example 5-3: Global Variables |
|
|
49 | (1) |
|
|
49 | (5) |
|
Example 5-4: Track the Mouse |
|
|
49 | (1) |
|
Example 5-5: The Dot Follows You |
|
|
50 | (1) |
|
Example 5-6: Draw Continuously |
|
|
50 | (1) |
|
Example 5-7: Set Thickness on the Fly |
|
|
51 | (1) |
|
Example 5-8: Easing Does It |
|
|
52 | (1) |
|
Example 5-9: Smooth Lines with Easing |
|
|
53 | (1) |
|
Modifying Global Variables |
|
|
54 | (1) |
|
|
55 | (4) |
|
Example 5-10: Click the Mouse |
|
|
56 | (1) |
|
Example 5-11: Detect When Not Clicked |
|
|
57 | (1) |
|
Example 5-12: Multiple Mouse Buttons |
|
|
58 | (1) |
|
|
59 | (5) |
|
Example 5-13: Find the Cursor |
|
|
60 | (1) |
|
Example 5-14: The Bounds of a Circle |
|
|
61 | (1) |
|
Example 5-15: The Bounds of a Rectangle |
|
|
62 | (2) |
|
|
64 | (4) |
|
|
65 | (1) |
|
Example 5-17: Draw Some Letters |
|
|
65 | (1) |
|
Example 5-18: Check for Specific Keys |
|
|
66 | (1) |
|
Example 5-19: Move with Arrow Keys |
|
|
67 | (1) |
|
|
68 | (2) |
|
Example 5-20: Map Values to a Range |
|
|
68 | (1) |
|
Example 5-21: Map with the map() Function |
|
|
69 | (1) |
|
|
70 | (3) |
6 Translate, Rotate, Scale |
|
73 | (12) |
|
|
73 | (2) |
|
Example 6-1: Translating Location |
|
|
74 | (1) |
|
Example 6-2: Multiple Translations |
|
|
74 | (1) |
|
|
75 | (5) |
|
Example 6-3: Corner Rotation |
|
|
76 | (1) |
|
Example 6-4: Center Rotation |
|
|
76 | (1) |
|
Example 6-5: Translation, Then Rotation |
|
|
77 | (1) |
|
Example 6-6: Rotation, Then Translation |
|
|
78 | (1) |
|
Example 6-7: An Articulating Arm |
|
|
79 | (1) |
|
|
80 | (1) |
|
|
80 | (1) |
|
Example 6-9: Keeping Strokes Consistent |
|
|
81 | (1) |
|
|
81 | (2) |
|
Example 6-10: Isolating Transformations |
|
|
82 | (1) |
|
Robot 4: Translate, Rotate, Scale |
|
|
83 | (2) |
7 Media |
|
85 | (14) |
|
|
86 | (5) |
|
Example 7-1: Load an Image |
|
|
86 | (1) |
|
Example 7-2: Load More Images |
|
|
87 | (1) |
|
Example 7-3: Mousing Around with Images |
|
|
88 | (2) |
|
Example 7-4: Transparency with a GIF |
|
|
90 | (1) |
|
Example 7-5: Transparency with a PNG |
|
|
90 | (1) |
|
|
91 | (3) |
|
Example 7-6: Drawing with Fonts |
|
|
92 | (1) |
|
Example 7-7: Draw Text in a Box |
|
|
93 | (1) |
|
Example 7-8: Store Text in a String |
|
|
93 | (1) |
|
|
94 | (3) |
|
Example 7-9: Draw with Shapes |
|
|
94 | (1) |
|
Example 7-10: Scaling Shapes |
|
|
95 | (1) |
|
Example 7-11: Creating a New Shape |
|
|
95 | (2) |
|
|
97 | (2) |
8 Motion |
|
99 | (18) |
|
|
99 | (1) |
|
Example 8-1: See the Frame Rate |
|
|
99 | (1) |
|
Example 8-2: Set the Frame Rate |
|
|
100 | (1) |
|
|
100 | (4) |
|
Example 8-3: Move a Shape |
|
|
101 | (1) |
|
|
101 | (2) |
|
Example 8-5: Bounce Off the Wall |
|
|
103 | (1) |
|
|
104 | (1) |
|
Example 8-6: Calculate Tween Positions |
|
|
104 | (1) |
|
|
105 | (3) |
|
Example 8-7: Generate Random Values |
|
|
105 | (1) |
|
Example 8-8: Draw Randomly |
|
|
106 | (1) |
|
Example 8-9: Move Shapes Randomly |
|
|
106 | (2) |
|
|
108 | (1) |
|
Example 8-10: Time Passes |
|
|
108 | (1) |
|
Example 8-11: Triggering Timed Events |
|
|
108 | (1) |
|
|
109 | (5) |
|
Example 8-12: Sine Wave Values |
|
|
111 | (1) |
|
Example 8-13: Sine Wave Movement |
|
|
111 | (1) |
|
Example 8-14: Circular Motion |
|
|
112 | (1) |
|
|
113 | (1) |
|
|
114 | (3) |
9 Functions |
|
117 | (12) |
|
|
118 | (2) |
|
Example 9-1: Roll the Dice |
|
|
118 | (1) |
|
Example 9-2: Another Way to Roll |
|
|
119 | (1) |
|
|
120 | (5) |
|
Example 9-3: Draw the Owl |
|
|
120 | (1) |
|
Example 9-4: Two's Company |
|
|
121 | (1) |
|
Example 9-5: An Owl Function |
|
|
122 | (2) |
|
Example 9-6: Increasing the Surplus Population |
|
|
124 | (1) |
|
Example 9-7: Owls of Different Sizes |
|
|
124 | (1) |
|
|
125 | (2) |
|
Example 9-8: Return a Value |
|
|
126 | (1) |
|
|
127 | (2) |
10 Objects |
|
129 | (12) |
|
|
130 | (1) |
|
|
131 | (4) |
|
|
135 | (4) |
|
Example 10-1: Make an Object |
|
|
135 | (1) |
|
Example 10-2: Make Multiple Objects |
|
|
136 | (1) |
|
|
137 | (2) |
|
|
139 | (2) |
11 Lists |
|
141 | (14) |
|
|
141 | (3) |
|
Example 11-1: Many Variables |
|
|
141 | (1) |
|
Example 11-2: Too Many Variables |
|
|
142 | (1) |
|
Example 11-3: Lists, Not Variables |
|
|
143 | (1) |
|
|
144 | (3) |
|
Example 11-4: Declare and Append to a List |
|
|
146 | (1) |
|
Example 11-5: Compact List Initialization |
|
|
146 | (1) |
|
Example 11-6: Revisiting the First Example |
|
|
146 | (1) |
|
|
147 | (2) |
|
Example 11-7: Filling a List in a for Loop |
|
|
147 | (1) |
|
Example 11-9: Track Mouse Movements |
|
|
148 | (1) |
|
|
149 | (3) |
|
Example 11-10: Managing Many Objects |
|
|
149 | (1) |
|
Example 11-11: A New Way to Manage Objects |
|
|
150 | (1) |
|
Example 11-12: Sequences of Images |
|
|
151 | (1) |
|
|
152 | (3) |
12 Data and Dictionaries |
|
155 | (24) |
|
|
155 | (1) |
|
|
156 | (6) |
|
Example 12-1: (Keyboard) Keys as (Dictionary) Keys |
|
|
157 | (1) |
|
|
158 | (3) |
|
Example 12-2: The Planets |
|
|
161 | (1) |
|
|
162 | (6) |
|
Example 12-3: Read the Data |
|
|
162 | (1) |
|
|
163 | (1) |
|
Example 12-4: Draw the Table |
|
|
164 | (2) |
|
Example 12-5: 29,740 Cities |
|
|
166 | (2) |
|
|
168 | (4) |
|
Example 12-6: Read a JSON File |
|
|
169 | (1) |
|
Example 12-7: Visualize Data from a JSON File |
|
|
170 | (2) |
|
|
172 | (4) |
|
Example 12-8: Parsing the Weather Data |
|
|
175 | (1) |
|
Example 12-9: Chaining Square Brackets |
|
|
175 | (1) |
|
|
176 | (3) |
13 Extend |
|
179 | (18) |
|
|
180 | (5) |
|
Example 13-1: Play a Sample |
|
|
181 | (1) |
|
Example 13-2: Listen to a Microphone |
|
|
182 | (2) |
|
Example 13-3: Create a Sine Wave |
|
|
184 | (1) |
|
|
185 | (3) |
|
Example 13-4: Saving Images |
|
|
185 | (2) |
|
Example 13-5: Draw to a PDF |
|
|
187 | (1) |
|
|
188 | (9) |
|
Example 13-6: Read a Sensor |
|
|
189 | (2) |
|
Example 13-7: Read Data from the Serial Port |
|
|
191 | (1) |
|
Example 13-8: Visualizing the Data Stream |
|
|
192 | (1) |
|
Example 13-9: Another Way to Look at the Data |
|
|
193 | (4) |
A Coding Tips |
|
197 | (6) |
B Data Types |
|
203 | (2) |
C Order of Operations |
|
205 | (2) |
D Variable Scope |
|
207 | (4) |
E Processing, Python, and Java |
|
211 | (4) |
Index |
|
215 | |