Skip to content

Commit

Permalink
fixing def lists, chapter 1, and updating PDF images
Browse files Browse the repository at this point in the history
  • Loading branch information
shiffman committed Aug 3, 2012
1 parent 51183fa commit 0e14451
Show file tree
Hide file tree
Showing 96 changed files with 57 additions and 56 deletions.
28 changes: 14 additions & 14 deletions raw/book.asc
@@ -1,38 +1,38 @@
The Nature of Code
==================

toc::[]
//toc::[]

include::chapters/math.asc[]
//include::chapters/math.asc[]

//include::mathnotation.asc[]

include::chapters/intro.asc[]
//include::chapters/intro.asc[]

include::chapters/01_vectors.asc[]
//include::chapters/01_vectors.asc[]

include::chapters/02_forces.asc[]
//include::chapters/02_forces.asc[]

include::chapters/03_oscillation.asc[]
//include::chapters/03_oscillation.asc[]

include::chapters/04_particles.asc[]
//include::chapters/04_particles.asc[]

include::chapters/05_physicslib.asc[]
//include::chapters/05_physicslib.asc[]

include::chapters/06_steering.asc[]
//include::chapters/06_steering.asc[]

include::chapters/07_ca.asc[]
//include::chapters/07_ca.asc[]

include::chapters/08_fractals.asc[]
//include::chapters/08_fractals.asc[]

include::chapters/09_ga.asc[]
//include::chapters/09_ga.asc[]

include::chapters/10_nn.asc[]
//include::chapters/10_nn.asc[]

//include::test_code.asc[]

//include::break_test.asc[]

//include::tables.asc[]

//include::scratch.asc[]
include::scratch.asc[]
25 changes: 13 additions & 12 deletions raw/chapters/01_vectors.asc
Expand Up @@ -10,10 +10,7 @@ This book is all about looking at the world around us and coming up with clever

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 are 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:

[NOTE]
==============================
A vector is an entity that has both magnitude and direction
==============================
[highlight]*A vector is 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.

Expand All @@ -34,33 +31,37 @@ image::imgs/chapter01/ch01_ex01.png[classname="screenshot",canvas="processingjs/

[source,java]
----
// Variables for location and speed of ball.
//[full] Variables for location and speed of ball.
float x = 100;
float y = 100;
float xspeed = 1;
float yspeed = 3.3;
//[end]
// Remember how Processing works? setup() is executed once when the sketch starts and draw() loops forever and ever (until you quit).
//[full] Remember how Processing works? setup() is executed once when the sketch starts and draw() loops forever and ever (until you quit).
void setup() {
size(200,200);
smooth();
background(255);
}
//[end]
void draw() {
background(255);
// Move the ball according to its speed.
//[full] Move the ball according to its speed.
x = x + xspeed;
y = y + yspeed;
//[end]
// Check for bouncing
//[full] Check for bouncing
if ((x > width) || (x < 0)) {
xspeed = xspeed * -1;
}
if ((y > height) || (y < 0)) {
yspeed = yspeed * -1;
}
//[end]
stroke(0);
fill(175);
Expand Down Expand Up @@ -125,10 +126,10 @@ image::imgs/chapter01/ch01_02.png[Figure 1.2]

[NOTE]
=====================================================================
( 3, 4) —> Walk three steps east, turn and walk five steps north. +
( 2,-1) —> Walk two steps east, turn and walk one step south. +
(-15, 3) —> Walk fifteen steps west, turn and walk three steps north. +
=====================================================================
(-15, 3):: _Walk fifteen steps west, turn and walk three steps north._
(3, 4):: _Walk three steps east, turn and walk five steps north._
(2, -1):: _Walk two steps east, turn and walk one step south._
=====================================================================

You’ve probably done this before when programming motion. For every frame of animation (i.e. a single cycle through Processing’s [function]*draw()* loop), you instruct each object on the screen to move a certain number of pixels horizontally and a certain number of pixels vertically.

Expand Down
22 changes: 14 additions & 8 deletions raw/chapters/intro.asc
Expand Up @@ -125,9 +125,10 @@ Finally, during each cycle through [function]*draw()*, we ask the Walker to take
[source,java]
----
void draw() {
// Call functions on the Walker.
//[full] Call functions on the Walker.
w.step(); // [bold]
w.display(); // [bold]
//[end]
}
----

Expand All @@ -145,9 +146,10 @@ To implement a walker that can step to any neighboring pixel (or stay put) we co
[source,java]
----
void step() {
// Yields -1, 0, or 1
int stepx = int(random(3))-1;
//[full] Yields -1, 0, or 1
int stepx = int(random(3))-1;
int stepy = int(random(3))-1;
//[end]
x += stepx;
y += stepy;
}
Expand All @@ -158,9 +160,10 @@ Taking this a step further, we could use floating point numbers (i.e. decimal nu
[source,java]
----
void step() {
// Yields any floating point number between -1.0 and 1.0
//[full] Yields any floating point number between -1.0 and 1.0
float stepx = random(-1, 1);
float stepy = random(-1, 1);
//[end]
x += stepx;
y += stepy;
}
Expand Down Expand Up @@ -515,10 +518,11 @@ float montecarlo() {
// Pick a second random value.
float r2 = random(1);
// Does it qualify? If so, we’re done!
//[full] Does it qualify? If so, we’re done!
if (r2 < probability) {
return r1;
}
//[end]
}
}
----
Expand Down Expand Up @@ -681,13 +685,15 @@ class Walker {
}
void step() {
// x- and y-location mapped from noise
//[full] x- and y-location mapped from noise
x = map(noise(tx), 0, 1, 0, width);
y = map(noise(ty), 0, 1, 0, height);
//[end]
// Move forward through “time.”
tx += 0.01;
//[full] Move forward through “time.”
tx += 0.01;
ty += 0.01;
//[end]
}
}
----
Expand Down
Binary file modified raw/noc_pdf/imgs/chapter01/ch01_03.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter02/ch02_01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter02/ch02_02.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter02/ch02_03.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter02/ch02_06.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter02/ch02_07.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter02/ch02_08.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter02/ch02_09.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter03/ch03_05.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter03/ch03_08.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter03/ch03_10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter03/ch03_11.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter03/ch03_15.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter04/ch04_01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter04/ch04_02.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_03.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_04.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_06.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_07.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_08.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_09.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_11.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_12.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_13.png
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_14.png
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_15.png
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_16.png
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_17.png
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_18.png
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_exc04.png
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_exc07.png
Binary file modified raw/noc_pdf/imgs/chapter05/ch05_exc15.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_05.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_06.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_07.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_08.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_09.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_10.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_11.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_13.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_14.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_18.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_19.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_20.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_21.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_22.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_26.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_27.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_28.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_30.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_31.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_32.png
Binary file modified raw/noc_pdf/imgs/chapter06/ch06_39.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_01.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_03.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_04.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_05.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_06.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_07.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_08.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_09.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_10.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_11.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_22.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_24.png
Binary file modified raw/noc_pdf/imgs/chapter07/ch07_25.png
Binary file modified raw/noc_pdf/imgs/chapter08/ch08_14.png
Binary file modified raw/noc_pdf/imgs/chapter08/ch08_16.png
Binary file modified raw/noc_pdf/imgs/chapter08/ch08_17.png
Binary file modified raw/noc_pdf/imgs/chapter08/ch08_18.png
Binary file modified raw/noc_pdf/imgs/chapter08/ch08_19.png
Binary file modified raw/noc_pdf/imgs/chapter08/ch08_21.png
Binary file removed raw/noc_pdf/imgs/chapter08/ch08_ex11.png
Diff not rendered.
Binary file modified raw/noc_pdf/imgs/chapter09/ch09_03.png
Binary file modified raw/noc_pdf/imgs/chapter09/ch09_04.png
Binary file modified raw/noc_pdf/imgs/chapter09/ch09_05.png
Binary file modified raw/noc_pdf/imgs/chapter09/ch09_06.png
Binary file modified raw/noc_pdf/imgs/chapter09/ch09_07.png
Binary file modified raw/noc_pdf/imgs/chapter09/ch09_14.png
Binary file modified raw/noc_pdf/imgs/chapter09/ch09_15.png
Binary file removed raw/noc_pdf/imgs/chapter09/chapter09_09.png
Diff not rendered.
Binary file modified raw/noc_pdf/imgs/chapter10/ch10_01.png
Binary file modified raw/noc_pdf/imgs/chapter10/ch10_02.png
Binary file modified raw/noc_pdf/imgs/chapter10/ch10_03.png
Binary file modified raw/noc_pdf/imgs/chapter10/ch10_05.png
Binary file modified raw/noc_pdf/imgs/chapter10/ch10_06.png
Binary file modified raw/noc_pdf/imgs/chapter10/ch10_07.png
Binary file modified raw/noc_pdf/imgs/chapter10/ch10_12.png
Binary file modified raw/noc_pdf/imgs/chapter10/ch10_13.png
6 changes: 3 additions & 3 deletions raw/noc_pdf/stylesheets/print.css
Expand Up @@ -542,15 +542,15 @@ dt, dd {
}

dt {
width:30%;
width:20%;
}

dd {
width:70%;
width:80%;
}

dd p {
font-size: 1.2em;
font-size: 9pt;
line-height: 1em;
margin: 0;
padding: 0;
Expand Down
32 changes: 13 additions & 19 deletions raw/scratch.asc
Expand Up @@ -4,23 +4,17 @@ Chapter 2. Forces
== A heading


Some regular text with the right font
[NOTE]
=====================================================================
(-15, 3):: _Walk fifteen steps west, turn and walk three steps north._
(3, 4):: _Walk three steps east, turn and walk five steps north._
(2, -1):: _Walk two steps east, turn and walk one step south._
=====================================================================

++++
<table class="code">
<tr>
<th>PVector</th>
<th>Vec2</th>
</tr>
<tr>
<td>
hello
</td>
<td>
hello
</td>
</tr>
</table>
++++

Fixed.
[NOTE]
=====================================================================
Acceleration:: _xacceleration and yacceleration_
Target location:: _xtarget and ytarget_
Wind:: _xwind and ywind_
Friction:: _xfriction and yfriction_
=====================================================================

0 comments on commit 0e14451

Please sign in to comment.