Skip to content
This repository was archived by the owner on Sep 22, 2024. It is now read-only.

Commit 6278fd5

Browse files
committed
sorting out merge
2 parents 4859d21 + 5042936 commit 6278fd5

File tree

410 files changed

+87988
-546051
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+87988
-546051
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 The Nature of Code
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
14
<head>
5+
<<<<<<< HEAD
26
<script language="javascript" type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.js"></script>
37
<script language="javascript" type="text/javascript" src="sketch.js"></script>
48
<title> Random Walk Traditional </title>
59
</head>
610

711
<body>
812
</body>
13+
=======
14+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
15+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
16+
<meta charset="utf-8" />
17+
</head>
18+
19+
<body>
20+
<script src="sketch.js"></script>
21+
</body>
22+
23+
</html>
24+
>>>>>>> master
Binary file not shown.

chp00_introduction/NOC_I_01_RandomWalkTraditional/sketch.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@
22
// Daniel Shiffman
33
// http://natureofcode.com
44

5-
var walker;
5+
let walker;
66

77
function setup() {
8-
createCanvas(640,360); //creating canvas of size 640 x 360
9-
walker = new Walker(); //creating an instance/object of class Walker
10-
background(127); // creating a grey background for canvas
8+
createCanvas(640, 360);
9+
walker = new Walker();
10+
background(127);
1111
}
1212

1313
function draw() {
1414
walker.step();
1515
walker.render();
1616
}
1717

18-
function Walker() {
19-
this.x = width/2; //width gives width of canvas
20-
this.y = height/2; //height gives height of canvas
18+
class Walker {
19+
constructor() {
20+
this.x = width / 2;
21+
this.y = height / 2;
22+
}
2123

22-
this.render = function() {
23-
stroke(0); //stroke with a color of black
24-
point(this.x,this.y); //plot a point,takes 2 parameters x and y
25-
};
24+
render() {
25+
stroke(0);
26+
point(this.x, this.y);
27+
}
2628

27-
this.step = function() {
28-
var choice = floor(random(4)); //return a random number between 0 and 4(exclusive)
29+
step() {
30+
var choice = floor(random(4));
2931
if (choice === 0) {
3032
this.x++;
3133
} else if (choice == 1) {
@@ -35,7 +37,7 @@ function Walker() {
3537
} else {
3638
this.y--;
3739
}
38-
this.x = constrain(this.x,0,width-1); //making sure the x value of plotted point lies between 0 and canvas width
39-
this.y = constrain(this.y,0,height-1);//making sure the y value of plotted point lies between 0 and canvas height
40-
};
40+
this.x = constrain(this.x, 0, width - 1);
41+
this.y = constrain(this.y, 0, height - 1);
42+
}
4143
}
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
<head>
2-
<script language="javascript" type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.js"></script>
3-
<script language="javascript" type="text/javascript" src="sketch.js"></script>
4-
<title>Random Distribution</title>
5-
</head>
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
5+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
6+
<meta charset="utf-8" />
7+
</head>
68

7-
<body>
8-
</body>
9+
<body>
10+
<script src="sketch.js"></script>
11+
</body>
12+
</html>
Binary file not shown.
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
21
// The Nature of Code
32
// Daniel Shiffman
43
// http://natureofcode.com
54

65
// An array to keep track of how often random numbers are picked
76

8-
var randomCounts = [];
9-
var total = 20; //Number of random numbers we want to track
7+
let randomCounts = [];
8+
let total = 20;
109

1110
function setup() {
12-
createCanvas(640,360);
13-
for (var i = 0; i < total; i++) {
14-
randomCounts[i] = 0; // initializing all indexes in radomCounts[20] to 0;
11+
createCanvas(640, 360);
12+
for (let i = 0; i < total; i++) {
13+
randomCounts[i] = 0;
1514
}
1615
}
1716

1817
function draw() {
19-
background(127);//clears and re-draws canvas background with grey color
20-
var index = floor(random(total));//return a random number between 0 and total(exclusive)
18+
background(127);
19+
let index = floor(random(total));
2120
randomCounts[index]++;
2221

2322
// Draw a rectangle to graph results
24-
stroke(0); //black stroke
25-
strokeWeight(2); //stroke thickness of 2
26-
fill(255); //fill rectangle with white
27-
28-
29-
var w = width/total; //calculating width of each rectangle/ histogram
23+
stroke(0);
24+
strokeWeight(2);
25+
fill(255);
26+
let w = width / randomCounts.length;
3027

31-
for (var x = 0; x < total; x++) {
32-
rect(x*w,height-randomCounts[x],w-1,randomCounts[x]);
28+
for (let x = 0; x < randomCounts.length; x++) {
29+
rect(x * w, height - randomCounts[x], w - 1, randomCounts[x]);
3330
}
3431
}
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
<head>
2-
<script language="javascript" type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.js"></script>
3-
<script language="javascript" type="text/javascript" src="sketch.js"></script>
4-
<title>Random Walks Tends to right</title>
5-
</head>
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
5+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
6+
<meta charset="utf-8" />
7+
</head>
68

7-
<body>
8-
</body>
9+
<body>
10+
<script src="sketch.js"></script>
11+
</body>
12+
</html>
Binary file not shown.

chp00_introduction/NOC_I_03_RandomWalkTendsToRight/sketch.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,34 @@
22
// Daniel Shiffman
33
// http://natureofcode.com
44

5-
var walker;
5+
let walker;
66

77
function setup() {
8-
createCanvas(640,360); //creating a canvas of size 640 x 360
9-
walker = new Walker(); //creating an instance/object of class Walker
10-
background(127); //setting a background of grey
8+
createCanvas(640, 360);
9+
// Creating the Walker object!
10+
walker = new Walker();
11+
background(127);
1112
}
1213

1314
function draw() {
1415
walker.step();
1516
walker.render();
1617
}
1718

18-
function Walker() {
19-
//initializing the position of walker
20-
this.x = width/2; //width gives width of canvas
21-
this.y = height/2; //width gives height of canvas
19+
class Walker {
20+
constructor() {
21+
this.x = width / 2;
22+
this.y = height / 2;
23+
}
2224

23-
this.render = function() {
24-
stroke(0); //setting color of stroke to black
25-
point(this.x,this.y);
26-
};
25+
render() {
26+
stroke(0);
27+
point(this.x, this.y);
28+
}
2729

28-
this.step = function() {
29-
30-
var r = random(1); //return a random number between 0 and 1(exclusive)
31-
// A 40% of moving to the right!
30+
step() {
31+
let r = random(1);
32+
// A 40% of moving to the right!
3233
if (r < 0.4) {
3334
this.x++;
3435
} else if (r < 0.6) {
@@ -38,7 +39,7 @@ function Walker() {
3839
} else {
3940
this.y--;
4041
}
41-
this.x = constrain(this.x,0,width-1);
42-
this.y = constrain(this.y,0,height-1);
43-
};
42+
this.x = constrain(this.x, 0, width - 1);
43+
this.y = constrain(this.y, 0, height - 1);
44+
}
4445
}

0 commit comments

Comments
 (0)