nature-of-code / noc-book Goto Github PK
View Code? Open in Web Editor NEWThe Nature of Code book (archived repo, see README for new repo / build system!)
Home Page: http://natureofcode.com
The Nature of Code book (archived repo, see README for new repo / build system!)
Home Page: http://natureofcode.com
There is a lot to discuss / work out for code comments and formatting. In the previous version, the book would:
[full]
, [end]
, [offset-down]
, [offset-up]
, [bold]
, etc.Broken link:
<a href="#chapter09_section2">
Source:
https://github.com/shiffman/The-Nature-of-Code/blob/master/chapters/10_nn.html
Note:
The link should point into chapter 9 – not chapter 10.
There are lots of empty <p>
tags throughout the HTML version. Do I remove these?
Hey there!
When you're explaining the drag force equation, you say "Cd is the coefficient of drag, exactly the same as the coefficient of friction (ρ)". Shouldn't it be μ instead of ρ? Just saying though, not sure! :)
The figure captions ended up in the alt=
attribute. This is a minor problem since there are so few but I need to go through the content and make sure they actually show up as captions.
In the code after the text "Taking this further, we could use floating point numbers (i.e. decimal numbers) for x and y instead and move according to an arbitrary random value between -1 and 1." the command
float stepx = random(-1, 1);
should be replaced by
float stepx = random(-1, 2);
Similarly for stepy
.
Has a stray 1 on generation 0.
Working through the Nature of Code w/ p5js. I'm using the p5 editor version 0.5.7
In the vector subtraction example (https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/blob/master/chp01_vectors/NOC_1_03_vector_subtraction/sketch.js)... if I run this code as-is, I see a line blip from the top left corner to center on frame 1, then no other lines. However, if I move the translate() call into setup(), the sketch behaves as expected.
Is this a possible issue with the p5 editor? Or has p5js syntax been updated to change the way translate() works?
Thanks!
If I'm not mistaken, there is a typo on the following page:
http://natureofcode.com/book/chapter-1-vectors/
In the rules box at the end of section 1.4,
"The distributive rule with 2 scalars, 1 vector: (n_m)_v⃗ =n_v⃗ +m_v⃗ ,"
should read,
"The distributive rule with 2 scalars, 1 vector: (n+m)_v⃗ =n_v⃗ +m*v⃗ ."
sin and cosine are inverted in the formula, oops
First of all, I don't want to be considered as a spammer or something. I'm just trying to help. I wonder if you prefer me to create a Github Issue for each little mistake I find or you prefer me reading a lot of the book before creating one? I personally think creating one for each would be the best, since each error would be represented by an Issue. But if you don't prefer like that, I can do the other way around.
Well, what I want to talk about friction is that the way you did, it's happening all the time (you said something like that yourself). But shouldn't it happen only when the object is on a surface? That is easily checkable with an if. I'm sorry doing these questions/issues, it's just I'm really enjoying this book and I want to understand everything well and correct.
Chapter 1. Vectors
Vector multiplication
More Number Properties with Vectors
I think the following sentence
The distributive rule with 2 scalars, 1 vector: (n_m)_v⃗ =n_v⃗ +m_v⃗
should be
The distributive rule with 2 scalars, 1 vector: (n+m)_v⃗ =n_v⃗ +m*v⃗
How do you think?
The initial code for Exercise 1.6 of "The Nature of Code" shows:
float stepsize = random(0,10); \\A uniform distribution of step sizes.
float stepx = random(-stepsize,stepsize);
float stepy = random(-stepsize,stepsize);
x += stepx;
y += stepy;
It seems to me that one would intend for stepx
and stepy
to have uniform distributions between -10 and 10.
As it stands they have triangular distributions.
Perhaps you intend stepx = random(0,10)*(random sign)
?
In the Preface P4, the link to the Magic Book Project is incorrect.
http://www.magicbookproject.com leads to a domain parked page.
The correct URL seems to be https://github.com/runemadsen/Magic-Book-Project
<span class="highlight">
and <span class="formula">
should maybe be divs.
Did we lose all of the indexing during the conversion?
((("natural phenomena","Perlin noise and")))
((("non-uniform distributions","Perlin noise")))
((("distributions, non-uniform","Perlin noise")))
((("Perlin noise","natural phenomena, modeling with")))
((("_Tron_ (1982)")))
In conversion I sometimes see:
<a data-primary="" data-type="indexterm" em=""> </a>
But it's empty.
At the beginning of "I.4 A Normal Distribution of Random Numbers", it is said:
A distribution of values that cluster around an average (referred to as the “mean”) is known as a “normal” distribution.
This is very misleading, because a distribution of values that cluster around an average is not necessarily a normal distribution. There are maaaany other distributions that are also clustered around the mean (exples: the Cauchy distribution, the Laplace distribution, the t-distribution...)
A normal distribution is one of these, yes, but a very special case and the "clustered around the mean" is by no means its definition.
is this still valid / correct for atlas?
<div style="page-break-after:always;"> </div>
First of all, thanks for doing this book. I'm in love with it, it's totally awesome, great job!
I think there is a mistake on:
http://natureofcode.com/book/chapter-1-vectors/
at "More Number Properties with Vectors". More specifically at "The distributive rule with 2 scalars, 1 vector: (n_m)_v". Shouldn't it be:
The distributive rule with 2 scalars, 1 vector: (n+m)*v ??? Or am I wrong? If I am, sorry about this ^^
In section 2.8 Air and Fluid Resistance (page 85), at the bottom of the page with the if() block, it says:
if (movers[i].isInside(liquid)) {movers[i].drag(liquid);}
But in the code example that correspond to this section, you have the function "boolean Liquid.contains(Mover m)" instead of "boolean Mover.isInside(Liquid liquid)".
Also, instead of "Mover.drag(Liquid)" like you have in the book, the code example uses "Liquid.drag(Mover m)".
Basically, the placement of Mover and Liquid classes don't match up between page 85 and the code examples, as well as a function name change. These typos carry over into page 86, where you talk about adding functions to the Mover class, functions that are written in the Liquid class in the examples.
In chapter 6 there is a "the the" typo:
Complex systems often include a feedback loop where the the output of the system....
I.4
The standard deviation percentages are off.
"68% of the members of that population will have values in the range of one standard deviation from the mean, 98% within two standard deviations, and 99.7% within three standard deviations."
Second number should be 95%.
https://en.wikipedia.org/wiki/68%E2%80%9395%E2%80%9399.7_rule
Question for @runemadsen about https://github.com/magicbookproject/magicbook.
In the first edition of NOC, the ASCIIDOC would resolve to CSS classes, i.e.
<div class="note" id="pseudo-random-numbers-o1bcX">
<h1>Pseudo-Random Numbers</h1>
</div>
The version I have now written in HTMLBook looks like:
<div data-type="note" id="pseudo-random-numbers-o1bcX">
<h1>Pseudo-Random Numbers</h1>
</div>
My old CSS is:
.note {
font-size: 10pt;
}
But I think it should now be:
[data-type="note"] {
font-size: 10pt;
}
I ask b/c this question applies across the board to just about everything. Is one of these preferable? Should adjust my CSS to use data attributes? Or adjust my HTML to go back to classes?
A link on this page appears to be broken: http://natureofcode.com/book/further-reading/
The link in question is : http://www.processing.org/learning/books
in the sentence "For other books that use Processing, see Processing Books."
I think the correct link could be: https://processing.org/books/
Hi Daniel,
This is a great book. Thanks for publishing it.
I was going through the first chapter while writing my own code in Java and noticed something rather inefficient in "1.9 Static vs. Non-Static Functions".
The problem is that these static methods create new instances of PVector every time you call them, which could happen 60 time per second when you animate a moving object and a lot more frequently if you have a complex scene. These temporary objects would soon have to be discarded and there would be a lot of work for the Garbage collector.
As an alternative I would recommend using a copyFrom method similar to this:
PVector copyFrom(PVector v) {
x = v.x;
y = v.y;
return this;
}
That method can be combined with using a temporary vector that is reused over and over without having to instantiate new objects. For example:
class MyAnimation
{
PVector v;
PVector u;
PVector tmp;
public MyAnimation()
{
v = new PVector(0,0);
u = new PVector(4,5);
tmp = new PVector(0,0);
}
void update()
{
tmp.copyFrom(u);
tmp.add(v);
// At this point you have the sum of u and v in tmp
// while the original two vectors remain unchanged
}
}
Hope this helps,
Vihren
Hello! Love this book.
Just wanted to query what you've written in Chapter 1 for the distributive rule:
The distributive rule with 2 scalars, 1 vector: (n*m)*v⃗ =n*v⃗ + m*v⃗
Did you mean this instead?
The distributive rule with 2 scalars, 1 vector: (n+m)*v⃗ =n*v⃗ + m*v⃗
Not every monkey will have a equal chance of reproducing.
Which should probably be:
Not every monkey will have an equal chance of reproducing.
new kind of science?
In the acknowledgments, the word "inspiration" appears as "inspiratio".
Thanks!
I need a way to deal with math notation. The previous solution used ASCIIDOC variables. For example:
In other words: {wuplusv}
can be written as: {wxuxplusvx}
{wyuyplusvy}
Then, replacing u and v with their values from Figure 1.6, we get: {wx53}
{wy24}
which means that:
{wx8} {wy6}
Finally, we write that as a vector: {w86}
These variables held elaborate SVG markup for the print, but rendered to MathML with MathJax for HTML.
https://github.com/shiffman/The-Nature-of-Code-archive/blob/master/raw/chapters/mathsvgfiles.asc
https://github.com/shiffman/The-Nature-of-Code-archive/blob/master/raw/chapters/math.asc
First off this is a great book. I've been trying to get to grips with the physics of vectors and force for years now and this is the first presentation of the topic that has actually made sense to me.
One small request; your in-browser code examples, while helpful, eat up a lot of CPU and thus laptop battery power. They only kick off once they scroll into view, which is great, but they keep going once you've scrolled past them.
Since some of the chapters are very long I tend to wind up leaving the tab open for days at a time. Since they contain numerous running code examples this can add up to a lot of wasted cycles and quickly drained batteries unless I remember to refresh the page or manually pause each example as I go.
Could you alter the JS used to run the examples so that they pause execution when you scroll them off-screen?
On the website, the image for figure 1.10 doesn't load in Chapter 1: Vectors:
<img src="imgs/chapter01/ch01_10.png" alt="Nature of Code Image">
Based on the other image paths on the page, I think it's just missing /book/
at and start so it should be:
<img src="/book/imgs/chapter01/ch01_10.png" alt="Nature of Code Image">
via twtter I think I noticed a typo when coding NOC exercises: http://natureofcode.com/book/chapter-6-autonomous-agents/ … 6.16 -- shouldn't it be "PVector.random2D();" ?
In chapter 3, oscillation, why is atan being passed in x/y, shouldn't it be y/x?
V1 ⇒ angle = atan(-4/3) = atan(-1.25) = -0.9272952 radians = -53 degrees
V2 ⇒ angle = atan(4/-3) = atan(-1.25) = -0.9272952 radians = -53 degrees
I'm checking out the book because I'd like to use it to explain Vectors to my students. However I'm pretty new to the subject, so I'm on student level as well.
I was wondering if Example 1.3. could be not more clear? You use a translate(width/2, height/2) to explain the subtraction. However that is a completely different concept (and pretty difficult as well, regarding the matrix). You need to translate, to show the subtract.
However without translate, you don't need the subtraction:
void setup() {
size(640,360);
}
void draw() {
background(255);
//[full] Two PVectors, one for the mouse location and one for the center of the window
PVector mouse = new PVector(mouseX,mouseY);
PVector center = new PVector(width/2,height/2);
//[end]
// PVector subtraction!
//mouse.sub(center);
// Draw a line to represent the vector.
//translate(width/2,height/2);
line(center.x,center.y,mouse.x,mouse.y);
}
I feel that something based on the example from the Processing reference could be more clear:
PVector v1, v2;
void setup() {
size(200,200);
noLoop();
v1 = new PVector(25, 25, 0);
v2 = new PVector(100, 100, 0);
}
void draw() {
ellipse(v1.x, v1.y, 12, 12);
ellipse(v2.x, v2.y, 12, 12);
v2.sub(v1);
ellipse(v2.x, v2.y, 24, 24);
}
Online book, Introduction-1.4 mentions:
Instead, we can make use of a class known as Random, which we get for free as part of the default Java libraries imported into Processing.
To use the Random class, we must first declare a variable of type Random and create the Random object in setup().
Random generator;
void setup() {
size(640,360);
generator = new Random();
}
In Processing 3.0.1 this didn't work for me without importing java.util.Random
to the sketch.
I know this is not part of the examples but I'm posting the issue because I think it can be a source of confusion for beginner readers using the latest version of Processing.
P.S. Thanks a lot for making the book. Can't wait for the next edition!
In the print book, at the bottom of page 34 (chapter 1: Vectors), it reads
Then, replacing u and v with their values from Figure 1.6, we get:
wx = 5 + 3
which means that:
Finally, we write that as a vector:
w = (8, 6)
On the online version, this section reads
Then, replacing u and v with their values from Figure 1.6, we get:
wx = 5 + 3
wy = 2 + 4
which means that:
wx = 8 wy = 6
Finally, we write that as a vector:
w = (8, 6)
Hello Daniel,
There is a segment of code excerpted from the Introduction.
void step() {
//Yields any floating point number between -1.0 and 1.0
float stepx = random(-1, 1);
float stepy = random(-1, 1);
x += stepx;
y += stepy;
}
I think it would causes some misunderstanding. According to the text, it would be easier to conclude that this segment of code has the same effect as this one :
void step() {
int stepx = int(random(3))-1;
int stepy = int(random(3))-1;
x += stepx;
y += stepy;
}
But the program shows that the walker using that code will go up and left, which may not be anticipated by some people.
At first, I was confused, because the probability of taking any direction is not equal. After I read the text several times, I found, actually the text does not state that segment of code would produce the same result. In fact, there is no problem of it. But, if I did not try to run the code, I would think they are no different. And maybe some others would think the same way.
So, instead of using random(-1, 1), I think it would be better to use random(-1, 2) here.
I just want to thank you for providing this wonderful book for free and would like to note a small mistake in section 1.4 where you give an example on calculating mean and standard deviation. The value of the average variance should be 228.81 not 254.23 as mentioned. The value of the standard deviation is correct though.
Thanks
Anis Nazer
In the section where the "enhanced for loop" is first shown, the name of the ArrayList that is created is plist
, but the name of the list that is inside the loop is particles
. Apparently the name plist
comes from the comparison between an array and a list (parray
vs plist
). However, as the name that is used throughout the chapter is particles
, that specific example got a mix of both names.
In the live examples of the online book (e.g. Example I.1: Traditional random walk) when RESET
button is pressed a new sketch is started while the previous one is not disposed; so every RESET
press adds one more active sketch on the same canvas element (in the aforementioned example every RESET
press adds one more random walker).
Walk three steps east; turn and walk five steps north.
recommended revision below
Walk three steps east; turn and walk four steps north.
In NOC 1.0, we had:
<span class="klass">Walker</span>
<span class="function">setup()</span>
<span class="var">x</span>
and probably more?
Right now, the conversion resulted in:
<strong klass="">Walker</strong>
<strong function="">setup()</strong>
<strong class="var">x</strong>
I can do a global regex search/replace, but want to confirm the correct markup.
The graphs above should give us a hint. The graph on the left shows us the distribution with a very low standard deviation, where the majority of the values cluster closely around the mean. The graph on the right shows us a higher standard deviation, where the values are more evenly spread out from the average.
I'm viewing the ePub in Google Play Books which stacks the two graphs on top of each other:
That makes it hard to figure out which one the text is referencing which it says "on the left" or "on the right". Referencing them using their Figure
number would be better.
I manually numbered everything, figures, examples, exercises. How do integrate the Atlas auto-numbering system?
This is sort of a duplicate of #4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.