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

Commit bf4fc4b

Browse files
authored
Merge pull request #125 from ferreira-mariana/master
NOC in ES6: change from var to let
2 parents 33cd32a + 27ada4b commit bf4fc4b

File tree

34 files changed

+164
-164
lines changed

34 files changed

+164
-164
lines changed

chp00_introduction/NOC_I_01_RandomWalkTraditional/sketch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Walker {
2727
}
2828

2929
step() {
30-
var choice = floor(random(4));
30+
let choice = floor(random(4));
3131
if (choice === 0) {
3232
this.x++;
3333
} else if (choice == 1) {

chp01_vectors/NOC_1_10_motion101_acceleration/mover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Mover{
1414

1515
update() {
1616
// Compute a vector that points from position to mouse
17-
var mouse = createVector(mouseX,mouseY);
17+
let mouse = createVector(mouseX,mouseY);
1818
this.acceleration = p5.Vector.sub(mouse,this.position);
1919
// Set magnitude of acceleration
2020
this.acceleration.setMag(0.2);

chp01_vectors/NOC_1_11_motion101_acceleration_array/mover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Mover{
1414

1515
update() {
1616
// Compute a vector that points from position to mouse
17-
var mouse = createVector(mouseX,mouseY);
17+
let mouse = createVector(mouseX,mouseY);
1818
this.acceleration = p5.Vector.sub(mouse,this.position);
1919
// Set magnitude of acceleration
2020
this.acceleration.setMag(0.2);

chp01_vectors/NOC_1_11_motion101_acceleration_array/sketch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let movers = [];
1010

1111
function setup() {
1212
createCanvas(640,360);
13-
for (var i = 0; i < 20; i++) {
13+
for (let i = 0; i < 20; i++) {
1414
movers[i] = new Mover();
1515
}
1616
}

chp02_forces/NOC_2_01_forces/mover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Mover {
1111
}
1212

1313
applyForce(force) {
14-
var f = p5.Vector.div(force, this.mass);
14+
let f = p5.Vector.div(force, this.mass);
1515
this.acceleration.add(f);
1616
}
1717

chp04_systems/NOC_4_02_ArrayParticles/sketch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function draw() {
1313
particles.push(new Particle(createVector(width / 2, 50)));
1414

1515
// Looping through backwards to delete
16-
for (var i = particles.length - 1; i >= 0; i--) {
17-
var p = particles[i];
16+
for (let i = particles.length - 1; i >= 0; i--) {
17+
let p = particles[i];
1818
p.run();
1919
if (p.isDead()) {
2020
//remove the particle

chp04_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/confetti.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Confetti extends Particle {
1313
strokeWeight(2);
1414
push();
1515
translate(this.position.x, this.position.y);
16-
var theta = map(this.position.x, 0, width, 0, TWO_PI * 2);
16+
let theta = map(this.position.x, 0, width, 0, TWO_PI * 2);
1717
rotate(theta);
1818
rect(0, 0, 12, 12);
1919
pop();

chp06_agents/NOC_6_01_Seek/vehicle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class Vehicle {
3434
// STEER = DESIRED MINUS VELOCITY
3535
seek(target) {
3636

37-
var desired = p5.Vector.sub(target, this.position); // A vector pointing from the location to the target
37+
let desired = p5.Vector.sub(target, this.position); // A vector pointing from the location to the target
3838

3939
// Scale to maximum speed
4040
desired.setMag(this.maxspeed);
4141

4242
// Steering = Desired minus velocity
43-
var steer = p5.Vector.sub(desired, this.velocity);
43+
let steer = p5.Vector.sub(desired, this.velocity);
4444
steer.limit(this.maxforce); // Limit to maximum steering force
4545

4646
this.applyForce(steer);

chp06_agents/NOC_6_02_Arrive/vehicle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Vehicle {
3737
let d = desired.mag();
3838
// Scale with arbitrary damping within 100 pixels
3939
if (d < 100) {
40-
var m = map(d, 0, 100, 0, this.maxspeed);
40+
let m = map(d, 0, 100, 0, this.maxspeed);
4141
desired.setMag(m);
4242
} else {
4343
desired.setMag(this.maxspeed);

chp07_CA/Exercise_7_01_WolframCA_randomizedrules/CA.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ function CA(r) {
1515

1616
// Make a random ruleset
1717
this.randomize = function() {
18-
for (var i = 0; i < 8; i++) {
18+
for (let i = 0; i < 8; i++) {
1919
this.ruleset[i] = Math.floor(random(2));
2020
}
2121
};
2222

2323
// Reset to generation 0
2424
this.restart = function() {
25-
for (var i = 0; i < this.cells.length; i++) {
25+
for (let i = 0; i < this.cells.length; i++) {
2626
this.cells[i] = 0;
2727
}
2828
// We arbitrarily start with just the middle cell having a state of "1"
@@ -34,13 +34,13 @@ function CA(r) {
3434
// The process of creating the new generation
3535
this.generate = function() {
3636
// First we create an empty array for the new values
37-
var nextgen = new Array(this.cells.length);
37+
let nextgen = new Array(this.cells.length);
3838
// For every spot, determine new state by examing current state, and neighbor states
3939
// Ignore edges that only have one neighor
40-
for (var i = 1; i < this.cells.length-1; i++) {
41-
var left = this.cells[i-1]; // Left neighbor state
42-
var me = this.cells[i]; // Current state
43-
var right = this.cells[i+1]; // Right neighbor state
40+
for (let i = 1; i < this.cells.length-1; i++) {
41+
let left = this.cells[i-1]; // Left neighbor state
42+
let me = this.cells[i]; // Current state
43+
let right = this.cells[i+1]; // Right neighbor state
4444
nextgen[i] = this.rules(left, me, right); // Compute next generation state based on ruleset
4545
}
4646
// The current generation is the new generation
@@ -50,7 +50,7 @@ function CA(r) {
5050

5151
// This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
5252
this.display = function() {
53-
for (var i = 0; i < this.cells.length; i++) {
53+
for (let i = 0; i < this.cells.length; i++) {
5454
if (this.cells[i] == 1) fill(200);
5555
else fill(51);
5656
noStroke();

0 commit comments

Comments
 (0)