Дэниел шифман природа кода

The Nature of Code

This book is all about looking at the world around us and coming up with clever ways to simulate that world with code. Divided into three parts, the book will start by looking at basic physics—how an apple falls from a tree, a pendulum swings in the air, the earth revolves around the sun, etc. Absolutely everything contained within the first five chapters of this book requires the use of the most basic building block for programming motion—the vector. And so this is where we begin our story.

Now, the word vector can mean a lot of different things. Vector is the name of a New Wave rock band formed in Sacramento, CA in the early 1980s. It’s the name of a breakfast cereal manufactured by Kellogg’s Canada. In the field of epidemiology, a vector is used to describe an organism that transmits infection from one host to another. In the C++ programming language, a vector (std::vector) is an implementation of a dynamically resizable array data structure. While all these definitions are interesting, they’re not what we’re looking for. What we want is called a Euclidean vector (named for the Greek mathematician Euclid and also known as a geometric vector). When you see the term “vector” in this book, you can assume it refers to a Euclidean vector, defined as an entity that has both magnitude and direction.

A vector is typically drawn as a arrow; the direction is indicated by where the arrow is pointing, and the magnitude by the length of the arrow itself.

Nature of Code Image

Figure 1.1: A vector (drawn as an arrow) has magnitude (length of arrow) and direction (which way it is pointing).

In the above illustration, the vector is drawn as an arrow from point A to point B and serves as an instruction for how to travel from A to B.

Читайте также:  Вид министерства природных ресурсов

1.1 Vectors, You Complete Me

Before we dive into more of the details about vectors, let’s look at a basic Processing example that demonstrates why we should care about vectors in the first place. If you’ve read any of the introductory Processing textbooks or taken a class on programming with Processing (and hopefully you’ve done one of these things to help prepare you for this book), you probably, at one point or another, learned how to write a simple bouncing ball sketch.

Your browser does not support the canvas tag.

If you are reading this book as a PDF or in print, then you will only see screenshots of the code. Motion, of course, is a key element of our discussion, so to the extent possible, the static screenshots will include trails to give a sense of the behavior. For more about how to draw trails, see the code examples available for download.

Example 1.1: Bouncing ball with no vectors

float x = 100; float y = 100; float xspeed = 1; float yspeed = 3.3;

Remember how Processing works? setup() is executed once when the sketch starts and draw() loops forever and ever (until you quit).

void setup()  size(640,360); background(255); >
 x = x + xspeed; y = y + yspeed;

Источник

The Nature of Code

The Nature of Code cover image

How can we use code to capture the unpredictable properties of nature? How can understanding the mathematical principles behind our physical world help us create interesting digital environments? Written by “The Coding Train” YouTube star Daniel Schiffman, The Nature of Code is a beginner-friendly creative coding tutorial that explores a range of programming strategies for developing computer simulations of natural systems—from elementary concepts in math and physics to sophisticated machine-learning algorithms.

Using the same enthusiastic style on display in Schiffman’s popular YT channel, this book makes learning to program fun, empowering you to generate fascinating graphical output while refining your problem-solving and algorithmic-thinking skills. You’ll progress from building a basic physics engine that simulates the effects of forces like gravity and wind resistance, to creating evolving systems of intelligent autonomous agents that can learn from their mistakes and adapt to their environment.

The Nature of Code introduces important topics such as:

  • Randomness
  • Forces and vectors
  • Trigonometry
  • Cellular automata and fractals
  • Genetic algorithms
  • Neural networks

Learn from an expert how to transform your beginner-level skills into writing well-organized, thoughtful programs that set the stage for further experiments in generative design.

NOTE: All examples are written with p5.js, a JavaScript library for creative coding, and are available on the book’s website.

Daniel Shiffman is an Associate Arts Professor at ITP/IMA, Tisch School of the Arts, NYU. He is a director of The Processing Foundation and the author of Learning Processing: A Beginner’s Guide to Programming Images, Animation, and Interaction and The Nature of Code , an open source book about simulating natural phenomenon with code. On his YouTube channel, The Coding Train , he publishes «creative coding» tutorials with subjects ranging from the basics of programming languages like JavaScript (with p5.js) and Java (with Processing) to generative algorithms like physics simulation, computer vision, and data visualization.

Introduction
Chapter 0: Randomness
Chapter 1: Vectors
Chapter 2: Forces
Chapter 3: Oscillation
Chapter 4: Particle Systems
Chapter 5: Autonomous Agents
Chapter 6: Physics Libraries
Chapter 7: Cellular Automata
Chapter 8: Fractals
Chapter 9: Evolutionary Computing
Chapter 10: Neural Networks

The chapters in red are included in this Early Access PDF.

Источник

The Nature of Code

Hello! By browsing the table of contents on your left, you can read the entire text of this book online for free, licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.

If you like this book, please consider supporting it via the links below:

Nature of Code Image

Nature of Code Image

Please submit corrections to the book on my Nature of Code GitHub repo. Bug reports for the site and online purchasing system can be reported on GitHub as well.

Copyright © 2012 by Daniel Shiffman

ISBN-13: 978-0985930806
ISBN-10: 0985930802

This work is licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported License. To view a copy of this license, visit creativecommons.org or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California 94041, USA.

All of the book’s source code is licensed under the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This book was generated by the Magic Book Project.

Editorial and Design Assistant

Magic Book Lead Developers

Evan Emolo, Miguel Bermudez, Luisa Peirera Hors

Licenses

All of the book’s source code is licensed under the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

Colophon

This book was generated with The Magic Book Project.

This book would not have been possible without the generous support of Kickstarter backers.

This book is typeset on the web in Georgia with headers in Proxima Nova.

Please report any mistakes in the book or bugs in the source with a GitHub issue or contact me at daniel at shiffman dot net .

Author

Daniel Shiffman is a professor of the Interactive Telecommunications Program at New York University.

Источник

Оцените статью