About the Author |
|
vi | |
About the Technical Reviewer |
|
vi | |
Acknowledgments |
|
xv | |
Introduction |
|
xvii | |
The Problem with School Math |
|
xviii | |
About This Book |
|
xx | |
Who Should Use This Book |
|
xxi | |
What's in This Book? |
|
xxi | |
Downloading and Installing Python |
|
xxii | |
Starting IDLE |
|
xxiii | |
Installing Processing |
|
xxiv | |
|
PART I HITCHIN' UP YOUR PYTHON WAGON |
|
|
|
1 Drawing Polygons With The Turtle Module |
|
|
3 | (16) |
|
|
4 | (3) |
|
Importing the turtle Module |
|
|
4 | (1) |
|
|
5 | (1) |
|
|
6 | (1) |
|
Repeating Code with Loops |
|
|
7 | (2) |
|
|
7 | (2) |
|
Using a for Loop to Draw a Square |
|
|
9 | (1) |
|
Creating Shortcuts with Functions |
|
|
9 | (2) |
|
Using Variables to Draw Shapes |
|
|
11 | (2) |
|
Using Variables in Functions |
|
|
11 | (1) |
|
|
12 | (1) |
|
|
13 | (4) |
|
Writing the triangle() Function |
|
|
13 | (1) |
|
|
14 | (3) |
|
|
17 | (2) |
|
2 Making Tedious Arithmetic Fun With Lists And Loops |
|
|
19 | (18) |
|
|
20 | (2) |
|
|
20 | (1) |
|
Using Operators to Write the average)) Function |
|
|
21 | (1) |
|
Mind the Order of Operations! |
|
|
21 | (1) |
|
Using Parentheses with Operators |
|
|
22 | (1) |
|
|
22 | (3) |
|
|
22 | (1) |
|
|
23 | (1) |
|
|
24 | (1) |
|
|
25 | (1) |
|
Using Lists to Store Values |
|
|
25 | (2) |
|
|
26 | (1) |
|
|
26 | (1) |
|
Removing Items from a List |
|
|
27 | (1) |
|
|
27 | (5) |
|
Accessing Individual Items with List Indices |
|
|
28 | (1) |
|
Accessing Index and Value with enumerated |
|
|
29 | (1) |
|
|
29 | (1) |
|
Accessing a Range of List Items |
|
|
30 | (1) |
|
Finding Out the Index of an Item |
|
|
30 | (1) |
|
|
31 | (1) |
|
|
32 | (2) |
|
Creating the running_sum Variable |
|
|
32 | (1) |
|
Writing the mySum() Function |
|
|
33 | (1) |
|
Finding the Average of a List of Numbers |
|
|
34 | (1) |
|
|
34 | (3) |
|
3 Guessing And Checking With Conditionals |
|
|
37 | (16) |
|
|
38 | (1) |
|
Making Decisions with if and else Statements |
|
|
38 | (1) |
|
Using Conditionals to Find Factors |
|
|
39 | (4) |
|
Writing the factors.py Program |
|
|
40 | (1) |
|
|
41 | (2) |
|
Creating a Number-Guessing Game |
|
|
43 | (5) |
|
Making a Random Number Generator |
|
|
44 | (1) |
|
|
44 | (1) |
|
Converting User Input to Integers |
|
|
45 | (1) |
|
Using Conditionals to Check for a Correct Guess |
|
|
45 | (1) |
|
Using a Loop to Guess Again! |
|
|
46 | (1) |
|
|
47 | (1) |
|
|
48 | (2) |
|
Applying the Number-Guessing Game Logic |
|
|
48 | (1) |
|
Writing the squareRoot() Function |
|
|
49 | (1) |
|
|
50 | (3) |
|
PART 2 RIDING INTO MATH TERRITORY |
|
|
|
4 Transforming And Storing Numbers With Algebra |
|
|
53 | (24) |
|
Solving First-Degree Equations |
|
|
54 | (4) |
|
Finding the Formula for First-Degree Equations |
|
|
55 | (1) |
|
Writing the equation() Function |
|
|
56 | (1) |
|
Using print() Instead of return |
|
|
57 | (1) |
|
Solving Higher-Degree Equations |
|
|
58 | (3) |
|
Using quad() to Solve Quadratic Equations |
|
|
59 | (1) |
|
Using plug() to Solve a Cubic Equation |
|
|
60 | (1) |
|
Solving Equations Graphically |
|
|
61 | (1) |
|
Getting Started with Processing |
|
|
61 | (2) |
|
Creating Your Own Graphing Tool |
|
|
63 | (6) |
|
|
69 | (4) |
|
Using Guess and Check to Find the Roots |
|
|
73 | (1) |
|
Writing the guess() Function |
|
|
73 | (2) |
|
|
75 | (2) |
|
5 Transforming Shapes With Geometry |
|
|
77 | (1) |
|
|
78 | (1) |
|
Specifying Location Using Coordinates |
|
|
79 | (1) |
|
|
80 | (6) |
|
Translating Objects with translate() |
|
|
80 | (3) |
|
Rotating Objects with rotate() |
|
|
83 | (1) |
|
Drawing a Circle of Circles |
|
|
84 | (1) |
|
Drawing a Circle of Squares |
|
|
85 | (1) |
|
|
86 | (3) |
|
|
86 | (1) |
|
Rotating the Individual Squares |
|
|
87 | (1) |
|
Saving Orientation with pushMatrix() and popMatrix() |
|
|
88 | (1) |
|
Rotating Around the Center |
|
|
89 | (1) |
|
Creating an Interactive Rainbow Grid |
|
|
89 | (4) |
|
Drawing a Grid of Objects |
|
|
90 | (1) |
|
Adding the Rainbow Color to Objects |
|
|
91 | (2) |
|
Drawing Complex Patterns Using Triangles |
|
|
93 | (9) |
|
|
94 | (2) |
|
Drawing an Equilateral Triangle |
|
|
96 | (2) |
|
Drawing Multiple Rotating Triangles |
|
|
98 | (1) |
|
Phase-Shifting the Rotation |
|
|
99 | (1) |
|
|
100 | (2) |
|
|
102 | (1) |
|
6 Creating Oscillations With Trigonometry |
|
|
103 | (24) |
|
Using Trigonometry for Rotations and Oscillations |
|
|
105 | (1) |
|
Writing Functions to Draw Polygons |
|
|
106 | (4) |
|
Drawing a Hexagon with Loops |
|
|
107 | (2) |
|
Drawing an Equilateral Triangle |
|
|
109 | (1) |
|
|
110 | (6) |
|
|
113 | (1) |
|
Using Python's Built-in enumerated Function |
|
|
114 | (2) |
|
Creating a Spirograph Program |
|
|
116 | (4) |
|
Drawing the Smaller Circle |
|
|
117 | (1) |
|
Rotating the Smaller Circle |
|
|
117 | (3) |
|
|
120 | (6) |
|
Writing the harmonograph Program |
|
|
121 | (2) |
|
Filling the List Instantly |
|
|
123 | (1) |
|
Two Pendulums Are Better Than One |
|
|
124 | (2) |
|
|
126 | (1) |
|
|
127 | (18) |
|
The Complex Coordinate System |
|
|
128 | (1) |
|
|
129 | (1) |
|
Multiplying a Complex Number by i |
|
|
130 | (1) |
|
Multiplying Two Complex Numbers |
|
|
131 | (1) |
|
Writing the magnitude() Function |
|
|
132 | (1) |
|
Creating the Mandelbrot Set |
|
|
132 | (9) |
|
Writing the mandelbrot() Function 1 |
|
|
35 | (104) |
|
Adding Color to the Mandelbrot Set |
|
|
139 | (2) |
|
|
141 | (2) |
|
Writing the Julia() Function |
|
|
141 | (2) |
|
|
143 | (2) |
|
8 Using Matrices For Computer Graphics And Systems Of Equations |
|
|
145 | (30) |
|
|
146 | (1) |
|
|
146 | (1) |
|
|
147 | (4) |
|
Order Matters in Matrix Multiplication |
|
|
151 | (1) |
|
|
151 | (3) |
|
|
154 | (2) |
|
|
156 | (4) |
|
Rotating Matrices in Real Time |
|
|
160 | (1) |
|
|
161 | (1) |
|
Creating the Rotation Matrix |
|
|
162 | (4) |
|
Solving Systems of Equations with Matrices |
|
|
166 | (6) |
|
|
167 | (1) |
|
Writing the gauss() Function |
|
|
168 | (4) |
|
|
172 | (3) |
|
PART 3 BLAZING YOUR OWN TRAIL |
|
|
|
9 Building Objects With Classes |
|
|
175 | (26) |
|
|
177 | (9) |
|
|
178 | (1) |
|
Making the Ball Bounce Off the Wall |
|
|
179 | (2) |
|
Making Multiple Balls Without Classes |
|
|
181 | (1) |
|
Creating Objects Using Classes |
|
|
182 | (4) |
|
|
186 | (14) |
|
Writing the Class for the Sheep |
|
|
186 | (1) |
|
Programming Sheep to Move Around |
|
|
187 | (2) |
|
Creating the energy Property |
|
|
189 | (1) |
|
Creating Grass Using Classes |
|
|
189 | (3) |
|
Making the Grass Brown when Eaten |
|
|
192 | (2) |
|
Giving Each Sheep a Random Color |
|
|
194 | (2) |
|
Programming Sheep to Reproduce |
|
|
196 | (1) |
|
|
197 | (1) |
|
Providing an Evolutionary Advantage |
|
|
198 | (2) |
|
|
200 | (1) |
|
10 Creating Fractals Using Recursion |
|
|
201 | (24) |
|
The Length of a Coastline |
|
|
202 | (7) |
|
|
203 | (1) |
|
Writing the factorial() Function |
|
|
203 | (1) |
|
|
204 | (5) |
|
|
209 | (5) |
|
Writing the segment() Function |
|
|
210 | (4) |
|
|
214 | (2) |
|
|
216 | (4) |
|
|
220 | (4) |
|
|
224 | (1) |
|
|
225 | (22) |
|
Creating a Cellular Automaton |
|
|
226 | (8) |
|
|
228 | (2) |
|
|
230 | (1) |
|
|
231 | (1) |
|
Putting the Cells into a Matrix |
|
|
232 | (1) |
|
|
233 | (1) |
|
|
234 | (4) |
|
|
235 | (3) |
|
Letting Your CA Grow Automatically |
|
|
238 | (1) |
|
|
238 | (3) |
|
The Elementary Cellular Automaton |
|
|
241 | (5) |
|
|
246 | (1) |
|
12 Solving Problems Using Genetic Algorithms |
|
|
247 | (26) |
|
Using a Genetic Algorithm to Guess Phrases |
|
|
248 | (6) |
|
Writing the makeList() Function |
|
|
248 | (1) |
|
Testing the makeList() Function |
|
|
249 | (1) |
|
Writing the score() Function |
|
|
250 | (1) |
|
Writing the mutate() Function |
|
|
250 | (1) |
|
Generating a Random Number |
|
|
251 | (3) |
|
Solving the Traveling Salesperson Problem (TSP) |
|
|
254 | (17) |
|
|
254 | (6) |
|
Writing the calcLength() Method |
|
|
260 | (1) |
|
Testing the calcLength() Method |
|
|
261 | (1) |
|
|
262 | (3) |
|
Applying the Phrase-Guessing Mutation Idea |
|
|
265 | (1) |
|
Mutating Two Numbers in a List |
|
|
265 | (4) |
|
Crossing Over to Improve Routes |
|
|
269 | (2) |
|
|
271 | (2) |
Index |
|
273 | |