http://natureofcode.com/book/
## 0 Introduction
### [均匀分布](http://zh.wikipedia.org/wiki/%E7%A6%BB%E6%95%A3%E5%9E%8B%E5%9D%87%E5%8C%80%E5%88%86%E5%B8%83)
**Example 0.1: Traditional random walk**
**Example 0.2: Random number distribution**
**Example 0.3: Walker that tends to move to the right**
### [正态分布](http://zh.wikipedia.org/wiki/%E6%AD%A3%E6%80%81%E5%88%86%E5%B8%83)
[生成算法(Marsaglia Polar Method)](http://en.wikipedia.org/wiki/Marsaglia_polar_method)
**Example 0.4: Gaussian distribution**
### [Perlin噪声](http://zh.wikipedia.org/wiki/Perlin%E5%99%AA%E5%A3%B0)
[Making Noise](http://www.noisemachine.com/talk1/)
[生成算法](http://staffwww.itn.liu.se/~stegu/simplexnoise/DSOnoises.html)
**Example 0.5: Perlin noise walker**
**Example 0.6: 2D Perlin noise**
## 1 Vectors
既有方向(direction)又有大小(magnitude)的量叫做[向量](http://zh.wikipedia.org/wiki/%E7%9F%A2%E9%87%8F)。
位置,方向,速度,加速度,力都可以用向量来表示。
**Example 1.1: Bouncing ball with no vectors**
**Example 1.2: Bouncing ball with Vectors!**
**Example 1.3: Vector subtraction**
**Example 1.4: Multiplying a vector**
**Example 1.5: Vector magnitude**
**Example 1.6: Normalizing a vector**
### 速度 velocity
\`v = s/t\` 单位时间的距离
对于每帧(单位时间),新位置就等于现在的位置加上速度:`loc2 = loc1 + v`
**Example 1.7: Motion 101 (velocity)**
### 加速度 acceleration
\`a = v/t\` 单位时间的速度,速度的变化
对于每帧(单位时间),新速度就等于现在的速度加上加速度:`v2 = v1 + a`
**Example 1.8: Motion 101 (velocity and constant acceleration)**
**Example 1.9: Motion 101 (velocity and random acceleration)**
**Example 1.10: Accelerating towards the mouse**
**Example 1.11: Array of movers accelerating towards the mouse**
## 2 Forces
[牛顿运动定律](http://zh.wikipedia.org/wiki/%E7%89%9B%E9%A1%BF%E8%BF%90%E5%8A%A8%E5%AE%9A%E5%BE%8B)
\`F = ma\` 牛顿第二运动定律
对于单位质量(比如一个像素),加速度就等于力:`F = a`
**Example 2.1: Forces**
**Example 2.2: Forces acting on many objects**
### [重力](http://zh.wikipedia.org/wiki/%E9%87%8D%E9%87%8F)
\`W = mg\`
**Example 2.3: Gravity scaled by mass**
### [摩擦力](http://zh.wikipedia.org/wiki/%E6%BB%91%E5%8A%A8%E6%91%A9%E6%93%A6)
\`f = -μN hat(v)\`
**Example 2.4: Including friction**
### [流体阻力](http://zh.wikipedia.org/wiki/%E9%98%BB%E5%8A%9B%E6%96%B9%E7%A8%8B)
\`F_d = -1/2ρv^2AC_d hat(v)\`
**Example 2.5: Fluid Resistance**
### [万有引力](http://zh.wikipedia.org/wiki/%E7%89%9B%E9%A1%BF%E4%B8%87%E6%9C%89%E5%BC%95%E5%8A%9B%E5%AE%9A%E5%BE%8B)
\`F = G(m_1m_2)/r^2 hat(r)\`
**Example 2.6: Attraction**
**Example 2.7: Attraction with many Movers**
**Example 2.8: Mutual attraction**
## 3 Oscillation
### 角速度及加速度
对于每帧(单位时间),新角度就等于现在的角度加上角速度:`ang2 = ang1 + angv`
对于每帧(单位时间),新角速度就等于现在的角速度加上角加速度:`angv2 = angv1 + anga`
**Example 3.1: Angular motion using rotate()**
**Example 3.2: Forces with (arbitrary) angular motion**
**Example 3.3: Pointing in the direction of motion**
**Example 3.4: Polar to Cartesian**
### [简谐运动](https://zh.wikipedia.org/wiki/简谐运动)
`位置 = 振幅 * sin(2PI * 时间 / 周期)` 时间用当前帧数表示。也可以用线性增长的如速度来表示。
**Example 3.5: Simple Harmonic Motion**
**Example 3.6: Simple Harmonic Motion II**
**Example 3.7: Oscillator objects**
**Example 3.8: Static wave drawn as a continuous line**
**Example 3.9: The Wave**
### [单摆运动](https://zh.wikipedia.org/wiki/%E6%93%BA)
角加速度\`= gsintheta/L\`
**Example 3.10: Swinging pendulum**
### 弹力
\`F_s = -kx\`
**Example 3.11: A Spring connection**
## 10 Neural Networks
### Classification
感知器(Perceptron):最简单的神经网络,只有一个神经元的计算模型,包含一个或多个输入,一个处理器,单个输出。
算法(前向计算):
1. 对每个输入(包括偏差)乘以权重
1. 累加所有权重后的输入得到和
1. 将和通过一个激活函数计算输出
训练过程(循环重复):
1. 提供 Perceptron 带有正确答案 `DESIRED OUTPUT` 的输入
1. 前向计算出 `GUESS OUTPUT`
1. 计算误差: `ERROR = DESIRED OUTPUT - GUESS OUTPUT`
1. 更新所有权重: `NEW WEIGHT = WEIGHT + ERROR * INPUT * LEARNING CONSTANT`
**Example 10.1: The Perceptron**