وبلاگ بلیان

The Nature of Code

معرفی کتاب «The Nature of Code» نوشتهٔ Hannah Cowan و Daniel Shiffman، منتشرشده توسط نشر 2 در سال 2024. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.

Dedication Acknowledgments Introduction What Is This Book? A Word About p5.js What Do You Need to Know? How Are You Reading This Book? The Coding Train Connection Additional Resources The “Story” of This Book Part 1: Inanimate Objects Part 2: It’s Alive! Part 3: Intelligence Using This Book as a Syllabus How to Read the Code Full Examples Example #.#: Example Title Complete Snippets Context-Free Code Snipped Code Exercises Exercise #.# Solutions The Ecosystem Project Getting Help and Submitting Feedback Randomness Random number tables from A Million Random Digits with 100,000 Normal Deviates by the RAND Corporation Random Walks The Random Walker Class Coding Conventions Example 0.1: A Traditional Random Walk Example 0.2: A Random-Number Distribution Pseudorandom Numbers Exercise 0.1 Probability and Nonuniform Distributions Exercise 0.2 Example 0.3: A Walker That Tends to Move to the Right Exercise 0.3 A Normal Distribution of Random Numbers Calculating Mean and Standard Deviation Example 0.4: A Gaussian Distribution Exercise 0.4 Exercise 0.5 A Custom Distribution of Random Numbers Example 0.5: An Accept-Reject Distribution Exercise 0.6 A Smoother Approach with Perlin Noise Noise Ranges Example 0.6: A Perlin Noise Walker Exercise 0.7 Two-Dimensional Noise Noise Detail Exercise 0.8 Exercise 0.9 Exercise 0.10 The Ecosystem Project Vectors Marshall Islands stick chart on display at the Berkeley Art Museum (photo by Jim Heaphy) The Point of Vectors Example 1.1: Bouncing Ball with No Vectors Vectors in p5.js Vector Addition Addition Properties with Vectors Example 1.2: Bouncing Ball with Vectors! Exercise 1.1 Exercise 1.2 Exercise 1.3 More Vector Math Vector Subtraction Example 1.3: Vector Subtraction Vector Multiplication and Division Example 1.4: Multiplying a Vector More Number Properties with Vectors Vector Magnitude Example 1.5: Vector Magnitude Normalizing Vectors Example 1.6: Normalizing a Vector Motion with Vectors Example 1.7: Motion 101 (Velocity) Acceleration Algorithm 1: Constant Acceleration Exercise 1.4 Example 1.8: Motion 101 (Velocity and Constant Acceleration) Exercise 1.5 Algorithm 2: Random Acceleration Example 1.9: Motion 101 (Velocity and Random Acceleration) Exercise 1.6 Static vs. Nonstatic Methods Exercise 1.7 Algorithm 3: Interactive Motion Example 1.10: Accelerating Toward the Mouse Exercise 1.8 The Ecosystem Project Forces Calder installation at the New Gallery, Charles Hayden Memorial Library, MIT, Cambridge, MA, 1950 (photo by Ezra Stoller) Forces and Newton’s Laws of Motion Newton’s First Law Newton’s Third Law Newton’s Second Law Weight vs. Mass Force Accumulation Exercise 2.1 Factoring In Mass Units of Measurement Exercise 2.2 Creating Forces Example 2.1: Forces Example 2.2: Forces Acting on Two Objects Exercise 2.3 Exercise 2.4 Exercise 2.5 Example 2.3: Gravity Scaled by Mass Modeling a Force Parsing Formulas Friction Example 2.4: Including Friction Exercise 2.6 Exercise 2.7 Air and Fluid Resistance Example 2.5: Fluid Resistance Exercise 2.8 Exercise 2.9 Exercise 2.10 Gravitational Attraction Example 2.6: Attraction Exercise 2.11 Example 2.7: Attraction with Many Movers Exercise 2.12 Exercise 2.13 The n-Body Problem Example 2.8: Two-Body Attraction Exercise 2.14 Example 2.9: n Bodies Exercise 2.15 Exercise 2.16 The Ecosystem Project Oscillation Gala by Bridget Riley, 1974; acrylic on canvas, 159.7 × 159.7 cm Angles What Is Pi? Exercise 3.1 Angular Motion Example 3.1: Angular Motion Using rotate() Exercise 3.2 Example 3.2: Forces with (Arbitrary) Angular Motion Exercise 3.3 Trigonometry Functions Pointing in the Direction of Movement Example 3.3: Pointing in the Direction of Motion Exercise 3.4 Polar vs. Cartesian Coordinates Example 3.4: Polar to Cartesian Exercise 3.5 Exercise 3.6 Properties of Oscillation Example 3.5: Simple Harmonic Motion I Exercise 3.7 Oscillation with Angular Velocity Example 3.6: Simple Harmonic Motion II Example 3.7: Oscillator Objects Exercise 3.8 Exercise 3.9 Waves Example 3.8: Static Wave Example 3.9: The Wave Exercise 3.10 Exercise 3.11 Exercise 3.12 Spring Forces Example 3.10: A Spring Connection Exercise 3.13 Exercise 3.14 The Pendulum Example 3.11: Swinging Pendulum Exercise 3.15 Exercise 3.16 Exercise 3.17 The Ecosystem Project Particle Systems Positron (photo by Carl D. Anderson) Why Particle Systems Matter A Single Particle Example 4.1: A Single Particle Exercise 4.1 Exercise 4.2 An Array of Particles Example 4.2: An Array of Particles A Particle Emitter Example 4.3: A Single Particle Emitter Exercise 4.3 Exercise 4.4 A System of Emitters Example 4.4: A System of Systems Exercise 4.5 Exercise 4.6 Inheritance and Polymorphism Inheritance Basics Polymorphism Basics Particles with Inheritance and Polymorphism Exercise 4.7 Example 4.5: A Particle System with Inheritance and Polymorphism Exercise 4.8 Particle Systems with Forces Example 4.6: A Particle System with Forces Particle Systems with Repellers Example 4.7: A Particle System with a Repeller Exercise 4.9 Exercise 4.10 Image Textures and Additive Blending Example 4.8: An Image-Texture Particle System Exercise 4.11 Exercise 4.12 Example 4.9: Additive Blending Exercise 4.13 Exercise 4.14 The Ecosystem Project Autonomous Agents Mo’i fish (photo courtesy of the US National Oceanic and Atmospheric Administration) Forces from Within Vehicles and Steering Why Vehicles? The Steering Force Example 5.1: Seeking a Target Exercise 5.1 Exercise 5.2 Exercise 5.3 The Arrive Behavior Example 5.2: Arriving at a Target Your Own Behaviors Exercise 5.4 Example 5.3: “Stay Within Walls” Steering Behavior Exercise 5.5 Flow Fields Exercise 5.6 Example 5.4: Flow-Field Following Exercise 5.7 Exercise 5.8 Path Following The Dot Product Exercise 5.9 Simple Path Following Example 5.5: Creating a Path Object Example 5.6: Simple Path Following Path Following with Multiple Segments Example 5.7: Path Made of Multiple Line Segments Exercise 5.10 Example 5.8: Path Following Exercise 5.11 Complex Systems Implementing Group Behaviors (or: Let’s Not Run Into Each Other) Example 5.9: Separation Exercise 5.12 Exercise 5.13 Combining Behaviors Example 5.10: Combining Steering Behaviors (Seek and Separate) Exercise 5.14 Flocking Exercise 5.15 Example 5.11: Flocking Exercise 5.16 Exercise 5.17 Exercise 5.18 Exercise 5.19 Algorithmic Efficiency (or: Why Does My Sketch Run So Slowly?) Spatial Subdivisions Example 5.12: Bin-Lattice Spatial Subdivision Example 5.13: Quadtree Exercise 5.20 More Optimization Tricks Use the Magnitude Squared Calculate Sine and Cosine Lookup Tables Example 5.14: Sin/Cos Lookup Table Don’t Make Gazillions of Unnecessary p5.Vector Objects Exercise 5.21 The Ecosystem Project Physics Libraries Living root bridges (photo by Arshiya Urveeja Bose) Why Use a Physics Library? Other Physics Libraries Importing the Matter.js Library Matter.js Overview Engine Object Destructuring Bodies Exercise 6.1 Render Example 6.1: Matter.js Default Render and Runner Matter.js with p5.js Example 6.2: A Comfortable and Cozy p5.js Sketch That Needs a Little Matter.js Step 1: Add Matter.js to the p5.js Sketch Step 2: Link Every Box Object with a Matter.js Body Step 3: Draw the Body Exercise 6.2 Static Matter.js Bodies Example 6.3: Falling Boxes Hitting Boundaries Polygons and Groups of Shapes Example 6.4: Polygon Shapes Exercise 6.3 Example 6.5: Multiple Shapes on One Body Exercise 6.4 Matter.js Constraints Distance Constraints Example 6.6: Matter.js Pendulum Exercise 6.5 Revolute Constraints Example 6.7: Spinning Windmill Exercise 6.6 Mouse Constraints Example 6.8: MouseConstraint Demonstration Adding More Forces Example 6.9: Attraction with Matter.js Exercise 6.7 Exercise 6.8 Collision Events Example 6.10: Collision Events Exercise 6.9 A Brief Interlude: Integration Methods Verlet Physics with Toxiclibs.js Vectors The Physics World Particles Springs Example 6.11: Simple Spring with Toxiclibs.js Soft-Body Simulations A String Example 6.12: Soft Swinging Pendulum Exercise 6.10 A Soft-Body Character Example 6.13: Soft-Body Character Exercise 6.11 A Force-Directed Graph Example 6.14: Cluster Exercise 6.12 Exercise 6.13 Attraction and Repulsion Behaviors Example 6.15: Attraction (and Repulsion) Behaviors Exercise 6.14 The Ecosystem Project Cellular Automata Kente cloth (photo by ZSM) What Is a Cellular Automaton? Elementary Cellular Automata Defining Rulesets Programming an Elementary CA Drawing an Elementary CA Example 7.1: Wolfram Elementary Cellular Automata Exercise 7.1 Exercise 7.2 Exercise 7.3 Exercise 7.4 Wolfram Classification Class 1: Uniformity Class 2: Repetition Class 3: Random Class 4: Complexity The Game of Life The Rules of the Game The Implementation Example 7.2: Game of Life Exercise 7.5 Exercise 7.6 Exercise 7.7 Object-Oriented Cells Example 7.3: Object-Oriented Game of Life Variations on Traditional CA Nonrectangular Grids Exercise 7.8 Probabilistic Exercise 7.9 Continuous Exercise 7.10 Image Processing Exercise 7.11 Historical Exercise 7.12 Moving Cells Exercise 7.13 Nesting Exercise 7.14 The Ecosystem Project Fractals Chakri Maha Prasat Hall, Bangkok, Thailand (photo by Saad Akhtar) What Is a Fractal? The Mandelbrot Set Recursion Implementing Recursive Functions Example 8.1: Recursive Circles Once Example 8.2: Recursive Circles Twice Example 8.3: Recursive Circles Four Times Drawing the Cantor Set with Recursion Example 8.4: The Cantor Set Exercise 8.1 The Koch Curve The Monster Curve Example 8.5: The Koch Curve Exercise 8.2 Exercise 8.3 Exercise 8.4 Exercise 8.5 Trees The Deterministic Version Exercise 8.6 Example 8.6: A Recursive Tree Exercise 8.7 Exercise 8.8 The Stochastic Version Example 8.7: A Stochastic Tree Exercise 8.9 Exercise 8.10 L-systems Example 8.8: Simple L-system Sentence Generation Example 8.9: An L-system Exercise 8.11 Exercise 8.12 Exercise 8.13 The Ecosystem Project Evolutionary Computing Pueblo pottery (photo courtesy of the National Park Service) Genetic Algorithms: Inspired by Actual Events Why Use Genetic Algorithms? Exercise 9.1 How Genetic Algorithms Work Step 1: Population Creation Step 2: Selection Step 3: Reproduction Step 4: Repetition! Coding the Genetic Algorithm Step 1: Initialization Step 2: Selection Exercise 9.2 Exercise 9.3 Exercise 9.4 Step 3: Reproduction (Crossover and Mutation) Exercise 9.5 Putting It All Together Example 9.1: Genetic Algorithm for Evolving Shakespeare Exercise 9.6 Exercise 9.7 Customizing Genetic Algorithms Key 1: The Global Variables Key 2: The Fitness Function Exercise 9.8 Key 3: The Genotype and Phenotype Evolving Forces: Smart Rockets Developing the Rockets Managing the Population Example 9.2: Smart Rockets Making Improvements Example 9.3: Smarter Rockets Exercise 9.9 Exercise 9.10 Exercise 9.11 Exercise 9.12 Interactive Selection Example 9.4: Interactive Selection Exercise 9.13 Exercise 9.14 Ecosystem Simulation Genotype and Phenotype Selection and Reproduction Example 9.5: An Evolving Ecosystem The Ecosystem Project Neural Networks Khipu on display at the Machu Picchu Museum, Cusco, Peru (photo by Pi3.124) Introducing Artificial Neural Networks How Neural Networks Work Machine Learning Libraries The Perceptron Perceptron Steps Step 1: Weight the Inputs Step 2: Sum the Inputs Step 3: Generate the Output Putting It All Together Simple Pattern Recognition Using a Perceptron The Perceptron Code Example 10.1: The Perceptron Exercise 10.1 Exercise 10.2 Exercise 10.3 Putting the “Network” in Neural Network Machine Learning with ml5.js The Machine Learning Life Cycle Classification and Regression Network Design ml5.js Syntax Building a Gesture Classifier Collecting and Preparing the Data Exercise 10.4 Choosing a Model Training the Model Callbacks Evaluating the Model Tuning the Parameters Deploying the Model Example 10.2: Gesture Classifier Exercise 10.5 Exercise 10.6 Exercise 10.7 The Ecosystem Project Neuroevolution Star-nosed moles (courtesy of New York Public Library, c. 1826–1828) Reinforcement Learning Evolving Neural Networks Is NEAT! Coding Flappy Bird Example 11.1: Flappy Bird Clone Exercise 11.1 Neuroevolutionary Flappy Bird The Bird Brain Variation: A Flock of Flappy Birds GPU vs. CPU Selection: Flappy Bird Fitness Heredity: Baby Birds Example 11.2: Flappy Bird with Neuroevolution Exercise 11.2 Exercise 11.3 Steering the Neuroevolutionary Way Example 11.3: Smart Rockets with Neuroevolution Exercise 11.4 Responding to Change Speeding Up Time Example 11.4: Dynamic Neuroevolutionary Steering A Neuroevolutionary Ecosystem Sensing the Environment Example 11.5: A Bloop with Sensors Learning from the Sensors Example 11.6: A Neuroevolutionary Ecosystem The Ecosystem Project The End Appendix: Creature Design Additional Resources Credits THE NATURE OF CODE. Image Credits
دانلود کتاب The Nature of Code