diff --git a/.eslintrc.js b/.eslintrc.js index 76153dcf57..5349370b55 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -8,9 +8,9 @@ module.exports = { plugins: ['prettier'], rules: { - // 'prettier/prettier': ['error', { - // singleQuote: true - // }], + 'prettier/prettier': ['error', { + singleQuote: true + }], 'no-cond-assign': ['error', 'except-parens'], diff --git a/CodingChallenges/CC_001_StarField/P5/Star.js b/CodingChallenges/CC_001_StarField/P5/Star.js index b3148e6f33..cedf360700 100644 --- a/CodingChallenges/CC_001_StarField/P5/Star.js +++ b/CodingChallenges/CC_001_StarField/P5/Star.js @@ -17,7 +17,7 @@ function Star() { this.y = random(-height, height); this.pz = this.z; } - } + }; this.show = function() { fill(255); @@ -36,6 +36,5 @@ function Star() { stroke(255); line(px, py, sx, sy); - - } + }; } diff --git a/CodingChallenges/CC_002_MengerSponge/P5/box.js b/CodingChallenges/CC_002_MengerSponge/P5/box.js index 1ae2b3c5ed..35a1fdf8ce 100644 --- a/CodingChallenges/CC_002_MengerSponge/P5/box.js +++ b/CodingChallenges/CC_002_MengerSponge/P5/box.js @@ -6,28 +6,33 @@ function Box(x, y, z, r) { this.pos = createVector(x, y, z); this.r = r; - - this.generate = function () { + + this.generate = function() { let boxes = []; for (let x = -1; x < 2; x++) { for (let y = -1; y < 2; y++) { for (let z = -1; z < 2; z++) { let sum = abs(x) + abs(y) + abs(z); - let newR = this.r / 3; + let newR = this.r / 3; if (sum > 1) { - let b = new Box(this.pos.x + x * newR, this.pos.y + y * newR, this.pos.z + z * newR, newR); + let b = new Box( + this.pos.x + x * newR, + this.pos.y + y * newR, + this.pos.z + z * newR, + newR + ); boxes.push(b); } } } } return boxes; - } + }; - this.show = function () { + this.show = function() { push(); translate(this.pos.x, this.pos.y, this.pos.z); box(this.r); pop(); - } + }; } diff --git a/CodingChallenges/CC_003_Snake_game/P5/sketch.js b/CodingChallenges/CC_003_Snake_game/P5/sketch.js index 0b2bba0d7b..0cbc4e4f74 100644 --- a/CodingChallenges/CC_003_Snake_game/P5/sketch.js +++ b/CodingChallenges/CC_003_Snake_game/P5/sketch.js @@ -15,8 +15,8 @@ function setup() { } function pickLocation() { - let cols = floor(width/scl); - let rows = floor(height/scl); + let cols = floor(width / scl); + let rows = floor(height / scl); food = createVector(floor(random(cols)), floor(random(rows))); food.mult(scl); } diff --git a/CodingChallenges/CC_003_Snake_game/P5/snake.js b/CodingChallenges/CC_003_Snake_game/P5/snake.js index 6b8d76c6a3..b2646dda95 100644 --- a/CodingChallenges/CC_003_Snake_game/P5/snake.js +++ b/CodingChallenges/CC_003_Snake_game/P5/snake.js @@ -11,7 +11,7 @@ function Snake() { this.total = 0; this.tail = []; - this.eat = function (pos) { + this.eat = function(pos) { let d = dist(this.x, this.y, pos.x, pos.y); if (d < 1) { this.total++; @@ -19,14 +19,14 @@ function Snake() { } else { return false; } - } + }; - this.dir = function (x, y) { + this.dir = function(x, y) { this.xspeed = x; this.yspeed = y; - } + }; - this.death = function () { + this.death = function() { for (let i = 0; i < this.tail.length; i++) { let pos = this.tail[i]; let d = dist(this.x, this.y, pos.x, pos.y); @@ -36,9 +36,9 @@ function Snake() { this.tail = []; } } - } + }; - this.update = function () { + this.update = function() { for (let i = 0; i < this.tail.length - 1; i++) { this.tail[i] = this.tail[i + 1]; } @@ -51,14 +51,13 @@ function Snake() { this.x = constrain(this.x, 0, width - scl); this.y = constrain(this.y, 0, height - scl); - } + }; - this.show = function () { + this.show = function() { fill(255); for (let i = 0; i < this.tail.length; i++) { rect(this.tail[i].x, this.tail[i].y, scl, scl); } rect(this.x, this.y, scl, scl); - - } + }; } diff --git a/CodingChallenges/CC_004_PurpleRain/P5/drop.js b/CodingChallenges/CC_004_PurpleRain/P5/drop.js index 112fb44e0b..986cfd6a4b 100644 --- a/CodingChallenges/CC_004_PurpleRain/P5/drop.js +++ b/CodingChallenges/CC_004_PurpleRain/P5/drop.js @@ -3,7 +3,6 @@ // http://patreon.com/codingtrain // Code for: https://youtu.be/KkyIDI6rQJI - function Drop() { this.x = random(width); this.y = random(-500, -50); @@ -11,7 +10,7 @@ function Drop() { this.len = map(this.z, 0, 20, 10, 20); this.yspeed = map(this.z, 0, 20, 1, 20); - this.fall = function () { + this.fall = function() { this.y = this.y + this.yspeed; var grav = map(this.z, 0, 20, 0, 0.2); this.yspeed = this.yspeed + grav; @@ -20,12 +19,12 @@ function Drop() { this.y = random(-200, -100); this.yspeed = map(this.z, 0, 20, 4, 10); } - } + }; - this.show = function () { + this.show = function() { var thick = map(this.z, 0, 20, 1, 3); strokeWeight(thick); stroke(138, 43, 226); line(this.x, this.y, this.x, this.y + this.len); - } -} \ No newline at end of file + }; +} diff --git a/CodingChallenges/CC_005_Space_invaders/P5/drop.js b/CodingChallenges/CC_005_Space_invaders/P5/drop.js index 74ce4fe7ef..7e6e936ab3 100644 --- a/CodingChallenges/CC_005_Space_invaders/P5/drop.js +++ b/CodingChallenges/CC_005_Space_invaders/P5/drop.js @@ -12,12 +12,12 @@ function Drop(x, y) { this.show = function() { noStroke(); fill(150, 0, 255); - ellipse(this.x, this.y, this.r*2, this.r*2); - } + ellipse(this.x, this.y, this.r * 2, this.r * 2); + }; this.evaporate = function() { this.toDelete = true; - } + }; this.hits = function(flower) { var d = dist(this.x, this.y, flower.x, flower.y); @@ -26,10 +26,9 @@ function Drop(x, y) { } else { return false; } - } + }; this.move = function() { this.y = this.y - 5; - } - + }; } diff --git a/CodingChallenges/CC_005_Space_invaders/P5/flower.js b/CodingChallenges/CC_005_Space_invaders/P5/flower.js index 90ce4d2616..0a91c89dfe 100644 --- a/CodingChallenges/CC_005_Space_invaders/P5/flower.js +++ b/CodingChallenges/CC_005_Space_invaders/P5/flower.js @@ -12,21 +12,20 @@ function Flower(x, y) { this.grow = function() { this.r = this.r + 2; - } + }; this.shiftDown = function() { this.xdir *= -1; this.y += this.r; - } + }; this.move = function() { this.x = this.x + this.xdir; - } + }; this.show = function() { noStroke(); fill(255, 0, 200, 150); - ellipse(this.x, this.y, this.r*2, this.r*2); - } - + ellipse(this.x, this.y, this.r * 2, this.r * 2); + }; } diff --git a/CodingChallenges/CC_005_Space_invaders/P5/ship.js b/CodingChallenges/CC_005_Space_invaders/P5/ship.js index 5a7f02ae64..4fbed8130b 100644 --- a/CodingChallenges/CC_005_Space_invaders/P5/ship.js +++ b/CodingChallenges/CC_005_Space_invaders/P5/ship.js @@ -4,21 +4,20 @@ // Code for: https://youtu.be/biN3v3ef-Y0 function Ship() { - this.x = width/2; + this.x = width / 2; this.xdir = 0; this.show = function() { fill(255); rectMode(CENTER); - rect(this.x, height-20, 20, 60); - } + rect(this.x, height - 20, 20, 60); + }; this.setDir = function(dir) { this.xdir = dir; - } + }; this.move = function(dir) { - this.x += this.xdir*5; - } - + this.x += this.xdir * 5; + }; } diff --git a/CodingChallenges/CC_005_Space_invaders/P5/sketch.js b/CodingChallenges/CC_005_Space_invaders/P5/sketch.js index 8ce20a5f13..cb2dd7efcf 100644 --- a/CodingChallenges/CC_005_Space_invaders/P5/sketch.js +++ b/CodingChallenges/CC_005_Space_invaders/P5/sketch.js @@ -12,7 +12,7 @@ function setup() { ship = new Ship(); // drop = new Drop(width/2, height/2); for (var i = 0; i < 6; i++) { - flowers[i] = new Flower(i*80+80, 60); + flowers[i] = new Flower(i * 80 + 80, 60); } } @@ -48,13 +48,11 @@ function draw() { } } - for (var i = drops.length-1; i >= 0; i--) { + for (var i = drops.length - 1; i >= 0; i--) { if (drops[i].toDelete) { drops.splice(i, 1); } } - - } function keyReleased() { @@ -63,7 +61,6 @@ function keyReleased() { } } - function keyPressed() { if (key === ' ') { var drop = new Drop(ship.x, height); diff --git a/CodingChallenges/CC_006_Mitosis/P5/cell.js b/CodingChallenges/CC_006_Mitosis/P5/cell.js index 5525c34d55..fbde5702e0 100644 --- a/CodingChallenges/CC_006_Mitosis/P5/cell.js +++ b/CodingChallenges/CC_006_Mitosis/P5/cell.js @@ -4,7 +4,6 @@ // Code for: https://youtu.be/jxGS3fKPKJA function Cell(pos, r, c) { - if (pos) { this.pos = pos.copy(); } else { @@ -14,30 +13,29 @@ function Cell(pos, r, c) { this.r = r || 60; this.c = c || color(random(100, 255), 0, random(100, 255), 100); - this.clicked = function (x, y) { + this.clicked = function(x, y) { var d = dist(this.pos.x, this.pos.y, x, y); if (d < this.r) { return true; } else { return false; } - } + }; - this.mitosis = function () { + this.mitosis = function() { //this.pos.x += random(-this.r, this.r); var cell = new Cell(this.pos, this.r * 0.8, this.c); return cell; - } + }; - this.move = function () { + this.move = function() { var vel = p5.Vector.random2D(); this.pos.add(vel); - } + }; - this.show = function () { + this.show = function() { noStroke(); fill(this.c); - ellipse(this.pos.x, this.pos.y, this.r, this.r) - } - -} \ No newline at end of file + ellipse(this.pos.x, this.pos.y, this.r, this.r); + }; +} diff --git a/CodingChallenges/CC_006_Mitosis/P5/sketch.js b/CodingChallenges/CC_006_Mitosis/P5/sketch.js index e4c0d00280..a70e794827 100644 --- a/CodingChallenges/CC_006_Mitosis/P5/sketch.js +++ b/CodingChallenges/CC_006_Mitosis/P5/sketch.js @@ -27,4 +27,4 @@ function mousePressed() { cells.splice(i, 1); } } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_007_SolarSystemGenerator/P5/planet.js b/CodingChallenges/CC_007_SolarSystemGenerator/P5/planet.js index 0d987a11ea..070c5e0c8d 100644 --- a/CodingChallenges/CC_007_SolarSystemGenerator/P5/planet.js +++ b/CodingChallenges/CC_007_SolarSystemGenerator/P5/planet.js @@ -1,46 +1,42 @@ class Planet { - constructor(radius, distance, orbitspeed, angle) { - this.radius = radius; - this.distance = distance; - this.orbitspeed = orbitspeed; - this.angle = angle; - this.planets = []; - } - + constructor(radius, distance, orbitspeed, angle) { + this.radius = radius; + this.distance = distance; + this.orbitspeed = orbitspeed; + this.angle = angle; + this.planets = []; + } - orbit() { - this.angle += this.orbitspeed; - for (let i in this.planets) { - this.planets[i].orbit(); - } + orbit() { + this.angle += this.orbitspeed; + for (let i in this.planets) { + this.planets[i].orbit(); } + } - - spawnMoons(total, level) { - for (let i = 0; i < total; i++) { - let r = this.radius / (level * 2); - let d = random(50, 150); - let o = random(-0.1, 0.1); - let a = random(TWO_PI); - this.planets.push(new Planet(r, d / level, o, a)); - if (level < 3) { - let num = Math.floor(random(0, 4)); - this.planets[i].spawnMoons(num, level + 1); - } - } + spawnMoons(total, level) { + for (let i = 0; i < total; i++) { + let r = this.radius / (level * 2); + let d = random(50, 150); + let o = random(-0.1, 0.1); + let a = random(TWO_PI); + this.planets.push(new Planet(r, d / level, o, a)); + if (level < 3) { + let num = Math.floor(random(0, 4)); + this.planets[i].spawnMoons(num, level + 1); + } } + } - - show() { - push(); - fill(255, 100); - rotate(this.angle); - translate(this.distance, 0); - ellipse(0, 0, this.radius * 2); - for (let i in this.planets) { - this.planets[i].show(); - } - pop(); + show() { + push(); + fill(255, 100); + rotate(this.angle); + translate(this.distance, 0); + ellipse(0, 0, this.radius * 2); + for (let i in this.planets) { + this.planets[i].show(); } - -} \ No newline at end of file + pop(); + } +} diff --git a/CodingChallenges/CC_007_SolarSystemGenerator/P5/sketch.js b/CodingChallenges/CC_007_SolarSystemGenerator/P5/sketch.js index 3386ec0be2..a13348c5b2 100644 --- a/CodingChallenges/CC_007_SolarSystemGenerator/P5/sketch.js +++ b/CodingChallenges/CC_007_SolarSystemGenerator/P5/sketch.js @@ -1,15 +1,14 @@ // port of Daniel Shiffman's pde SolarSystemGenerator by madacoo - function setup() { - createCanvas(600, 600); - sun = new Planet(50, 0, 0, random(TWO_PI)); - sun.spawnMoons(5, 1); + createCanvas(600, 600); + sun = new Planet(50, 0, 0, random(TWO_PI)); + sun.spawnMoons(5, 1); } function draw() { - background(51); - translate(width / 2, height / 2); - sun.show(); - sun.orbit(); -} \ No newline at end of file + background(51); + translate(width / 2, height / 2); + sun.show(); + sun.orbit(); +} diff --git a/CodingChallenges/CC_010_Maze_DFS/P5/cell.js b/CodingChallenges/CC_010_Maze_DFS/P5/cell.js index fdf3c83912..7622f8f042 100644 --- a/CodingChallenges/CC_010_Maze_DFS/P5/cell.js +++ b/CodingChallenges/CC_010_Maze_DFS/P5/cell.js @@ -20,11 +20,11 @@ function Cell(i, j) { this.checkNeighbors = function() { let neighbors = []; - - let top = grid[index(i, j -1)]; - let right = grid[index(i+1, j)]; - let bottom = grid[index(i, j+1)]; - let left = grid[index(i-1, j)]; + + let top = grid[index(i, j - 1)]; + let right = grid[index(i + 1, j)]; + let bottom = grid[index(i, j + 1)]; + let left = grid[index(i - 1, j)]; if (top && !top.visited) { neighbors.push(top); @@ -45,33 +45,30 @@ function Cell(i, j) { } else { return undefined; } - - - } + }; this.highlight = function() { - let x = this.i*w; - let y = this.j*w; + let x = this.i * w; + let y = this.j * w; noStroke(); fill(0, 0, 255, 100); rect(x, y, w, w); - - } + }; this.show = function() { - let x = this.i*w; - let y = this.j*w; + let x = this.i * w; + let y = this.j * w; stroke(255); if (this.walls[0]) { - line(x , y , x + w, y); + line(x, y, x + w, y); } if (this.walls[1]) { - line(x + w, y , x + w, y + w); + line(x + w, y, x + w, y + w); } if (this.walls[2]) { - line(x + w, y + w, x , y + w); + line(x + w, y + w, x, y + w); } if (this.walls[3]) { - line(x , y + w, x , y); + line(x, y + w, x, y); } if (this.visited) { @@ -79,5 +76,5 @@ function Cell(i, j) { fill(255, 0, 255, 100); rect(x, y, w, w); } - } + }; } diff --git a/CodingChallenges/CC_010_Maze_DFS/P5/sketch.js b/CodingChallenges/CC_010_Maze_DFS/P5/sketch.js index 27c1b85c22..f2399156be 100644 --- a/CodingChallenges/CC_010_Maze_DFS/P5/sketch.js +++ b/CodingChallenges/CC_010_Maze_DFS/P5/sketch.js @@ -20,9 +20,9 @@ let stack = []; function setup() { createCanvas(600, 600); - cols = floor(width/w); - rows = floor(height/w); - + cols = floor(width / w); + rows = floor(height / w); + for (let j = 0; j < rows; j++) { for (let i = 0; i < cols; i++) { var cell = new Cell(i, j); @@ -31,7 +31,6 @@ function setup() { } current = grid[0]; - } function draw() { @@ -58,17 +57,15 @@ function draw() { } else if (stack.length > 0) { current = stack.pop(); } - } function index(i, j) { - if (i < 0 || j < 0 || i > cols-1 || j > rows-1) { + if (i < 0 || j < 0 || i > cols - 1 || j > rows - 1) { return -1; } return i + j * cols; } - function removeWalls(a, b) { let x = a.i - b.i; if (x === 1) { diff --git a/CodingChallenges/CC_011_PerlinNoiseTerrain/P5/sketch.js b/CodingChallenges/CC_011_PerlinNoiseTerrain/P5/sketch.js index 3618ea9135..3fb41ea0dc 100644 --- a/CodingChallenges/CC_011_PerlinNoiseTerrain/P5/sketch.js +++ b/CodingChallenges/CC_011_PerlinNoiseTerrain/P5/sketch.js @@ -17,7 +17,7 @@ var terrain = []; function setup() { createCanvas(600, 600, WEBGL); cols = w / scl; - rows = h/ scl; + rows = h / scl; for (var x = 0; x < cols; x++) { terrain[x] = []; @@ -28,7 +28,6 @@ function setup() { } function draw() { - flying -= 0.1; var yoff = flying; for (var y = 0; y < rows; y++) { @@ -40,17 +39,16 @@ function draw() { yoff += 0.2; } - background(0); translate(0, 50); - rotateX(PI/3); - fill(200,200,200, 50); - translate(-w/2, -h/2); - for (var y = 0; y < rows-1; y++) { + rotateX(PI / 3); + fill(200, 200, 200, 50); + translate(-w / 2, -h / 2); + for (var y = 0; y < rows - 1; y++) { beginShape(TRIANGLE_STRIP); for (var x = 0; x < cols; x++) { - vertex(x*scl, y*scl, terrain[x][y]); - vertex(x*scl, (y+1)*scl, terrain[x][y+1]); + vertex(x * scl, y * scl, terrain[x][y]); + vertex(x * scl, (y + 1) * scl, terrain[x][y + 1]); } endShape(); } diff --git a/CodingChallenges/CC_012_LorenzAttractor/P5/sketch.js b/CodingChallenges/CC_012_LorenzAttractor/P5/sketch.js index 9930cad010..32b4e0f4cc 100644 --- a/CodingChallenges/CC_012_LorenzAttractor/P5/sketch.js +++ b/CodingChallenges/CC_012_LorenzAttractor/P5/sketch.js @@ -8,51 +8,49 @@ let c = 8.0 / 3.0; let points = new Array(); - function setup() { - createCanvas(800, 600, WEBGL); - colorMode(HSB); + createCanvas(800, 600, WEBGL); + colorMode(HSB); } function draw() { - background(0); - - let dt = 0.01; - let dx = (a * (y - x)) * dt; - let dy = (x * (b - z) - y) * dt; - let dz = (x * y - c * z) * dt; - x = x + dx; - y = y + dy; - z = z + dz; - - points.push(new p5.Vector(x, y, z)); - - translate(0, 0, -80); - let camX = map(mouseX, 0, width, -200, 200); - let camY = map(mouseY, 0, height, -200,200); - camera(camX, camY, (height/2.0) / tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0); - //translate(width/2, height/2); - scale(5); - stroke(255); - noFill(); - - let hu = 0; - beginShape(); - - for (let v of points) { - stroke(hu, 255, 255); - vertex(v.x, v.y, v.z); - //PVector offset = PVector.random3D(); - //offset.mult(0.1); - //v.add(offset); - - hu += 1; - if (hu > 255) { - hu = 0; - } - } - endShape(); - - - //println(x,y,z); -} \ No newline at end of file + background(0); + + let dt = 0.01; + let dx = a * (y - x) * dt; + let dy = (x * (b - z) - y) * dt; + let dz = (x * y - c * z) * dt; + x = x + dx; + y = y + dy; + z = z + dz; + + points.push(new p5.Vector(x, y, z)); + + translate(0, 0, -80); + let camX = map(mouseX, 0, width, -200, 200); + let camY = map(mouseY, 0, height, -200, 200); + camera(camX, camY, height / 2.0 / tan((PI * 30.0) / 180.0), 0, 0, 0, 0, 1, 0); + //translate(width/2, height/2); + scale(5); + stroke(255); + noFill(); + + let hu = 0; + beginShape(); + + for (let v of points) { + stroke(hu, 255, 255); + vertex(v.x, v.y, v.z); + //PVector offset = PVector.random3D(); + //offset.mult(0.1); + //v.add(offset); + + hu += 1; + if (hu > 255) { + hu = 0; + } + } + endShape(); + + //println(x,y,z); +} diff --git a/CodingChallenges/CC_013_ReactionDiffusion/P5/sketch.js b/CodingChallenges/CC_013_ReactionDiffusion/P5/sketch.js index 7351da3d85..5973e2e65c 100644 --- a/CodingChallenges/CC_013_ReactionDiffusion/P5/sketch.js +++ b/CodingChallenges/CC_013_ReactionDiffusion/P5/sketch.js @@ -42,7 +42,6 @@ function setup() { grid[i][j].b = 1; } } - } function draw() { @@ -52,21 +51,14 @@ function draw() { for (var y = 1; y < height - 1; y++) { var a = grid[x][y].a; var b = grid[x][y].b; - next[x][y].a = a + - (dA * laplaceA(x, y)) - - (a * b * b) + - (feed * (1 - a)); - next[x][y].b = b + - (dB * laplaceB(x, y)) + - (a * b * b) - - ((k + feed) * b); + next[x][y].a = a + dA * laplaceA(x, y) - a * b * b + feed * (1 - a); + next[x][y].b = b + dB * laplaceB(x, y) + a * b * b - (k + feed) * b; next[x][y].a = constrain(next[x][y].a, 0, 1); next[x][y].b = constrain(next[x][y].b, 0, 1); } } - loadPixels(); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { @@ -83,13 +75,9 @@ function draw() { } updatePixels(); - swap(); - - } - function laplaceA(x, y) { var sumA = 0; sumA += grid[x][y].a * -1; @@ -118,8 +106,6 @@ function laplaceB(x, y) { return sumB; } - - function swap() { var temp = grid; grid = next; diff --git a/CodingChallenges/CC_014_FractalTree/P5/sketch.js b/CodingChallenges/CC_014_FractalTree/P5/sketch.js index 514e385bf6..2479bd82b5 100644 --- a/CodingChallenges/CC_014_FractalTree/P5/sketch.js +++ b/CodingChallenges/CC_014_FractalTree/P5/sketch.js @@ -17,7 +17,6 @@ function draw() { stroke(255); translate(200, height); branch(100); - } function branch(len) { diff --git a/CodingChallenges/CC_015_FractalTreeArray/P5/branch.js b/CodingChallenges/CC_015_FractalTreeArray/P5/branch.js index c0ceb8a2b0..21964c68c8 100644 --- a/CodingChallenges/CC_015_FractalTreeArray/P5/branch.js +++ b/CodingChallenges/CC_015_FractalTreeArray/P5/branch.js @@ -6,12 +6,12 @@ function Branch(begin, end) { this.jitter = function() { this.end.x += random(-1, 1); this.end.y += random(-1, 1); - } + }; this.show = function() { stroke(255); line(this.begin.x, this.begin.y, this.end.x, this.end.y); - } + }; this.branchA = function() { var dir = p5.Vector.sub(this.end, this.begin); @@ -20,7 +20,7 @@ function Branch(begin, end) { var newEnd = p5.Vector.add(this.end, dir); var b = new Branch(this.end, newEnd); return b; - } + }; this.branchB = function() { var dir = p5.Vector.sub(this.end, this.begin); dir.rotate(-PI / 4); @@ -28,8 +28,5 @@ function Branch(begin, end) { var newEnd = p5.Vector.add(this.end, dir); var b = new Branch(this.end, newEnd); return b; - } - - - + }; } diff --git a/CodingChallenges/CC_015_FractalTreeArray/P5/sketch.js b/CodingChallenges/CC_015_FractalTreeArray/P5/sketch.js index 2e10cb431f..c2668944a5 100644 --- a/CodingChallenges/CC_015_FractalTreeArray/P5/sketch.js +++ b/CodingChallenges/CC_015_FractalTreeArray/P5/sketch.js @@ -35,7 +35,6 @@ function mousePressed() { } } } - } function draw() { @@ -52,5 +51,4 @@ function draw() { ellipse(leaves[i].x, leaves[i].y, 8, 8); leaves[i].y += random(0, 2); } - } diff --git a/CodingChallenges/CC_016_LSystem/P5/sketch.js b/CodingChallenges/CC_016_LSystem/P5/sketch.js index 0ce6ee750f..a37d455df7 100644 --- a/CodingChallenges/CC_016_LSystem/P5/sketch.js +++ b/CodingChallenges/CC_016_LSystem/P5/sketch.js @@ -7,19 +7,19 @@ // axiom: A // rules: (A → AB), (B → A) var angle; -var axiom = "F"; +var axiom = 'F'; var sentence = axiom; var len = 100; var rules = []; rules[0] = { - a: "F", - b: "FF+[+F-F-F]-[-F+F+F]" -} + a: 'F', + b: 'FF+[+F-F-F]-[-F+F+F]' +}; function generate() { len *= 0.5; - var nextSentence = ""; + var nextSentence = ''; for (var i = 0; i < sentence.length; i++) { var current = sentence.charAt(i); var found = false; @@ -37,7 +37,6 @@ function generate() { sentence = nextSentence; createP(sentence); turtle(); - } function turtle() { @@ -48,16 +47,16 @@ function turtle() { for (var i = 0; i < sentence.length; i++) { var current = sentence.charAt(i); - if (current == "F") { + if (current == 'F') { line(0, 0, 0, -len); translate(0, -len); - } else if (current == "+") { + } else if (current == '+') { rotate(angle); - } else if (current == "-") { - rotate(-angle) - } else if (current == "[") { + } else if (current == '-') { + rotate(-angle); + } else if (current == '[') { push(); - } else if (current == "]") { + } else if (current == ']') { pop(); } } @@ -69,6 +68,6 @@ function setup() { background(51); createP(axiom); turtle(); - var button = createButton("generate"); + var button = createButton('generate'); button.mousePressed(generate); } diff --git a/CodingChallenges/CC_017_SpaceColonizer/P5/branch.js b/CodingChallenges/CC_017_SpaceColonizer/P5/branch.js index d1909997cb..bd519ce4a9 100644 --- a/CodingChallenges/CC_017_SpaceColonizer/P5/branch.js +++ b/CodingChallenges/CC_017_SpaceColonizer/P5/branch.js @@ -14,21 +14,19 @@ function Branch(parent, pos, dir) { this.reset = function() { this.dir = this.origDir.copy(); this.count = 0; - } - + }; this.next = function() { var nextDir = p5.Vector.mult(this.dir, this.len); var nextPos = p5.Vector.add(this.pos, nextDir); var nextBranch = new Branch(this, nextPos, this.dir.copy()); return nextBranch; - } + }; this.show = function() { if (parent != null) { stroke(255); line(this.pos.x, this.pos.y, this.parent.pos.x, this.parent.pos.y); } - - } + }; } diff --git a/CodingChallenges/CC_017_SpaceColonizer/P5/leaf.js b/CodingChallenges/CC_017_SpaceColonizer/P5/leaf.js index 4556a888ab..a033bd9046 100644 --- a/CodingChallenges/CC_017_SpaceColonizer/P5/leaf.js +++ b/CodingChallenges/CC_017_SpaceColonizer/P5/leaf.js @@ -11,6 +11,5 @@ function Leaf() { fill(255); noStroke(); ellipse(this.pos.x, this.pos.y, 4, 4); - } - + }; } diff --git a/CodingChallenges/CC_017_SpaceColonizer/P5/tree.js b/CodingChallenges/CC_017_SpaceColonizer/P5/tree.js index 40ef52e0b9..911f3a9c5c 100644 --- a/CodingChallenges/CC_017_SpaceColonizer/P5/tree.js +++ b/CodingChallenges/CC_017_SpaceColonizer/P5/tree.js @@ -70,11 +70,7 @@ function Tree() { branch.reset(); } } - } - - - - + }; this.show = function() { for (var i = 0; i < this.leaves.length; i++) { @@ -84,7 +80,5 @@ function Tree() { for (var i = 0; i < this.branches.length; i++) { this.branches[i].show(); } - - } - + }; } diff --git a/CodingChallenges/CC_019_Superellipse/P5/sketch.js b/CodingChallenges/CC_019_Superellipse/P5/sketch.js index 36fbb36046..446ee2f2e3 100644 --- a/CodingChallenges/CC_019_Superellipse/P5/sketch.js +++ b/CodingChallenges/CC_019_Superellipse/P5/sketch.js @@ -41,4 +41,4 @@ function sgn(val) { return 0; } return val / abs(val); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_021_Mandelbrot/P5/sketch.js b/CodingChallenges/CC_021_Mandelbrot/P5/sketch.js index f9be5f7ef3..476704ddb4 100644 --- a/CodingChallenges/CC_021_Mandelbrot/P5/sketch.js +++ b/CodingChallenges/CC_021_Mandelbrot/P5/sketch.js @@ -27,7 +27,6 @@ function draw() { loadPixels(); for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { - var a = map(x, 0, width, minSlider.value(), maxSlider.value()); var b = map(y, 0, height, minSlider.value(), maxSlider.value()); diff --git a/CodingChallenges/CC_023_SuperShape2D/P5/sketch.js b/CodingChallenges/CC_023_SuperShape2D/P5/sketch.js index a8d6c579f1..1cd5175e6f 100644 --- a/CodingChallenges/CC_023_SuperShape2D/P5/sketch.js +++ b/CodingChallenges/CC_023_SuperShape2D/P5/sketch.js @@ -20,12 +20,11 @@ function setup() { } function supershape(theta) { - - var part1 = (1 / a) * cos(theta * m / 4); + var part1 = (1 / a) * cos((theta * m) / 4); part1 = abs(part1); part1 = pow(part1, n2); - var part2 = (1 / b) * sin(theta * m / 4); + var part2 = (1 / b) * sin((theta * m) / 4); part2 = abs(part2); part2 = pow(part2, n3); @@ -35,10 +34,9 @@ function supershape(theta) { return 0; } - return (1 / part3); + return 1 / part3; } - function draw() { m = map(sin(osc), -1, 1, 0, 10); //slider.value(); osc += 0.02; @@ -63,6 +61,4 @@ function draw() { vertex(x, y); } endShape(CLOSE); - - } diff --git a/CodingChallenges/CC_024_PerlinNoiseFlowField/P5/particle.js b/CodingChallenges/CC_024_PerlinNoiseFlowField/P5/particle.js index be94f199cf..dadb5da84e 100644 --- a/CodingChallenges/CC_024_PerlinNoiseFlowField/P5/particle.js +++ b/CodingChallenges/CC_024_PerlinNoiseFlowField/P5/particle.js @@ -17,7 +17,7 @@ function Particle() { this.vel.limit(this.maxspeed); this.pos.add(this.vel); this.acc.mult(0); - } + }; this.follow = function(vectors) { var x = floor(this.pos.x / scl); @@ -25,11 +25,11 @@ function Particle() { var index = x + y * cols; var force = vectors[index]; this.applyForce(force); - } + }; this.applyForce = function(force) { this.acc.add(force); - } + }; this.show = function() { stroke(this.h, 255, 255, 25); @@ -40,12 +40,12 @@ function Particle() { strokeWeight(1); line(this.pos.x, this.pos.y, this.prevPos.x, this.prevPos.y); this.updatePrev(); - } + }; this.updatePrev = function() { this.prevPos.x = this.pos.x; this.prevPos.y = this.pos.y; - } + }; this.edges = function() { if (this.pos.x > width) { @@ -64,7 +64,5 @@ function Particle() { this.pos.y = height; this.updatePrev(); } - - } - + }; } diff --git a/CodingChallenges/CC_027_FireWorks/P5/firework.js b/CodingChallenges/CC_027_FireWorks/P5/firework.js index aca67a67f6..f25e7ad403 100644 --- a/CodingChallenges/CC_027_FireWorks/P5/firework.js +++ b/CodingChallenges/CC_027_FireWorks/P5/firework.js @@ -15,43 +15,48 @@ function Firework() { } else { return false; } - } + }; this.update = function() { if (!this.exploded) { this.firework.applyForce(gravity); this.firework.update(); - + if (this.firework.vel.y >= 0) { this.exploded = true; this.explode(); } } - + for (var i = this.particles.length - 1; i >= 0; i--) { this.particles[i].applyForce(gravity); this.particles[i].update(); - + if (this.particles[i].done()) { this.particles.splice(i, 1); } } - } + }; this.explode = function() { for (var i = 0; i < 100; i++) { - var p = new Particle(this.firework.pos.x, this.firework.pos.y, this.hu, false); + var p = new Particle( + this.firework.pos.x, + this.firework.pos.y, + this.hu, + false + ); this.particles.push(p); } - } + }; this.show = function() { if (!this.exploded) { this.firework.show(); } - + for (var i = 0; i < this.particles.length; i++) { this.particles[i].show(); } - } + }; } diff --git a/CodingChallenges/CC_027_FireWorks/P5/particle.js b/CodingChallenges/CC_027_FireWorks/P5/particle.js index a7be4673cd..b2479dbca0 100644 --- a/CodingChallenges/CC_027_FireWorks/P5/particle.js +++ b/CodingChallenges/CC_027_FireWorks/P5/particle.js @@ -9,28 +9,28 @@ function Particle(x, y, hu, firework) { this.lifespan = 255; this.hu = hu; this.acc = createVector(0, 0); - + if (this.firework) { this.vel = createVector(0, random(-12, -8)); } else { this.vel = p5.Vector.random2D(); this.vel.mult(random(2, 10)); } - + this.applyForce = function(force) { this.acc.add(force); - } + }; this.update = function() { if (!this.firework) { this.vel.mult(0.9); this.lifespan -= 4; } - + this.vel.add(this.acc); this.pos.add(this.vel); this.acc.mult(0); - } + }; this.done = function() { if (this.lifespan < 0) { @@ -38,11 +38,11 @@ function Particle(x, y, hu, firework) { } else { return false; } - } + }; this.show = function() { colorMode(HSB); - + if (!this.firework) { strokeWeight(2); stroke(hu, 255, 255, this.lifespan); @@ -50,7 +50,7 @@ function Particle(x, y, hu, firework) { strokeWeight(4); stroke(hu, 255, 255); } - + point(this.pos.x, this.pos.y); - } + }; } diff --git a/CodingChallenges/CC_027_FireWorks/P5/sketch.js b/CodingChallenges/CC_027_FireWorks/P5/sketch.js index 433486481f..185ef183dd 100644 --- a/CodingChallenges/CC_027_FireWorks/P5/sketch.js +++ b/CodingChallenges/CC_027_FireWorks/P5/sketch.js @@ -18,15 +18,15 @@ function setup() { function draw() { colorMode(RGB); background(0, 0, 0, 25); - + if (random(1) < 0.03) { fireworks.push(new Firework()); } - + for (var i = fireworks.length - 1; i >= 0; i--) { fireworks[i].update(); fireworks[i].show(); - + if (fireworks[i].done()) { fireworks.splice(i, 1); } diff --git a/CodingChallenges/CC_028_MetaBalls/P5/blob.js b/CodingChallenges/CC_028_MetaBalls/P5/blob.js index 1702eb9dfd..fe4bdfa26b 100644 --- a/CodingChallenges/CC_028_MetaBalls/P5/blob.js +++ b/CodingChallenges/CC_028_MetaBalls/P5/blob.js @@ -4,27 +4,26 @@ // MetaBalls : p5.js implementation class Blob { + constructor(x, y) { + this.x = x; + this.y = y; + let angle = random(0, 2 * PI); + this.xspeed = random(2, 5) * Math.cos(angle); + this.yspeed = random(2, 5) * Math.sin(angle); + this.r = random(120, 240); + } - constructor(x, y) { - this.x = x; - this.y = y; - let angle = random(0, 2 * PI); - this.xspeed = random(2, 5) * Math.cos(angle); - this.yspeed = random(2, 5) * Math.sin(angle); - this.r = random(120, 240); - } + update() { + this.x += this.xspeed; + this.y += this.yspeed; + if (this.x > width || this.x < 0) this.xspeed *= -1; + if (this.y > height || this.y < 0) this.yspeed *= -1; + } - update() { - this.x += this.xspeed; - this.y += this.yspeed; - if (this.x > width || this.x < 0) this.xspeed *= -1; - if (this.y > height || this.y < 0) this.yspeed *= -1; - } - - show() { - noFill(); - stroke(0); - strokeWeight(4); - ellipse(this.x, this.y, this.r * 2, this.r * 2); - } -} \ No newline at end of file + show() { + noFill(); + stroke(0); + strokeWeight(4); + ellipse(this.x, this.y, this.r * 2, this.r * 2); + } +} diff --git a/CodingChallenges/CC_028_MetaBalls/P5/sketch.js b/CodingChallenges/CC_028_MetaBalls/P5/sketch.js index aed59fc8f8..44a3ac4d9d 100644 --- a/CodingChallenges/CC_028_MetaBalls/P5/sketch.js +++ b/CodingChallenges/CC_028_MetaBalls/P5/sketch.js @@ -3,33 +3,34 @@ // MetaBalls : p5.js implementation -var blobs = [] +var blobs = []; function setup() { - createCanvas(400, 200); - colorMode(HSB); - for (i = 0; i < 10; i++) blobs.push(new Blob(random(0, width), random(0, height))); + createCanvas(400, 200); + colorMode(HSB); + for (i = 0; i < 10; i++) + blobs.push(new Blob(random(0, width), random(0, height))); } function draw() { - background(51); + background(51); - loadPixels(); - for (x = 0; x < width; x++) { - for (y = 0; y < height; y++) { - let sum = 0; - for (i = 0; i < blobs.length; i++) { - let xdif = x - blobs[i].x; - let ydif = y - blobs[i].y; - let d = sqrt((xdif * xdif) + (ydif * ydif)); - sum += 10 * blobs[i].r / d; - } - set(x, y, color(sum, 255, 255)); - } + loadPixels(); + for (x = 0; x < width; x++) { + for (y = 0; y < height; y++) { + let sum = 0; + for (i = 0; i < blobs.length; i++) { + let xdif = x - blobs[i].x; + let ydif = y - blobs[i].y; + let d = sqrt(xdif * xdif + ydif * ydif); + sum += (10 * blobs[i].r) / d; + } + set(x, y, color(sum, 255, 255)); } - updatePixels(); + } + updatePixels(); - for (i = 0; i < blobs.length; i++) { - blobs[i].update(); - } -} \ No newline at end of file + for (i = 0; i < blobs.length; i++) { + blobs[i].update(); + } +} diff --git a/CodingChallenges/CC_029_SmartRockets/P5/dna.js b/CodingChallenges/CC_029_SmartRockets/P5/dna.js index 42bfff2223..a7d0fa62a5 100644 --- a/CodingChallenges/CC_029_SmartRockets/P5/dna.js +++ b/CodingChallenges/CC_029_SmartRockets/P5/dna.js @@ -35,7 +35,7 @@ function DNA(genes) { } // Gives DNA object an array return new DNA(newgenes); - } + }; // Adds random mutation to the genes to add variance. this.mutation = function() { @@ -46,6 +46,5 @@ function DNA(genes) { this.genes[i].setMag(maxforce); } } - } - + }; } diff --git a/CodingChallenges/CC_029_SmartRockets/P5/population.js b/CodingChallenges/CC_029_SmartRockets/P5/population.js index 04b61009c4..f1ebe066c6 100644 --- a/CodingChallenges/CC_029_SmartRockets/P5/population.js +++ b/CodingChallenges/CC_029_SmartRockets/P5/population.js @@ -17,7 +17,6 @@ function Population() { } this.evaluate = function() { - var maxfit = 0; // Iterate through all rockets and calcultes their fitness for (var i = 0; i < this.popsize; i++) { @@ -42,7 +41,7 @@ function Population() { this.matingpool.push(this.rockets[i]); } } - } + }; // Selects appropriate genes for child this.selection = function() { var newRockets = []; @@ -58,7 +57,7 @@ function Population() { } // This instance of rockets are the new rockets this.rockets = newRockets; - } + }; // Calls for update and show functions this.run = function() { @@ -67,5 +66,5 @@ function Population() { // Displays rockets to screen this.rockets[i].show(); } - } + }; } diff --git a/CodingChallenges/CC_029_SmartRockets/P5/rocket.js b/CodingChallenges/CC_029_SmartRockets/P5/rocket.js index 70f59b42c5..7d02a60607 100644 --- a/CodingChallenges/CC_029_SmartRockets/P5/rocket.js +++ b/CodingChallenges/CC_029_SmartRockets/P5/rocket.js @@ -24,7 +24,7 @@ function Rocket(dna) { // Object can recieve force and add to acceleration this.applyForce = function(force) { this.acc.add(force); - } + }; // Calulates fitness of rocket this.calcFitness = function() { // Takes distance to target @@ -40,8 +40,7 @@ function Rocket(dna) { if (this.crashed) { this.fitness /= 10; } - - } + }; // Updates state of rocket this.update = function() { // Checks distance from rocket to target @@ -52,7 +51,12 @@ function Rocket(dna) { this.pos = target.copy(); } // Rocket hit the barrier - if (this.pos.x > rx && this.pos.x < rx + rw && this.pos.y > ry && this.pos.y < ry + rh) { + if ( + this.pos.x > rx && + this.pos.x < rx + rw && + this.pos.y > ry && + this.pos.y < ry + rh + ) { this.crashed = true; } // Rocket has hit left or right of window @@ -64,7 +68,6 @@ function Rocket(dna) { this.crashed = true; } - //applies the random vectors defined in dna to consecutive frames of rocket this.applyForce(this.dna.genes[count]); // if rocket has not got to goal and not crashed then update physics engine @@ -74,7 +77,7 @@ function Rocket(dna) { this.acc.mult(0); this.vel.limit(4); } - } + }; // displays rocket to window this.show = function() { // push and pop allow's rotating and translation not to affect other objects @@ -90,6 +93,5 @@ function Rocket(dna) { rectMode(CENTER); rect(0, 0, 25, 5); pop(); - } - + }; } diff --git a/CodingChallenges/CC_029_SmartRockets/P5/sketch.js b/CodingChallenges/CC_029_SmartRockets/P5/sketch.js index e06e77d88c..12e2c0129d 100644 --- a/CodingChallenges/CC_029_SmartRockets/P5/sketch.js +++ b/CodingChallenges/CC_029_SmartRockets/P5/sketch.js @@ -26,7 +26,6 @@ function setup() { population = new Population(); lifeP = createP(); target = createVector(width / 2, 50); - } function draw() { diff --git a/CodingChallenges/CC_031_FlappyBird/P5/bird.js b/CodingChallenges/CC_031_FlappyBird/P5/bird.js index 1d7a1cd1aa..b61c64a338 100644 --- a/CodingChallenges/CC_031_FlappyBird/P5/bird.js +++ b/CodingChallenges/CC_031_FlappyBird/P5/bird.js @@ -4,7 +4,7 @@ // Code for: https://youtu.be/cXgA1d_E-jY& function Bird() { - this.y = height/2; + this.y = height / 2; this.x = 64; this.gravity = 0.7; @@ -14,11 +14,11 @@ function Bird() { this.show = function() { fill(255); ellipse(this.x, this.y, 32, 32); - } + }; this.up = function() { this.velocity += this.lift; - } + }; this.update = function() { this.velocity += this.gravity; @@ -34,7 +34,5 @@ function Bird() { this.y = 0; this.velocity = 0; } - - } - + }; } diff --git a/CodingChallenges/CC_031_FlappyBird/P5/pipe.js b/CodingChallenges/CC_031_FlappyBird/P5/pipe.js index 504d9069b1..db85bce198 100644 --- a/CodingChallenges/CC_031_FlappyBird/P5/pipe.js +++ b/CodingChallenges/CC_031_FlappyBird/P5/pipe.js @@ -5,7 +5,7 @@ function Pipe() { this.spacing = 175; - this.top = random(height / 6, 3 / 4 * height); + this.top = random(height / 6, (3 / 4) * height); this.bottom = height - (this.top + this.spacing); this.x = width; this.w = 80; @@ -22,7 +22,7 @@ function Pipe() { } this.highlight = false; return false; - } + }; this.show = function() { fill(255); @@ -30,12 +30,12 @@ function Pipe() { fill(255, 0, 0); } rect(this.x, 0, this.w, this.top); - rect(this.x, height-this.bottom, this.w, this.bottom); - } + rect(this.x, height - this.bottom, this.w, this.bottom); + }; this.update = function() { this.x -= this.speed; - } + }; this.offscreen = function() { if (this.x < -this.w) { @@ -43,7 +43,5 @@ function Pipe() { } else { return false; } - } - - + }; } diff --git a/CodingChallenges/CC_031_FlappyBird/P5/sketch.js b/CodingChallenges/CC_031_FlappyBird/P5/sketch.js index a52ba2815e..bc31952347 100644 --- a/CodingChallenges/CC_031_FlappyBird/P5/sketch.js +++ b/CodingChallenges/CC_031_FlappyBird/P5/sketch.js @@ -3,7 +3,6 @@ // http://patreon.com/codingtrain // Code for: https://youtu.be/cXgA1d_E-jY& - var bird; var pipes = []; @@ -16,12 +15,12 @@ function setup() { function draw() { background(0); - for (var i = pipes.length-1; i >= 0; i--) { + for (var i = pipes.length - 1; i >= 0; i--) { pipes[i].show(); pipes[i].update(); if (pipes[i].hits(bird)) { - console.log("HIT"); + console.log('HIT'); } if (pipes[i].offscreen()) { diff --git a/CodingChallenges/CC_032.1_agar.io/P5/blob.js b/CodingChallenges/CC_032.1_agar.io/P5/blob.js index 2c4d7197c5..c193f09bf9 100644 --- a/CodingChallenges/CC_032.1_agar.io/P5/blob.js +++ b/CodingChallenges/CC_032.1_agar.io/P5/blob.js @@ -6,14 +6,14 @@ function Blob(x, y, r) { this.pos = createVector(x, y); this.r = r; - this.vel = createVector(0,0); + this.vel = createVector(0, 0); this.update = function() { - var newvel = createVector(mouseX-width/2, mouseY-height/2); + var newvel = createVector(mouseX - width / 2, mouseY - height / 2); newvel.setMag(3); this.vel.lerp(newvel, 0.2); this.pos.add(this.vel); - } + }; this.eats = function(other) { var d = p5.Vector.dist(this.pos, other.pos); @@ -25,10 +25,10 @@ function Blob(x, y, r) { } else { return false; } - } + }; this.show = function() { fill(255); - ellipse(this.pos.x, this.pos.y, this.r*2, this.r*2); - } + ellipse(this.pos.x, this.pos.y, this.r * 2, this.r * 2); + }; } diff --git a/CodingChallenges/CC_032.1_agar.io/P5/sketch.js b/CodingChallenges/CC_032.1_agar.io/P5/sketch.js index bbbe8f3070..5a345b60a9 100644 --- a/CodingChallenges/CC_032.1_agar.io/P5/sketch.js +++ b/CodingChallenges/CC_032.1_agar.io/P5/sketch.js @@ -12,8 +12,8 @@ function setup() { createCanvas(600, 600); blob = new Blob(0, 0, 64); for (var i = 0; i < 200; i++) { - var x = random(-width,width); - var y = random(-height,height); + var x = random(-width, width); + var y = random(-height, height); blobs[i] = new Blob(x, y, 16); } } @@ -21,21 +21,19 @@ function setup() { function draw() { background(0); - translate(width/2, height/2); + translate(width / 2, height / 2); var newzoom = 64 / blob.r; zoom = lerp(zoom, newzoom, 0.1); scale(zoom); translate(-blob.pos.x, -blob.pos.y); - for (var i = blobs.length-1; i >=0; i--) { + for (var i = blobs.length - 1; i >= 0; i--) { blobs[i].show(); if (blob.eats(blobs[i])) { blobs.splice(i, 1); } } - blob.show(); blob.update(); - } diff --git a/CodingChallenges/CC_032.2_agar.io_sockets/Node/public/blob.js b/CodingChallenges/CC_032.2_agar.io_sockets/Node/public/blob.js index b5e23318db..3c0d0476f0 100644 --- a/CodingChallenges/CC_032.2_agar.io_sockets/Node/public/blob.js +++ b/CodingChallenges/CC_032.2_agar.io_sockets/Node/public/blob.js @@ -15,7 +15,7 @@ function Blob(x, y, r) { newvel.limit(3); this.vel.lerp(newvel, 0.2); this.pos.add(this.vel); - } + }; this.eats = function(other) { var d = p5.Vector.dist(this.pos, other.pos); @@ -27,15 +27,15 @@ function Blob(x, y, r) { } else { return false; } - } + }; this.constrain = function() { blob.pos.x = constrain(blob.pos.x, -width / 4, width / 4); blob.pos.y = constrain(blob.pos.y, -height / 4, height / 4); - } + }; this.show = function() { fill(255); ellipse(this.pos.x, this.pos.y, this.r * 2, this.r * 2); - } + }; } diff --git a/CodingChallenges/CC_032.2_agar.io_sockets/Node/public/sketch.js b/CodingChallenges/CC_032.2_agar.io_sockets/Node/public/sketch.js index fdc4d998b3..1e94726b30 100644 --- a/CodingChallenges/CC_032.2_agar.io_sockets/Node/public/sketch.js +++ b/CodingChallenges/CC_032.2_agar.io_sockets/Node/public/sketch.js @@ -17,7 +17,6 @@ function setup() { // Some day we would run this server somewhere else socket = io.connect('http://localhost:3000'); - blob = new Blob(random(width), random(height), random(8, 24)); // Make a little object with and y var data = { @@ -27,12 +26,10 @@ function setup() { }; socket.emit('start', data); - socket.on('heartbeat', - function(data) { - //console.log(data); - blobs = data; - } - ); + socket.on('heartbeat', function(data) { + //console.log(data); + blobs = data; + }); } function draw() { @@ -62,8 +59,6 @@ function draw() { // } } - - blob.show(); if (mouseIsPressed) { blob.update(); @@ -76,6 +71,4 @@ function draw() { r: blob.r }; socket.emit('update', data); - - } diff --git a/CodingChallenges/CC_032.2_agar.io_sockets/Node/server.js b/CodingChallenges/CC_032.2_agar.io_sockets/Node/server.js index 668295a95c..e53c4c0407 100644 --- a/CodingChallenges/CC_032.2_agar.io_sockets/Node/server.js +++ b/CodingChallenges/CC_032.2_agar.io_sockets/Node/server.js @@ -33,7 +33,6 @@ function listen() { app.use(express.static('public')); - // WebSocket Portion // WebSockets work with the HTTP server var io = require('socket.io')(server); @@ -44,44 +43,35 @@ function heartbeat() { io.sockets.emit('heartbeat', blobs); } - - // Register a callback function to run when we have an individual connection // This is run for each individual user that connects -io.sockets.on('connection', +io.sockets.on( + 'connection', // We are given a websocket object in our function function(socket) { + console.log('We have a new client: ' + socket.id); - console.log("We have a new client: " + socket.id); - - - socket.on('start', - function(data) { - console.log(socket.id + " " + data.x + " " + data.y + " " + data.r); - var blob = new Blob(socket.id, data.x, data.y, data.r); - blobs.push(blob); - } - ); + socket.on('start', function(data) { + console.log(socket.id + ' ' + data.x + ' ' + data.y + ' ' + data.r); + var blob = new Blob(socket.id, data.x, data.y, data.r); + blobs.push(blob); + }); - socket.on('update', - function(data) { - //console.log(socket.id + " " + data.x + " " + data.y + " " + data.r); - var blob; - for (var i = 0; i < blobs.length; i++) { - if (socket.id == blobs[i].id) { - blob = blobs[i]; - } + socket.on('update', function(data) { + //console.log(socket.id + " " + data.x + " " + data.y + " " + data.r); + var blob; + for (var i = 0; i < blobs.length; i++) { + if (socket.id == blobs[i].id) { + blob = blobs[i]; } - blob.x = data.x; - blob.y = data.y; - blob.r = data.r; } - ); - - + blob.x = data.x; + blob.y = data.y; + blob.r = data.r; + }); socket.on('disconnect', function() { - console.log("Client has disconnected"); + console.log('Client has disconnected'); }); } ); diff --git a/CodingChallenges/CC_033_poisson_disc/P5/sketch.js b/CodingChallenges/CC_033_poisson_disc/P5/sketch.js index f5f2ed5c85..6c4e819b0d 100644 --- a/CodingChallenges/CC_033_poisson_disc/P5/sketch.js +++ b/CodingChallenges/CC_033_poisson_disc/P5/sketch.js @@ -53,11 +53,17 @@ function draw() { var col = floor(sample.x / w); var row = floor(sample.y / w); - if (col > -1 && row > -1 && col < cols && row < rows && !grid[col + row * cols]) { + if ( + col > -1 && + row > -1 && + col < cols && + row < rows && + !grid[col + row * cols] + ) { var ok = true; for (var i = -1; i <= 1; i++) { for (var j = -1; j <= 1; j++) { - var index = (col + i) + (row + j) * cols; + var index = col + i + (row + j) * cols; var neighbor = grid[index]; if (neighbor) { var d = p5.Vector.dist(sample, neighbor); @@ -81,7 +87,6 @@ function draw() { if (!found) { active.splice(randIndex, 1); } - } } diff --git a/CodingChallenges/CC_034_DLA/P5/sketch.js b/CodingChallenges/CC_034_DLA/P5/sketch.js index e87c1cdb25..545524e67d 100644 --- a/CodingChallenges/CC_034_DLA/P5/sketch.js +++ b/CodingChallenges/CC_034_DLA/P5/sketch.js @@ -55,5 +55,4 @@ function draw() { radius *= shrink; walkers.push(new Walker()); } - } diff --git a/CodingChallenges/CC_034_DLA/P5/walker.js b/CodingChallenges/CC_034_DLA/P5/walker.js index 1ba7ad4ece..c20cf4e595 100644 --- a/CodingChallenges/CC_034_DLA/P5/walker.js +++ b/CodingChallenges/CC_034_DLA/P5/walker.js @@ -19,13 +19,15 @@ function Walker(x, y) { this.pos.add(vel); this.pos.x = constrain(this.pos.x, 0, width); this.pos.y = constrain(this.pos.y, 0, height); - } - + }; this.checkStuck = function(others) { for (var i = 0; i < others.length; i++) { var d = distSq(this.pos, others[i].pos); - if (d < (this.r * this.r + others[i].r * others[i].r + 2 * others[i].r * this.r)) { + if ( + d < + this.r * this.r + others[i].r * others[i].r + 2 * others[i].r * this.r + ) { //if (random(1) < 0.1) { this.stuck = true; return true; @@ -34,11 +36,11 @@ function Walker(x, y) { } } return false; - } + }; this.setHue = function(hu) { this.hu = hu; - } + }; this.show = function() { noStroke(); @@ -48,8 +50,7 @@ function Walker(x, y) { fill(360, 0, 255); } ellipse(this.pos.x, this.pos.y, this.r * 2, this.r * 2); - } - + }; } function randomPoint() { @@ -70,7 +71,6 @@ function randomPoint() { } } - function distSq(a, b) { var dx = b.x - a.x; var dy = b.y - a.y; diff --git a/CodingChallenges/CC_035.1_TSP/P5/sketch.js b/CodingChallenges/CC_035.1_TSP/P5/sketch.js index a8c7d6fb73..2afd7eb617 100644 --- a/CodingChallenges/CC_035.1_TSP/P5/sketch.js +++ b/CodingChallenges/CC_035.1_TSP/P5/sketch.js @@ -19,7 +19,6 @@ function setup() { var d = calcDistance(cities); recordDistance = d; bestEver = cities.slice(); - } function draw() { @@ -28,7 +27,7 @@ function draw() { noStroke(); textSize(12); text(`Best: ${floor(recordDistance)}`, 340, 10); - + fill(255); for (var i = 0; i < cities.length; i++) { ellipse(cities[i].x, cities[i].y, 8, 8); @@ -52,8 +51,6 @@ function draw() { } endShape(); - - var i = floor(random(cities.length)); var j = floor(random(cities.length)); swap(cities, i, j); @@ -71,7 +68,6 @@ function swap(a, i, j) { a[j] = temp; } - function calcDistance(points) { var sum = 0; for (var i = 0; i < points.length - 1; i++) { diff --git a/CodingChallenges/CC_035.2_LexicographicOrder/P5/sketch.js b/CodingChallenges/CC_035.2_LexicographicOrder/P5/sketch.js index 0f0599dc7b..94759b27b4 100644 --- a/CodingChallenges/CC_035.2_LexicographicOrder/P5/sketch.js +++ b/CodingChallenges/CC_035.2_LexicographicOrder/P5/sketch.js @@ -49,8 +49,6 @@ function draw() { } fill(255); text(s, 20, height / 2); - - } function swap(a, i, j) { diff --git a/CodingChallenges/CC_035.3_TSP_Lexical/P5/sketch.js b/CodingChallenges/CC_035.3_TSP_Lexical/P5/sketch.js index 8a17d9fb52..6df4229c83 100644 --- a/CodingChallenges/CC_035.3_TSP_Lexical/P5/sketch.js +++ b/CodingChallenges/CC_035.3_TSP_Lexical/P5/sketch.js @@ -11,7 +11,6 @@ var order = []; var totalPermutations; var count = 0; - var recordDistance; var bestEver; @@ -29,7 +28,6 @@ function setup() { totalPermutations = factorial(totalCities); console.log(totalPermutations); - } function draw() { @@ -50,7 +48,6 @@ function draw() { } endShape(); - translate(0, height / 2); stroke(255); strokeWeight(1); @@ -62,8 +59,6 @@ function draw() { } endShape(); - - var d = calcDistance(cities, order); if (d < recordDistance) { recordDistance = d; @@ -77,11 +72,9 @@ function draw() { // } fill(255); var percent = 100 * (count / totalPermutations); - text(nf(percent, 0, 2) + "% completed", 20, height / 2 - 50); + text(nf(percent, 0, 2) + '% completed', 20, height / 2 - 50); nextOrder(); - - } function swap(a, i, j) { @@ -90,7 +83,6 @@ function swap(a, i, j) { a[j] = temp; } - function calcDistance(points, order) { var sum = 0; for (var i = 0; i < order.length - 1; i++) { diff --git a/CodingChallenges/CC_035.4_TSP_GA/P5/ga.js b/CodingChallenges/CC_035.4_TSP_GA/P5/ga.js index c4e6a45ce0..8a253291ec 100644 --- a/CodingChallenges/CC_035.4_TSP_GA/P5/ga.js +++ b/CodingChallenges/CC_035.4_TSP_GA/P5/ga.js @@ -22,7 +22,6 @@ function calculateFitness() { currentBest = population[i]; } - // This fitness function has been edited from the original video // to improve performance, as discussed in The Nature of Code 9.6 video, // available here: https://www.youtube.com/watch?v=HzaLIO9dLbA @@ -50,7 +49,6 @@ function nextGeneration() { newPopulation[i] = order; } population = newPopulation; - } function pickOne(list, prob) { @@ -79,7 +77,6 @@ function crossOver(orderA, orderB) { return neworder; } - function mutate(order, mutationRate) { for (var i = 0; i < totalCities; i++) { if (random(1) < mutationRate) { diff --git a/CodingChallenges/CC_035.4_TSP_GA/P5/sketch.js b/CodingChallenges/CC_035.4_TSP_GA/P5/sketch.js index 10b83fd23a..54f5782d09 100644 --- a/CodingChallenges/CC_035.4_TSP_GA/P5/sketch.js +++ b/CodingChallenges/CC_035.4_TSP_GA/P5/sketch.js @@ -67,11 +67,6 @@ function draw() { ellipse(cities[n].x, cities[n].y, 16, 16); } endShape(); - - - - - } // function shuffle(a, num) { @@ -82,14 +77,12 @@ function draw() { // } // } - function swap(a, i, j) { var temp = a[i]; a[i] = a[j]; a[j] = temp; } - function calcDistance(points, order) { var sum = 0; for (var i = 0; i < order.length - 1; i++) { diff --git a/CodingChallenges/CC_037_diastic/P5/sketch.js b/CodingChallenges/CC_037_diastic/P5/sketch.js index a40a99e548..b231317f23 100644 --- a/CodingChallenges/CC_037_diastic/P5/sketch.js +++ b/CodingChallenges/CC_037_diastic/P5/sketch.js @@ -4,8 +4,7 @@ // Code for: https://youtu.be/u-HUtrpyi1c function diastic(seed, words) { - - var phrase = ""; + var phrase = ''; var currentWord = 0; for (var i = 0; i < seed.length; i++) { @@ -14,7 +13,7 @@ function diastic(seed, words) { for (var j = currentWord; j < words.length; j++) { if (words[j].charAt(i) == c) { phrase += words[j]; - phrase += " "; + phrase += ' '; currentWord = j + 1; //console.log(words[j]); break; @@ -24,11 +23,6 @@ function diastic(seed, words) { return phrase; } - - - - - var srctxt; var words; @@ -36,21 +30,17 @@ function preload() { srctxt = loadStrings('rainbow.txt'); } - function setup() { noCanvas(); srctxt = join(srctxt, ' '); words = splitTokens(srctxt, ' ,!.?'); - var seed = select("#seed"); - var submit = select("#submit"); + var seed = select('#seed'); + var submit = select('#submit'); submit.mousePressed(function() { var phrase = diastic(seed.value(), words); createP(phrase); // createP(seed.value()); // createP(srctxt); }); - - - } diff --git a/CodingChallenges/CC_038_word_interactor/P5/sketch.js b/CodingChallenges/CC_038_word_interactor/P5/sketch.js index b13c9c71aa..584c05bb69 100644 --- a/CodingChallenges/CC_038_word_interactor/P5/sketch.js +++ b/CodingChallenges/CC_038_word_interactor/P5/sketch.js @@ -10,9 +10,9 @@ var submit; function setup() { console.log(this); noCanvas(); - textfield = select("#input"); + textfield = select('#input'); output = select('#output'); - submit = select("#submit"); + submit = select('#submit'); submit.mousePressed(newText); } @@ -33,7 +33,6 @@ function newText() { var words = s.split(/(\W+)/); console.log(words); for (var i = 0; i < words.length; i++) { - var span = createSpan(words[i]); span.parent(output); diff --git a/CodingChallenges/CC_039_madlibs/P5/sketch.js b/CodingChallenges/CC_039_madlibs/P5/sketch.js index 94d1422a85..c0d817751c 100644 --- a/CodingChallenges/CC_039_madlibs/P5/sketch.js +++ b/CodingChallenges/CC_039_madlibs/P5/sketch.js @@ -5,7 +5,8 @@ var data; -var txt = '$$Exclamation$$! they said $$Adverb$$ as they jumped into their $$Noun$$ and flew off with their $$Adjective$$ $$PluralNoun$$.'; +var txt = + '$$Exclamation$$! they said $$Adverb$$ as they jumped into their $$Noun$$ and flew off with their $$Adjective$$ $$PluralNoun$$.'; function setup() { noCanvas(); @@ -24,7 +25,6 @@ function replacer(match, pos) { return entry[pos]; } - function generate() { //console.log('generate'); var madlib = txt.replace(/\$\$(.*?)\$\$/g, replacer); diff --git a/CodingChallenges/CC_040.1_wordcounts/P5/sketch.js b/CodingChallenges/CC_040.1_wordcounts/P5/sketch.js index 3edac87426..03b997c21e 100644 --- a/CodingChallenges/CC_040.1_wordcounts/P5/sketch.js +++ b/CodingChallenges/CC_040.1_wordcounts/P5/sketch.js @@ -9,11 +9,10 @@ var keys = []; function preload() { txt = loadStrings('rainbow.txt'); - } function setup() { - var allwords = txt.join("\n"); + var allwords = txt.join('\n'); var tokens = allwords.split(/\W+/); for (var i = 0; i < tokens.length; i++) { var word = tokens[i].toLowerCase(); @@ -38,10 +37,8 @@ function setup() { for (var i = 0; i < keys.length; i++) { var key = keys[i]; - createDiv(key + " " + counts[key]); + createDiv(key + ' ' + counts[key]); } - - noCanvas(); } diff --git a/CodingChallenges/CC_040.3_tf-idf/P5/sketch.js b/CodingChallenges/CC_040.3_tf-idf/P5/sketch.js index 14b3b7a207..0c3af4c8e5 100644 --- a/CodingChallenges/CC_040.3_tf-idf/P5/sketch.js +++ b/CodingChallenges/CC_040.3_tf-idf/P5/sketch.js @@ -8,7 +8,7 @@ var counts = {}; var keys = []; var allwords = []; -var files = ['rainbow.txt','sports.txt', 'eclipse.txt', 'fish.txt']; +var files = ['rainbow.txt', 'sports.txt', 'eclipse.txt', 'fish.txt']; function preload() { for (var i = 0; i < files.length; i++) { @@ -18,7 +18,7 @@ function preload() { function setup() { for (var i = 0; i < txt.length; i++) { - allwords[i] = txt[i].join("\n"); + allwords[i] = txt[i].join('\n'); } var tokens = allwords[0].split(/\W+/); @@ -48,8 +48,6 @@ function setup() { othercounts.push(tempcounts); } - - for (var i = 0; i < keys.length; i++) { var word = keys[i]; for (var j = 0; j < othercounts.length; j++) { @@ -66,7 +64,6 @@ function setup() { wordobj.tfidf = wordobj.tf * log(files.length / wordobj.df); } - keys.sort(compare); function compare(a, b) { @@ -77,7 +74,7 @@ function setup() { for (var i = 0; i < keys.length; i++) { var key = keys[i]; - createDiv(key + " " + counts[key].tfidf); + createDiv(key + ' ' + counts[key].tfidf); } noCanvas(); diff --git a/CodingChallenges/CC_041_ClappyBird/P5/bird.js b/CodingChallenges/CC_041_ClappyBird/P5/bird.js index dae38a2e0c..c086a135cd 100644 --- a/CodingChallenges/CC_041_ClappyBird/P5/bird.js +++ b/CodingChallenges/CC_041_ClappyBird/P5/bird.js @@ -15,11 +15,11 @@ function Bird() { fill(255); noStroke(); ellipse(this.x, this.y, 32, 32); - } + }; this.up = function() { this.velocity += this.lift; - } + }; this.update = function() { this.velocity += this.gravity; @@ -35,7 +35,5 @@ function Bird() { this.y = 0; this.velocity = 0; } - - } - + }; } diff --git a/CodingChallenges/CC_041_ClappyBird/P5/pipe.js b/CodingChallenges/CC_041_ClappyBird/P5/pipe.js index e33a5a7abb..76370cec1e 100644 --- a/CodingChallenges/CC_041_ClappyBird/P5/pipe.js +++ b/CodingChallenges/CC_041_ClappyBird/P5/pipe.js @@ -4,7 +4,6 @@ // Code for: https://youtu.be/cXgA1d_E-jY& function Pipe() { - var spacing = random(50, height / 2); var centery = random(spacing, height - spacing); @@ -25,7 +24,7 @@ function Pipe() { } this.highlight = false; return false; - } + }; this.show = function() { noStroke(); @@ -35,11 +34,11 @@ function Pipe() { } rect(this.x, 0, this.w, this.top); rect(this.x, height - this.bottom, this.w, this.bottom); - } + }; this.update = function() { this.x -= this.speed; - } + }; this.offscreen = function() { if (this.x < -this.w) { @@ -47,7 +46,5 @@ function Pipe() { } else { return false; } - } - - + }; } diff --git a/CodingChallenges/CC_041_ClappyBird/P5/sketch.js b/CodingChallenges/CC_041_ClappyBird/P5/sketch.js index dc431cee49..08328b1c28 100644 --- a/CodingChallenges/CC_041_ClappyBird/P5/sketch.js +++ b/CodingChallenges/CC_041_ClappyBird/P5/sketch.js @@ -25,21 +25,17 @@ function draw() { var vol = mic.getLevel(); - for (var i = pipes.length - 1; i >= 0; i--) { pipes[i].show(); pipes[i].update(); if (pipes[i].hits(bird)) { - console.log("HIT"); + console.log('HIT'); } - if (pipes[i].offscreen()) { pipes.splice(i, 1); } - - } bird.update(); @@ -76,8 +72,6 @@ function draw() { stroke(0, 0, 255); strokeWeight(4); line(width - 50, by, width, by); - - } function keyPressed() { diff --git a/CodingChallenges/CC_042.1_markov-chain/P5/sketch.js b/CodingChallenges/CC_042.1_markov-chain/P5/sketch.js index 7226b5533e..b12e721888 100644 --- a/CodingChallenges/CC_042.1_markov-chain/P5/sketch.js +++ b/CodingChallenges/CC_042.1_markov-chain/P5/sketch.js @@ -3,9 +3,9 @@ // http://patreon.com/codingtrain // Code for: https://youtu.be/eGFJ8vugIWA - //var txt = "the theremin is theirs, ok? yes, it is. this is a theremin."; -var txt = "The unicorn is a legendary creature that has been described since antiquity as a beast with a large, pointed, spiraling horn projecting from its forehead. The unicorn was depicted in ancient seals of the Indus Valley Civilization and was mentioned by the ancient Greeks in accounts of natural history by various writers, including Ctesias, Strabo, Pliny the Younger, and Aelian.[1] The Bible also describes an animal, the re'em, which some translations have erroneously rendered with the word unicorn.[1] In European folklore, the unicorn is often depicted as a white horse-like or goat-like animal with a long horn and cloven hooves (sometimes a goat's beard). In the Middle Ages and Renaissance, it was commonly described as an extremely wild woodland creature, a symbol of purity and grace, which could only be captured by a virgin. In the encyclopedias its horn was said to have the power to render poisoned water potable and to heal sickness. In medieval and Renaissance times, the tusk of the narwhal was sometimes sold as unicorn horn."; +var txt = + "The unicorn is a legendary creature that has been described since antiquity as a beast with a large, pointed, spiraling horn projecting from its forehead. The unicorn was depicted in ancient seals of the Indus Valley Civilization and was mentioned by the ancient Greeks in accounts of natural history by various writers, including Ctesias, Strabo, Pliny the Younger, and Aelian.[1] The Bible also describes an animal, the re'em, which some translations have erroneously rendered with the word unicorn.[1] In European folklore, the unicorn is often depicted as a white horse-like or goat-like animal with a long horn and cloven hooves (sometimes a goat's beard). In the Middle Ages and Renaissance, it was commonly described as an extremely wild woodland creature, a symbol of purity and grace, which could only be captured by a virgin. In the encyclopedias its horn was said to have the power to render poisoned water potable and to heal sickness. In medieval and Renaissance times, the tusk of the narwhal was sometimes sold as unicorn horn."; var order = 2; var ngrams = {}; var button; @@ -21,13 +21,12 @@ function setup() { } ngrams[gram].push(txt.charAt(i + order)); } - button = createButton("generate"); + button = createButton('generate'); button.mousePressed(markovIt); console.log(ngrams); } function markovIt() { - var currentGram = txt.substring(0, order); var result = currentGram; @@ -43,4 +42,4 @@ function markovIt() { } createP(result); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_042.2_markov-chain-names/P5/sketch.js b/CodingChallenges/CC_042.2_markov-chain-names/P5/sketch.js index e92f153883..717276e56d 100644 --- a/CodingChallenges/CC_042.2_markov-chain-names/P5/sketch.js +++ b/CodingChallenges/CC_042.2_markov-chain-names/P5/sketch.js @@ -32,13 +32,12 @@ function setup() { ngrams[gram].push(txt.charAt(i + order)); } } - button = createButton("generate"); + button = createButton('generate'); button.mousePressed(markovIt); console.log(ngrams); } function markovIt() { - var currentGram = random(beginnings); var result = currentGram; @@ -54,4 +53,4 @@ function markovIt() { } createP(result); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_043_ContextFreeGrammar/P5/sketch.js b/CodingChallenges/CC_043_ContextFreeGrammar/P5/sketch.js index 2c48203c7e..264c73cc2a 100644 --- a/CodingChallenges/CC_043_ContextFreeGrammar/P5/sketch.js +++ b/CodingChallenges/CC_043_ContextFreeGrammar/P5/sketch.js @@ -4,56 +4,36 @@ // Code for: https://youtu.be/8Z9FRiW2Jlc var rules = { - "S": [ - ["NP", "VP"], - ["Interj", "NP", "VP"] + S: [ + ['NP', 'VP'], + ['Interj', 'NP', 'VP'] ], - "NP": [ - ["Det", "N"], - ["Det", "N", "that", "VP"], - ["Det", "Adj", "N"] + NP: [ + ['Det', 'N'], + ['Det', 'N', 'that', 'VP'], + ['Det', 'Adj', 'N'] ], - "VP": [ - ["Vtrans", "NP"], - ["Vintr"] + VP: [['Vtrans', 'NP'], ['Vintr']], + Interj: [['oh'], ['my'], ['wow'], ['darn']], + Det: [['this'], ['that'], ['the']], + N: [ + ['amoeba'], + ['dichotomy'], + ['seagull'], + ['trombone'], + ['overstaffed'], + ['corsage'] ], - "Interj": [ - ["oh"], - ["my"], - ["wow"], - ["darn"] + Adj: [ + ['bald'], + ['smug'], + ['important'], + ['tame'], + ['overstaffed'], + ['corsage'] ], - "Det": [ - ["this"], - ["that"], - ["the"] - ], - "N": [ - ["amoeba"], - ["dichotomy"], - ["seagull"], - ["trombone"], - ["overstaffed"], - ["corsage"] - ], - "Adj": [ - ["bald"], - ["smug"], - ["important"], - ["tame"], - ["overstaffed"], - ["corsage"] - ], - "Vtrans": [ - ["computes"], - ["examines"], - ["foregrounds"], - ], - "Vintr": [ - ["coughs"], - ["daydreams"], - ["whines"], - ] + Vtrans: [['computes'], ['examines'], ['foregrounds']], + Vintr: [['coughs'], ['daydreams'], ['whines']] }; // var rules = { // "S": [ @@ -79,7 +59,7 @@ function expand(start, expansion) { } else { expansion.push(start); } - return expansion.join(" "); + return expansion.join(' '); } var button; @@ -91,14 +71,9 @@ function setup() { } function cfg() { - - var start = "S"; + var start = 'S'; var expansion = []; var result = expand(start, expansion); console.log(result); createP(result); - - - - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_044_afinn111SentimentAnalysis/P5/convert.js b/CodingChallenges/CC_044_afinn111SentimentAnalysis/P5/convert.js index 4b85208944..623bad49f0 100644 --- a/CodingChallenges/CC_044_afinn111SentimentAnalysis/P5/convert.js +++ b/CodingChallenges/CC_044_afinn111SentimentAnalysis/P5/convert.js @@ -4,7 +4,7 @@ // Code for: https://youtu.be/uw3GbsY_Pbc var table; -var afinn = {} +var afinn = {}; function preload() { table = loadTable('AFINN-111.txt', 'tsv'); @@ -23,11 +23,6 @@ function setup() { } console.log(afinn); save(afinn, 'afinn111.json'); - - - } -function draw() { - -} \ No newline at end of file +function draw() {} diff --git a/CodingChallenges/CC_044_afinn111SentimentAnalysis/P5/sketch.js b/CodingChallenges/CC_044_afinn111SentimentAnalysis/P5/sketch.js index 9488298a53..eb9711a3d7 100644 --- a/CodingChallenges/CC_044_afinn111SentimentAnalysis/P5/sketch.js +++ b/CodingChallenges/CC_044_afinn111SentimentAnalysis/P5/sketch.js @@ -3,14 +3,12 @@ // http://patreon.com/codingtrain // Code for: https://youtu.be/VV1JmMYceJw - var afinn; function preload() { afinn = loadJSON('afinn111.json'); } - function setup() { noCanvas(); console.log(afinn); @@ -44,10 +42,4 @@ function setup() { } } - - - - -function draw() { - -} \ No newline at end of file +function draw() {} diff --git a/CodingChallenges/CC_045_FirebaseSavingDrawing/P5/sketch.js b/CodingChallenges/CC_045_FirebaseSavingDrawing/P5/sketch.js index c8bec29f37..4ad2d44f63 100644 --- a/CodingChallenges/CC_045_FirebaseSavingDrawing/P5/sketch.js +++ b/CodingChallenges/CC_045_FirebaseSavingDrawing/P5/sketch.js @@ -12,8 +12,6 @@ var isDrawing = false; function setup() { canvas = createCanvas(200, 200); - - canvas.mousePressed(startPath); canvas.parent('canvascontainer'); canvas.mouseReleased(endPath); @@ -24,14 +22,12 @@ function setup() { var clearButton = select('#clearButton'); clearButton.mousePressed(clearDrawing); - - var config = { apiKey: [YOUR_API_KEY], - authDomain: "my-not-awesome-project.firebaseapp.com", - databaseURL: "https://my-not-awesome-project.firebaseio.com", - storageBucket: "my-not-awesome-project.appspot.com", - messagingSenderId: "583703514528" + authDomain: 'my-not-awesome-project.firebaseapp.com', + databaseURL: 'https://my-not-awesome-project.firebaseio.com', + storageBucket: 'my-not-awesome-project.appspot.com', + messagingSenderId: '583703514528' }; firebase.initializeApp(config); database = firebase.database(); @@ -43,7 +39,6 @@ function setup() { showDrawing(params.id); } - var ref = database.ref('drawings'); ref.on('value', gotData, errData); } @@ -65,7 +60,7 @@ function draw() { var point = { x: mouseX, y: mouseY - } + }; currentPath.push(point); } @@ -76,21 +71,18 @@ function draw() { var path = drawing[i]; beginShape(); for (var j = 0; j < path.length; j++) { - vertex(path[j].x, path[j].y) + vertex(path[j].x, path[j].y); } endShape(); } - - } - function saveDrawing() { var ref = database.ref('drawings'); var data = { - name: "Dan", + name: 'Dan', drawing: drawing - } + }; var result = ref.push(data, dataSent); console.log(result.key); @@ -100,7 +92,6 @@ function saveDrawing() { } function gotData(data) { - // clear the listing var elts = selectAll('.listing'); for (var i = 0; i < elts.length; i++) { @@ -144,10 +135,8 @@ function showDrawing(key) { drawing = dbdrawing.drawing; //console.log(drawing); } - } - function clearDrawing() { drawing = []; -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_046_Asteroids/P5/asteroid.js b/CodingChallenges/CC_046_Asteroids/P5/asteroid.js index 3a98369959..977e1da7e7 100644 --- a/CodingChallenges/CC_046_Asteroids/P5/asteroid.js +++ b/CodingChallenges/CC_046_Asteroids/P5/asteroid.js @@ -7,7 +7,7 @@ function Asteroid(pos, r) { if (pos) { this.pos = pos.copy(); } else { - this.pos = createVector(random(width), random(height)) + this.pos = createVector(random(width), random(height)); } if (r) { this.r = r * 0.5; @@ -24,7 +24,7 @@ function Asteroid(pos, r) { this.update = function() { this.pos.add(this.vel); - } + }; this.render = function() { push(); @@ -42,14 +42,14 @@ function Asteroid(pos, r) { } endShape(CLOSE); pop(); - } + }; this.breakup = function() { var newA = []; newA[0] = new Asteroid(this.pos, this.r); newA[1] = new Asteroid(this.pos, this.r); return newA; - } + }; this.edges = function() { if (this.pos.x > width + this.r) { @@ -62,6 +62,5 @@ function Asteroid(pos, r) { } else if (this.pos.y < -this.r) { this.pos.y = height + this.r; } - } - + }; } diff --git a/CodingChallenges/CC_046_Asteroids/P5/laser.js b/CodingChallenges/CC_046_Asteroids/P5/laser.js index d16494c904..aa2648c8df 100644 --- a/CodingChallenges/CC_046_Asteroids/P5/laser.js +++ b/CodingChallenges/CC_046_Asteroids/P5/laser.js @@ -10,15 +10,15 @@ function Laser(spos, angle) { this.update = function() { this.pos.add(this.vel); - } - + }; + this.render = function() { push(); stroke(255); strokeWeight(4); point(this.pos.x, this.pos.y); pop(); - } + }; this.hits = function(asteroid) { var d = dist(this.pos.x, this.pos.y, asteroid.pos.x, asteroid.pos.y); @@ -27,7 +27,7 @@ function Laser(spos, angle) { } else { return false; } - } + }; this.offscreen = function() { if (this.pos.x > width || this.pos.x < 0) { @@ -37,7 +37,5 @@ function Laser(spos, angle) { return true; } return false; - } - - + }; } diff --git a/CodingChallenges/CC_046_Asteroids/P5/ship.js b/CodingChallenges/CC_046_Asteroids/P5/ship.js index 364290313f..b0a4e8e02d 100644 --- a/CodingChallenges/CC_046_Asteroids/P5/ship.js +++ b/CodingChallenges/CC_046_Asteroids/P5/ship.js @@ -13,7 +13,7 @@ function Ship() { this.boosting = function(b) { this.isBoosting = b; - } + }; this.update = function() { if (this.isBoosting) { @@ -21,13 +21,13 @@ function Ship() { } this.pos.add(this.vel); this.vel.mult(0.99); - } + }; this.boost = function() { var force = p5.Vector.fromAngle(this.heading); force.mult(0.1); this.vel.add(force); - } + }; this.hits = function(asteroid) { var d = dist(this.pos.x, this.pos.y, asteroid.pos.x, asteroid.pos.y); @@ -36,7 +36,7 @@ function Ship() { } else { return false; } - } + }; this.render = function() { push(); @@ -46,7 +46,7 @@ function Ship() { stroke(255); triangle(-this.r, this.r, this.r, this.r, 0, -this.r); pop(); - } + }; this.edges = function() { if (this.pos.x > width + this.r) { @@ -59,14 +59,13 @@ function Ship() { } else if (this.pos.y < -this.r) { this.pos.y = height + this.r; } - } + }; this.setRotation = function(a) { this.rotation = a; - } + }; this.turn = function() { this.heading += this.rotation; - } - + }; } diff --git a/CodingChallenges/CC_046_Asteroids/P5/sketch.js b/CodingChallenges/CC_046_Asteroids/P5/sketch.js index 57081e8762..023e2503d9 100644 --- a/CodingChallenges/CC_046_Asteroids/P5/sketch.js +++ b/CodingChallenges/CC_046_Asteroids/P5/sketch.js @@ -53,8 +53,6 @@ function draw() { ship.turn(); ship.update(); ship.edges(); - - } function keyReleased() { diff --git a/CodingChallenges/CC_047_PixelSorting/P5/sketch.js b/CodingChallenges/CC_047_PixelSorting/P5/sketch.js index 9c92db5489..29d63923c2 100644 --- a/CodingChallenges/CC_047_PixelSorting/P5/sketch.js +++ b/CodingChallenges/CC_047_PixelSorting/P5/sketch.js @@ -12,61 +12,66 @@ let sorted; let index = 0; function preload() { - // try data/sunflower.jpg or data/sunflower400.jpg - img = loadImage("data/sunflower100.jpg"); + // try data/sunflower.jpg or data/sunflower400.jpg + img = loadImage('data/sunflower100.jpg'); } function setup() { - createCanvas(200, 100); + createCanvas(200, 100); - sorted = createImage(img.width, img.height); - sorted = img.get(); + sorted = createImage(img.width, img.height); + sorted = img.get(); } function draw() { - console.log(frameRate()); + console.log(frameRate()); - sorted.loadPixels(); + sorted.loadPixels(); - // Selection sort! - for (let n = 0; n < 1; n++) { - let record = -1; - let selectedPixel = index; - for (let j = index; j < sorted.pixels.length; j += 4) { - let pix = color(sorted.pixels[j], sorted.pixels[j + 1], sorted.pixels[j + 2], sorted.pixels[j + 3]); - let b = hue(pix); - if (b > record) { - selectedPixel = j; - record = b; - } - } + // Selection sort! + for (let n = 0; n < 1; n++) { + let record = -1; + let selectedPixel = index; + for (let j = index; j < sorted.pixels.length; j += 4) { + let pix = color( + sorted.pixels[j], + sorted.pixels[j + 1], + sorted.pixels[j + 2], + sorted.pixels[j + 3] + ); + let b = hue(pix); + if (b > record) { + selectedPixel = j; + record = b; + } + } - // Swap selectedPixel with i - let temp = []; - temp[0] = sorted.pixels[index]; - temp[1] = sorted.pixels[index + 1]; - temp[2] = sorted.pixels[index + 2]; - temp[3] = sorted.pixels[index + 3]; - sorted.pixels[index] = sorted.pixels[selectedPixel]; - sorted.pixels[index + 1] = sorted.pixels[selectedPixel + 1]; - sorted.pixels[index + 2] = sorted.pixels[selectedPixel + 2]; - sorted.pixels[index + 3] = sorted.pixels[selectedPixel + 3]; - sorted.pixels[selectedPixel] = temp[0]; - sorted.pixels[selectedPixel + 1] = temp[1]; - sorted.pixels[selectedPixel + 2] = temp[2]; - sorted.pixels[selectedPixel + 3] = temp[3]; + // Swap selectedPixel with i + let temp = []; + temp[0] = sorted.pixels[index]; + temp[1] = sorted.pixels[index + 1]; + temp[2] = sorted.pixels[index + 2]; + temp[3] = sorted.pixels[index + 3]; + sorted.pixels[index] = sorted.pixels[selectedPixel]; + sorted.pixels[index + 1] = sorted.pixels[selectedPixel + 1]; + sorted.pixels[index + 2] = sorted.pixels[selectedPixel + 2]; + sorted.pixels[index + 3] = sorted.pixels[selectedPixel + 3]; + sorted.pixels[selectedPixel] = temp[0]; + sorted.pixels[selectedPixel + 1] = temp[1]; + sorted.pixels[selectedPixel + 2] = temp[2]; + sorted.pixels[selectedPixel + 3] = temp[3]; - if (index < sorted.pixels.length - 1) { - index += 4; - } + if (index < sorted.pixels.length - 1) { + index += 4; } + } - sorted.updatePixels(); + sorted.updatePixels(); - background(0); - image(img, 0, 0); - image(sorted, 100, 0); + background(0); + image(img, 0, 0); + image(sorted, 100, 0); - noStroke(); - fill(255); + noStroke(); + fill(255); } diff --git a/CodingChallenges/CC_048_TweetsByMonth/P5/sketch.js b/CodingChallenges/CC_048_TweetsByMonth/P5/sketch.js index d07db9010a..3afa9253c6 100644 --- a/CodingChallenges/CC_048_TweetsByMonth/P5/sketch.js +++ b/CodingChallenges/CC_048_TweetsByMonth/P5/sketch.js @@ -2,7 +2,6 @@ // https://github.com/ITPNYU/Obamathon // YouTube video tutorial: https://youtu.be/UrznYJltZrU - // All data var potus; @@ -13,24 +12,22 @@ var counts = {}; // This is silly and a better strategy would be to load from a text files // or use an algorithm like TF-IDF to pick out unique words var ignore = { - "the": 'true', - "to": 'true', - "we": 'true', - "of": 'true', - "and": 'true', - "a": 'true', - "http": 'true', - "https": 'true', - "our": 'true' -} + the: 'true', + to: 'true', + we: 'true', + of: 'true', + and: 'true', + a: 'true', + http: 'true', + https: 'true', + our: 'true' +}; // Load the data function preload() { potus = loadJSON('flotus.json'); - } - function setup() { createCanvas(600, 400); var tweets = potus.tweets; @@ -71,7 +68,6 @@ function setup() { } } } - } background(0); @@ -115,7 +111,5 @@ function setup() { // Draw the word fill(255); text(biggestWord, i * w, height - h - 5); - } - } diff --git a/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_A_CirclePackingAnimated/Circle.js b/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_A_CirclePackingAnimated/Circle.js index 83c3f9984a..1d1e1490b5 100644 --- a/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_A_CirclePackingAnimated/Circle.js +++ b/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_A_CirclePackingAnimated/Circle.js @@ -13,7 +13,7 @@ function Circle(x, y) { if (this.growing) { this.r += 1; } - } + }; this.show = function() { stroke(255); @@ -21,9 +21,14 @@ function Circle(x, y) { strokeWeight(2); ellipse(this.x, this.y, this.r * 2, this.r * 2); - } + }; this.edges = function() { - return (this.x + this.r >= width || this.x - this.r <= 0 || this.y + this.r >= height || this.y - this.r <= 0) - } + return ( + this.x + this.r >= width || + this.x - this.r <= 0 || + this.y + this.r >= height || + this.y - this.r <= 0 + ); + }; } diff --git a/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_A_CirclePackingAnimated/sketch.js b/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_A_CirclePackingAnimated/sketch.js index 7862004943..ea6d6f8dc8 100644 --- a/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_A_CirclePackingAnimated/sketch.js +++ b/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_A_CirclePackingAnimated/sketch.js @@ -12,7 +12,7 @@ function setup() { function draw() { background(0); - frameRate(20) + frameRate(20); var total = 5; var count = 0; @@ -27,7 +27,7 @@ function draw() { attempts++; if (attempts > 100) { noLoop(); - console.log("finished"); + console.log('finished'); break; } } diff --git a/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_B_CirclePackingAnimatedText/Circle.js b/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_B_CirclePackingAnimatedText/Circle.js index a49ff403c8..da6410c1ed 100644 --- a/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_B_CirclePackingAnimatedText/Circle.js +++ b/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_B_CirclePackingAnimatedText/Circle.js @@ -13,16 +13,21 @@ function Circle(x, y) { if (this.growing) { this.r += 0.5; } - } + }; this.show = function() { - stroke("red"); + stroke('red'); strokeWeight(2); noFill(); ellipse(this.x, this.y, this.r * 2, this.r * 2); - } + }; this.edges = function() { - return (this.x + this.r >= width || this.x - this.r <= 0 || this.y + this.r >= height || this.y - this.r <= 0) - } + return ( + this.x + this.r >= width || + this.x - this.r <= 0 || + this.y + this.r >= height || + this.y - this.r <= 0 + ); + }; } diff --git a/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_B_CirclePackingAnimatedText/sketch.js b/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_B_CirclePackingAnimatedText/sketch.js index 29ecb268e8..c0b7a7050b 100644 --- a/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_B_CirclePackingAnimatedText/sketch.js +++ b/CodingChallenges/CC_050.1_CirclePackingAnimated/P5/CC_050.1_B_CirclePackingAnimatedText/sketch.js @@ -8,7 +8,7 @@ var spots; var img; function preload() { - img = loadImage("assets/2017.png"); + img = loadImage('assets/2017.png'); } function setup() { @@ -21,7 +21,7 @@ function setup() { for (var x = 0; x < img.width; x++) { for (var y = 0; y < img.height; y++) { var index = x + y * img.width; - var c = img.pixels[index*4]; + var c = img.pixels[index * 4]; var b = brightness([c]); if (b > 1) { spots.push(createVector(x, y)); @@ -31,9 +31,9 @@ function setup() { console.log(img.width); console.log(img.height); - console.log("pixels", img.pixels.length); - console.log("spots", spots.length); - console.log(density) + console.log('pixels', img.pixels.length); + console.log('spots', spots.length); + console.log(density); } function draw() { @@ -53,7 +53,7 @@ function draw() { attempts++; if (attempts > 1000) { noLoop(); - console.log("finished"); + console.log('finished'); break; } } diff --git a/CodingChallenges/CC_050.2_CirclePackingImage/P5/Circle.js b/CodingChallenges/CC_050.2_CirclePackingImage/P5/Circle.js index bdd8d876ab..51d33fb811 100644 --- a/CodingChallenges/CC_050.2_CirclePackingImage/P5/Circle.js +++ b/CodingChallenges/CC_050.2_CirclePackingImage/P5/Circle.js @@ -14,15 +14,20 @@ function Circle(x, y, color) { if (this.growing) { this.r += 0.5; } - } + }; this.show = function() { noStroke(); fill(this.color); ellipse(this.x, this.y, this.r * 2, this.r * 2); - } + }; this.edges = function() { - return (this.x + this.r >= width || this.x - this.r <= 0 || this.y + this.r >= height || this.y - this.r <= 0) - } + return ( + this.x + this.r >= width || + this.x - this.r <= 0 || + this.y + this.r >= height || + this.y - this.r <= 0 + ); + }; } diff --git a/CodingChallenges/CC_050.2_CirclePackingImage/P5/sketch.js b/CodingChallenges/CC_050.2_CirclePackingImage/P5/sketch.js index 13eb451220..98f9855bde 100644 --- a/CodingChallenges/CC_050.2_CirclePackingImage/P5/sketch.js +++ b/CodingChallenges/CC_050.2_CirclePackingImage/P5/sketch.js @@ -7,7 +7,7 @@ var circles; var img; function preload() { - img = loadImage("assets/kitten.jpg"); + img = loadImage('assets/kitten.jpg'); } function setup() { @@ -19,8 +19,8 @@ function setup() { console.log(img.width); console.log(img.height); - console.log("pixels", img.pixels.length); - console.log(density) + console.log('pixels', img.pixels.length); + console.log(density); } function draw() { @@ -39,7 +39,7 @@ function draw() { attempts++; if (attempts > 1000) { noLoop(); - console.log("finished"); + console.log('finished'); break; } } @@ -87,9 +87,9 @@ function newCircle() { if (valid) { var index = (int(x) + int(y) * img.width) * 4; var r = img.pixels[index]; - var g = img.pixels[index+1]; - var b = img.pixels[index+2]; - var c = color(r,g,b); + var g = img.pixels[index + 1]; + var b = img.pixels[index + 2]; + var c = color(r, g, b); return new Circle(x, y, color(c)); } else { return null; diff --git a/CodingChallenges/CC_051_astar/P5/sketch.js b/CodingChallenges/CC_051_astar/P5/sketch.js index d4bba8857a..c85acfffde 100644 --- a/CodingChallenges/CC_051_astar/P5/sketch.js +++ b/CodingChallenges/CC_051_astar/P5/sketch.js @@ -69,7 +69,6 @@ function setup() { } } - // Start and end start = grid[0][0]; end = grid[cols - 1][rows - 1]; @@ -81,10 +80,8 @@ function setup() { } function draw() { - // Am I still searching? if (openSet.length > 0) { - // Best next option var winner = 0; for (var i = 0; i < openSet.length; i++) { @@ -97,7 +94,7 @@ function draw() { // Did I finish? if (current === end) { noLoop(); - console.log("DONE!"); + console.log('DONE!'); } // Best option moves from openSet to closedSet @@ -133,9 +130,8 @@ function draw() { neighbor.previous = current; } } - } - // Uh oh, no solution + // Uh oh, no solution } else { console.log('no solution'); noLoop(); @@ -159,7 +155,6 @@ function draw() { openSet[i].show(color(0, 255, 0, 50)); } - // Find the path by working backwards path = []; var temp = current; @@ -169,9 +164,8 @@ function draw() { temp = temp.previous; } - // for (var i = 0; i < path.length; i++) { - // path[i].show(color(0, 0, 255)); + // path[i].show(color(0, 0, 255)); //} // Drawing path as continuous line @@ -183,7 +177,4 @@ function draw() { vertex(path[i].i * w + w / 2, path[i].j * h + h / 2); } endShape(); - - - } diff --git a/CodingChallenges/CC_051_astar/P5/spot.js b/CodingChallenges/CC_051_astar/P5/spot.js index 0a69823786..032d90d262 100644 --- a/CodingChallenges/CC_051_astar/P5/spot.js +++ b/CodingChallenges/CC_051_astar/P5/spot.js @@ -7,7 +7,6 @@ // An object to describe a spot in the grid function Spot(i, j) { - // Location this.i = i; this.j = j; @@ -35,11 +34,11 @@ function Spot(i, j) { fill(0); noStroke(); ellipse(this.i * w + w / 2, this.j * h + h / 2, w / 2, h / 2); - } else if (col){ + } else if (col) { fill(col); rect(this.i * w, this.j * h, w, h); } - } + }; // Figure out who my neighbors are this.addNeighbors = function(grid) { @@ -69,5 +68,5 @@ function Spot(i, j) { if (i < cols - 1 && j < rows - 1) { this.neighbors.push(grid[i + 1][j + 1]); } - } + }; } diff --git a/CodingChallenges/CC_052_random_walk/P5/sketch.js b/CodingChallenges/CC_052_random_walk/P5/sketch.js index ba7ec4fca7..41056c4da2 100644 --- a/CodingChallenges/CC_052_random_walk/P5/sketch.js +++ b/CodingChallenges/CC_052_random_walk/P5/sketch.js @@ -34,6 +34,4 @@ function draw() { y = y - 1; break; } - - } diff --git a/CodingChallenges/CC_053_random_walk_levy/P5/sketch.js b/CodingChallenges/CC_053_random_walk_levy/P5/sketch.js index 78ab74bc6f..8ef72676c1 100644 --- a/CodingChallenges/CC_053_random_walk_levy/P5/sketch.js +++ b/CodingChallenges/CC_053_random_walk_levy/P5/sketch.js @@ -34,5 +34,4 @@ function draw() { //pos = pos + step; pos.add(step); - } diff --git a/CodingChallenges/CC_054.1_StarPatterns/P5/edge.js b/CodingChallenges/CC_054.1_StarPatterns/P5/edge.js index 8dbceca2ed..3280bedaa4 100644 --- a/CodingChallenges/CC_054.1_StarPatterns/P5/edge.js +++ b/CodingChallenges/CC_054.1_StarPatterns/P5/edge.js @@ -19,7 +19,7 @@ function Edge(a, b) { //line(this.a.x, this.a.y, this.b.x, this.b.y); this.h1.show(); this.h2.show(); - } + }; this.hankin = function() { var mid = p5.Vector.add(this.a, this.b); @@ -38,21 +38,17 @@ function Edge(a, b) { v1.normalize(); v2.normalize(); - v1.rotate(radians(-angle)); v2.rotate(radians(angle)); this.h1 = new Hankin(offset1, v1); this.h2 = new Hankin(offset2, v2); - - } + }; this.findEnds = function(edge) { this.h1.findEnd(edge.h1); this.h1.findEnd(edge.h2); this.h2.findEnd(edge.h1); this.h2.findEnd(edge.h2); - } - - + }; } diff --git a/CodingChallenges/CC_054.1_StarPatterns/P5/hankin.js b/CodingChallenges/CC_054.1_StarPatterns/P5/hankin.js index f60afee98b..85a543f2f1 100644 --- a/CodingChallenges/CC_054.1_StarPatterns/P5/hankin.js +++ b/CodingChallenges/CC_054.1_StarPatterns/P5/hankin.js @@ -24,7 +24,7 @@ function Hankin(a, v) { // fill(255, 255, 0); // ellipse(this.end.x, this.end.y, 8); // } - } + }; this.findEnd = function(other) { // line line intersection??? @@ -32,16 +32,18 @@ function Hankin(a, v) { // other.a, other.v (P3, P4-P3) // From: http://paulbourke.net/geometry/pointlineplane/ - var den = (other.v.y * this.v.x) - (other.v.x * this.v.y); + var den = other.v.y * this.v.x - other.v.x * this.v.y; if (!den) { return; } - var numa = (other.v.x * (this.a.y - other.a.y)) - (other.v.y * (this.a.x - other.a.x)); - var numb = (this.v.x * (this.a.y - other.a.y)) - (this.v.y * (this.a.x - other.a.x)); + var numa = + other.v.x * (this.a.y - other.a.y) - other.v.y * (this.a.x - other.a.x); + var numb = + this.v.x * (this.a.y - other.a.y) - this.v.y * (this.a.x - other.a.x); var ua = numa / den; var ub = numb / den; - var x = this.a.x + (ua * this.v.x); - var y = this.a.y + (ua * this.v.y); + var x = this.a.x + ua * this.v.x; + var y = this.a.y + ua * this.v.y; if (ua > 0 && ub > 0) { var candidate = createVector(x, y); @@ -59,9 +61,5 @@ function Hankin(a, v) { } } } - - - - } - + }; } diff --git a/CodingChallenges/CC_054.1_StarPatterns/P5/polygon.js b/CodingChallenges/CC_054.1_StarPatterns/P5/polygon.js index e330935339..d88dbed4aa 100644 --- a/CodingChallenges/CC_054.1_StarPatterns/P5/polygon.js +++ b/CodingChallenges/CC_054.1_StarPatterns/P5/polygon.js @@ -21,7 +21,7 @@ function Polygon() { this.edges.push(edge); } this.vertices.push(a); - } + }; this.close = function() { var total = this.vertices.length; @@ -29,7 +29,7 @@ function Polygon() { var first = this.vertices[0]; var edge = new Edge(last, first); this.edges.push(edge); - } + }; this.hankin = function() { for (var i = 0; i < this.edges.length; i++) { @@ -43,12 +43,11 @@ function Polygon() { } } } - } + }; this.show = function() { for (var i = 0; i < this.edges.length; i++) { this.edges[i].show(); } - } - + }; } diff --git a/CodingChallenges/CC_054.2_StarPatterns/P5/edge.js b/CodingChallenges/CC_054.2_StarPatterns/P5/edge.js index 8ffef8df21..d9ab0a1ae2 100644 --- a/CodingChallenges/CC_054.2_StarPatterns/P5/edge.js +++ b/CodingChallenges/CC_054.2_StarPatterns/P5/edge.js @@ -19,7 +19,7 @@ function Edge(a, b) { line(this.a.x, this.a.y, this.b.x, this.b.y); this.h1.show(); this.h2.show(); - } + }; this.hankin = function(sides) { var mid = p5.Vector.add(this.a, this.b); @@ -46,7 +46,7 @@ function Edge(a, b) { v2.rotate(radians(angle)); // Calculate interior angle - var interior = (sides - 2) * PI / sides; + var interior = ((sides - 2) * PI) / sides; // Law of sines right here! var alpha = interior * 0.5; var beta = PI - radians(angle) - alpha; @@ -57,7 +57,5 @@ function Edge(a, b) { this.h1 = new Hankin(offset1, v1); this.h2 = new Hankin(offset2, v2); - - } - + }; } diff --git a/CodingChallenges/CC_054.2_StarPatterns/P5/hankin.js b/CodingChallenges/CC_054.2_StarPatterns/P5/hankin.js index f9d9d3b368..9a00be4ed7 100644 --- a/CodingChallenges/CC_054.2_StarPatterns/P5/hankin.js +++ b/CodingChallenges/CC_054.2_StarPatterns/P5/hankin.js @@ -16,5 +16,5 @@ function Hankin(a, v) { this.show = function() { stroke(255, 0, 255); line(this.a.x, this.a.y, this.b.x, this.b.y); - } + }; } diff --git a/CodingChallenges/CC_054.2_StarPatterns/P5/polygon.js b/CodingChallenges/CC_054.2_StarPatterns/P5/polygon.js index 3ac4cbee3b..7591f0c4e8 100644 --- a/CodingChallenges/CC_054.2_StarPatterns/P5/polygon.js +++ b/CodingChallenges/CC_054.2_StarPatterns/P5/polygon.js @@ -22,7 +22,7 @@ function Polygon(n) { this.edges.push(edge); } this.vertices.push(a); - } + }; this.close = function() { var total = this.vertices.length; @@ -30,18 +30,17 @@ function Polygon(n) { var first = this.vertices[0]; var edge = new Edge(last, first); this.edges.push(edge); - } + }; this.hankin = function() { for (var i = 0; i < this.edges.length; i++) { this.edges[i].hankin(this.sides); } - } + }; this.show = function() { for (var i = 0; i < this.edges.length; i++) { this.edges[i].show(); } - } - + }; } diff --git a/CodingChallenges/CC_055_Roses/P5/sketch.js b/CodingChallenges/CC_055_Roses/P5/sketch.js index 5366038b6c..7040616380 100644 --- a/CodingChallenges/CC_055_Roses/P5/sketch.js +++ b/CodingChallenges/CC_055_Roses/P5/sketch.js @@ -41,8 +41,8 @@ function draw() { } function reduceDenominator(numerator, denominator) { - function rec(a, b) { - return b ? rec(b, a % b) : a; - } - return denominator / rec(numerator, denominator); -} \ No newline at end of file + function rec(a, b) { + return b ? rec(b, a % b) : a; + } + return denominator / rec(numerator, denominator); +} diff --git a/CodingChallenges/CC_056_attraction_repulsion/P5/particle.js b/CodingChallenges/CC_056_attraction_repulsion/P5/particle.js index 13b64b124c..f3dbe44ee3 100644 --- a/CodingChallenges/CC_056_attraction_repulsion/P5/particle.js +++ b/CodingChallenges/CC_056_attraction_repulsion/P5/particle.js @@ -16,7 +16,7 @@ function Particle(x, y) { this.vel.limit(5); this.pos.add(this.vel); this.acc.mult(0); - } + }; this.show = function() { stroke(255, 255); @@ -25,8 +25,7 @@ function Particle(x, y) { this.prev.x = this.pos.x; this.prev.y = this.pos.y; - - } + }; this.attracted = function(target) { // var dir = target - this.pos @@ -40,6 +39,5 @@ function Particle(x, y) { force.mult(-10); } this.acc.add(force); - } - + }; } diff --git a/CodingChallenges/CC_056_attraction_repulsion/P5/sketch.js b/CodingChallenges/CC_056_attraction_repulsion/P5/sketch.js index b3774caa50..1c9cfb208c 100644 --- a/CodingChallenges/CC_056_attraction_repulsion/P5/sketch.js +++ b/CodingChallenges/CC_056_attraction_repulsion/P5/sketch.js @@ -40,5 +40,4 @@ function draw() { particle.update(); particle.show(); } - } diff --git a/CodingChallenges/CC_057_Earthquake_Viz/P5/sketch.js b/CodingChallenges/CC_057_Earthquake_Viz/P5/sketch.js index 4f09542229..18f7c626d6 100644 --- a/CodingChallenges/CC_057_Earthquake_Viz/P5/sketch.js +++ b/CodingChallenges/CC_057_Earthquake_Viz/P5/sketch.js @@ -16,12 +16,23 @@ var earthquakes; function preload() { // The clon and clat in this url are edited to be in the correct order. - mapimg = loadImage('https://api.mapbox.com/styles/v1/mapbox/dark-v9/static/' + - clon + ',' + clat + ',' + zoom + '/' + - ww + 'x' + hh + - '?access_token=pk.eyJ1IjoiY29kaW5ndHJhaW4iLCJhIjoiY2l6MGl4bXhsMDRpNzJxcDh0a2NhNDExbCJ9.awIfnl6ngyHoB3Xztkzarw'); + mapimg = loadImage( + 'https://api.mapbox.com/styles/v1/mapbox/dark-v9/static/' + + clon + + ',' + + clat + + ',' + + zoom + + '/' + + ww + + 'x' + + hh + + '?access_token=pk.eyJ1IjoiY29kaW5ndHJhaW4iLCJhIjoiY2l6MGl4bXhsMDRpNzJxcDh0a2NhNDExbCJ9.awIfnl6ngyHoB3Xztkzarw' + ); // earthquakes = loadStrings('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.csv'); - earthquakes = loadStrings('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv'); + earthquakes = loadStrings( + 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv' + ); } function mercX(lon) { @@ -39,7 +50,6 @@ function mercY(lat) { return a * c; } - function setup() { createCanvas(ww, hh); translate(width / 2, height / 2); @@ -59,9 +69,9 @@ function setup() { var y = mercY(lat) - cy; // This addition fixes the case where the longitude is non-zero and // points can go off the screen. - if(x < - width/2) { + if (x < -width / 2) { x += width; - } else if(x > width / 2) { + } else if (x > width / 2) { x -= width; } mag = pow(10, mag); @@ -72,5 +82,4 @@ function setup() { fill(255, 0, 255, 200); ellipse(x, y, d, d); } - } diff --git a/CodingChallenges/CC_059_Steering_Text_Paths/P5/vehicle.js b/CodingChallenges/CC_059_Steering_Text_Paths/P5/vehicle.js index 70b418d865..421632e842 100644 --- a/CodingChallenges/CC_059_Steering_Text_Paths/P5/vehicle.js +++ b/CodingChallenges/CC_059_Steering_Text_Paths/P5/vehicle.js @@ -23,24 +23,23 @@ Vehicle.prototype.behaviors = function() { this.applyForce(arrive); this.applyForce(flee); -} +}; Vehicle.prototype.applyForce = function(f) { this.acc.add(f); -} +}; Vehicle.prototype.update = function() { this.pos.add(this.vel); this.vel.add(this.acc); this.acc.mult(0); -} +}; Vehicle.prototype.show = function() { stroke(255); strokeWeight(this.r); point(this.pos.x, this.pos.y); -} - +}; Vehicle.prototype.arrive = function(target) { var desired = p5.Vector.sub(target, this.pos); @@ -53,7 +52,7 @@ Vehicle.prototype.arrive = function(target) { var steer = p5.Vector.sub(desired, this.vel); steer.limit(this.maxforce); return steer; -} +}; Vehicle.prototype.flee = function(target) { var desired = p5.Vector.sub(target, this.pos); @@ -67,4 +66,4 @@ Vehicle.prototype.flee = function(target) { } else { return createVector(0, 0); } -} +}; diff --git a/CodingChallenges/CC_060_Butterfly_Wings/P5/sketch.js b/CodingChallenges/CC_060_Butterfly_Wings/P5/sketch.js index e5a1a1db8b..1b58843b69 100644 --- a/CodingChallenges/CC_060_Butterfly_Wings/P5/sketch.js +++ b/CodingChallenges/CC_060_Butterfly_Wings/P5/sketch.js @@ -28,10 +28,10 @@ function draw() { var r = sin(2 * a) * map(n, 0, 1, 50, 300); var x = r * cos(a); var y = r * sin(a); - if (a < PI){ - xoff += dx; - } else{ - xoff -= dx; + if (a < PI) { + xoff += dx; + } else { + xoff -= dx; } //point(x, y); vertex(x, y); diff --git a/CodingChallenges/CC_061_fractal_spirograph/P5/orbit.js b/CodingChallenges/CC_061_fractal_spirograph/P5/orbit.js index 1a5abffeba..479f03c2f3 100644 --- a/CodingChallenges/CC_061_fractal_spirograph/P5/orbit.js +++ b/CodingChallenges/CC_061_fractal_spirograph/P5/orbit.js @@ -12,16 +12,16 @@ function Orbit(x_, y_, r_, n, p) { this.r = r_; this.parent = p; this.child = null; - this.speed = (radians(pow(k, n-1)))/resolution; - this.angle = -PI/2; + this.speed = radians(pow(k, n - 1)) / resolution; + this.angle = -PI / 2; this.addChild = function() { var newr = this.r / 3.0; var newx = this.x + this.r + newr; var newy = this.y; - this.child = new Orbit(newx, newy, newr, n+1, this); + this.child = new Orbit(newx, newy, newr, n + 1, this); return this.child; - } + }; this.update = function() { var parent = this.parent; @@ -31,12 +31,12 @@ function Orbit(x_, y_, r_, n, p) { this.x = parent.x + rsum * cos(this.angle); this.y = parent.y + rsum * sin(this.angle); } - } + }; this.show = function() { stroke(255, 100); strokeWeight(1); noFill(); - ellipse(this.x, this.y, this.r*2, this.r*2); - } + ellipse(this.x, this.y, this.r * 2, this.r * 2); + }; } diff --git a/CodingChallenges/CC_061_fractal_spirograph/P5/sketch.js b/CodingChallenges/CC_061_fractal_spirograph/P5/sketch.js index 90054f9679..2d29ebf08c 100644 --- a/CodingChallenges/CC_061_fractal_spirograph/P5/sketch.js +++ b/CodingChallenges/CC_061_fractal_spirograph/P5/sketch.js @@ -14,7 +14,7 @@ var end; function setup() { createCanvas(600, 600); - sun = new Orbit(width/2, height/2, width/4, 0); + sun = new Orbit(width / 2, height / 2, width / 4, 0); var next = sun; for (var i = 0; i < 10; i++) { next = next.addChild(); diff --git a/CodingChallenges/CC_062_plinko/P5/boundary.js b/CodingChallenges/CC_062_plinko/P5/boundary.js index 428550e85f..78af9ff6d9 100644 --- a/CodingChallenges/CC_062_plinko/P5/boundary.js +++ b/CodingChallenges/CC_062_plinko/P5/boundary.js @@ -17,7 +17,7 @@ function Boundary(x, y, w, h) { World.add(world, this.body); } -Boundary.prototype.show = function () { +Boundary.prototype.show = function() { fill(255); stroke(255); var pos = this.body.position; @@ -26,4 +26,4 @@ Boundary.prototype.show = function () { rectMode(CENTER); rect(0, 0, this.w, this.h); pop(); -} \ No newline at end of file +}; diff --git a/CodingChallenges/CC_062_plinko/P5/particle.js b/CodingChallenges/CC_062_plinko/P5/particle.js index 74a9b984b7..b76b75b4a4 100644 --- a/CodingChallenges/CC_062_plinko/P5/particle.js +++ b/CodingChallenges/CC_062_plinko/P5/particle.js @@ -13,21 +13,21 @@ function Particle(x, y, r) { restitution: 0.5, friction: 0, density: 1 - } + }; x += random(-1, 1); this.body = Bodies.circle(x, y, r, options); - this.body.label = "particle"; + this.body.label = 'particle'; this.r = r; World.add(world, this.body); } -Particle.prototype.isOffScreen = function () { +Particle.prototype.isOffScreen = function() { var x = this.body.position.x; var y = this.body.position.y; - return (x < -50 || x > width + 50 || y > height); -} + return x < -50 || x > width + 50 || y > height; +}; -Particle.prototype.show = function () { +Particle.prototype.show = function() { fill(this.hue, 255, 255); noStroke(); var pos = this.body.position; @@ -35,4 +35,4 @@ Particle.prototype.show = function () { translate(pos.x, pos.y); ellipse(0, 0, this.r * 2); pop(); -} \ No newline at end of file +}; diff --git a/CodingChallenges/CC_062_plinko/P5/plinko.js b/CodingChallenges/CC_062_plinko/P5/plinko.js index b6d070d79e..909b5d9398 100644 --- a/CodingChallenges/CC_062_plinko/P5/plinko.js +++ b/CodingChallenges/CC_062_plinko/P5/plinko.js @@ -12,14 +12,14 @@ function Plinko(x, y, r) { restitution: 1, friction: 0, isStatic: true - } + }; this.body = Bodies.circle(x, y, r, options); - this.body.label = "plinko"; + this.body.label = 'plinko'; this.r = r; World.add(world, this.body); } -Plinko.prototype.show = function () { +Plinko.prototype.show = function() { noStroke(); fill(127); var pos = this.body.position; @@ -27,4 +27,4 @@ Plinko.prototype.show = function () { translate(pos.x, pos.y); ellipse(0, 0, this.r * 2); pop(); -} \ No newline at end of file +}; diff --git a/CodingChallenges/CC_062_plinko/P5/sketch.js b/CodingChallenges/CC_062_plinko/P5/sketch.js index 3c09ffcb7c..a4bb7da81c 100644 --- a/CodingChallenges/CC_062_plinko/P5/sketch.js +++ b/CodingChallenges/CC_062_plinko/P5/sketch.js @@ -72,10 +72,7 @@ function setup() { var y = height - h / 2; var b = new Boundary(x, y, w, h); bounds.push(b); - } - - } function newParticle() { @@ -103,4 +100,4 @@ function draw() { for (var i = 0; i < bounds.length; i++) { bounds[i].show(); } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_064.1_ForwardKinematics/P5/CC_064.1_A_ForwardKinematics/segment.js b/CodingChallenges/CC_064.1_ForwardKinematics/P5/CC_064.1_A_ForwardKinematics/segment.js index dbe2cc9baa..b46072c71a 100644 --- a/CodingChallenges/CC_064.1_ForwardKinematics/P5/CC_064.1_A_ForwardKinematics/segment.js +++ b/CodingChallenges/CC_064.1_ForwardKinematics/P5/CC_064.1_A_ForwardKinematics/segment.js @@ -1,59 +1,56 @@ class Segment { - /* Unlike in Java, JavaScript does not have implement - * function overloading, which means we cannot simply have - * two different constructors for our Segment class as Shiffman does in - * his pde example. Instead, we must have one constructor function - * which behaves differently depending on the type of arguments we pass. - */ - constructor(point, len, angle) { - if (point.hasOwnProperty("angle")) { // point is probably a Segment - this.par = point; - this.a = new p5.Vector(this.par.b.x, this.par.b.y); - } else { - this.par = false; - this.a = point; - } - this.len = len; - this.angle = angle; - this.selfAngle = angle; - this.calculateB(); - - this.xoff = random(1000); + /* Unlike in Java, JavaScript does not have implement + * function overloading, which means we cannot simply have + * two different constructors for our Segment class as Shiffman does in + * his pde example. Instead, we must have one constructor function + * which behaves differently depending on the type of arguments we pass. + */ + constructor(point, len, angle) { + if (point.hasOwnProperty('angle')) { + // point is probably a Segment + this.par = point; + this.a = new p5.Vector(this.par.b.x, this.par.b.y); + } else { + this.par = false; + this.a = point; } - - wiggle() { - let maxangle = 1; - let minangle = -1; - this.selfAngle = map(noise(this.xoff),0,1,maxangle,minangle); - this.xoff += 0.03; - - //this.selfAngle += 0.01; - } - - update() { - this.angle = this.selfAngle; - if (this.par) { - this.a = this.par.b.copy(); - this.angle += this.par.angle; - } else { - this.angle += -PI/2; - - } - this.calculateB(); - } - - calculateB() { - let dx = this.len * Math.cos(this.angle); - let dy = this.len * Math.sin(this.angle); - this.b = new p5.Vector(this.a.x+dx, this.a.y+dy); - } - - show() { - stroke(255); - strokeWeight(4); - line(this.a.x, this.a.y, this.b.x, this.b.y); + this.len = len; + this.angle = angle; + this.selfAngle = angle; + this.calculateB(); + + this.xoff = random(1000); + } + + wiggle() { + let maxangle = 1; + let minangle = -1; + this.selfAngle = map(noise(this.xoff), 0, 1, maxangle, minangle); + this.xoff += 0.03; + + //this.selfAngle += 0.01; + } + + update() { + this.angle = this.selfAngle; + if (this.par) { + this.a = this.par.b.copy(); + this.angle += this.par.angle; + } else { + this.angle += -PI / 2; } + this.calculateB(); + } + + calculateB() { + let dx = this.len * Math.cos(this.angle); + let dy = this.len * Math.sin(this.angle); + this.b = new p5.Vector(this.a.x + dx, this.a.y + dy); + } + + show() { + stroke(255); + strokeWeight(4); + line(this.a.x, this.a.y, this.b.x, this.b.y); + } } - - - diff --git a/CodingChallenges/CC_064.1_ForwardKinematics/P5/CC_064.1_A_ForwardKinematics/sketch.js b/CodingChallenges/CC_064.1_ForwardKinematics/P5/CC_064.1_A_ForwardKinematics/sketch.js index eda2e3b06c..5464abed8f 100644 --- a/CodingChallenges/CC_064.1_ForwardKinematics/P5/CC_064.1_A_ForwardKinematics/sketch.js +++ b/CodingChallenges/CC_064.1_ForwardKinematics/P5/CC_064.1_A_ForwardKinematics/sketch.js @@ -1,33 +1,33 @@ let tentacle; function setup() { - createCanvas(600, 400); + createCanvas(600, 400); - // We're building the positional p5.Vector for the first segment's - // point a because of how we're handling JavaScript's lack of - // functional overloading (see segment.js for more information) - let x = width/2; - let y = height; - let pos = new p5.Vector(x, y); + // We're building the positional p5.Vector for the first segment's + // point a because of how we're handling JavaScript's lack of + // functional overloading (see segment.js for more information) + let x = width / 2; + let y = height; + let pos = new p5.Vector(x, y); - tentacle = new Segment(pos, 10, 0); + tentacle = new Segment(pos, 10, 0); - let current = tentacle; - for (let i = 0; i < 20; i++) { - let next = new Segment(current, 10, 0); - current.child = next; - current = next; - } + let current = tentacle; + for (let i = 0; i < 20; i++) { + let next = new Segment(current, 10, 0); + current.child = next; + current = next; + } } function draw() { - background(51); + background(51); - let next = tentacle; - while (next) { - next.wiggle(); - next.update(); - next.show(); - next = next.child; - } + let next = tentacle; + while (next) { + next.wiggle(); + next.update(); + next.show(); + next = next.child; + } } diff --git a/CodingChallenges/CC_064.2_InverseKinematics/P5/segment.js b/CodingChallenges/CC_064.2_InverseKinematics/P5/segment.js index 3584298856..f1c1ec8c52 100644 --- a/CodingChallenges/CC_064.2_InverseKinematics/P5/segment.js +++ b/CodingChallenges/CC_064.2_InverseKinematics/P5/segment.js @@ -1,4 +1,3 @@ - class Segment { /* Unlike in Java, JavaScript does not implement * function overloading, which means we cannot simply have @@ -7,16 +6,14 @@ class Segment { * which behaves differently depending on the type of arguments we pass. */ constructor(point, len, i) { - if (point.hasOwnProperty("angle")) { // point is probably a Segment + if (point.hasOwnProperty('angle')) { + // point is probably a Segment this.par = point; this.a = this.par.b.copy(); - } else { - this.par = false; this.a = point; - } this.b = new p5.Vector(); @@ -26,18 +23,14 @@ class Segment { this.calculateB(); } - follow(tx, ty) { - /* Shiffman used function overloading here too, but since we can't - * in JavaScript we instead check whether or not ty is undefined. */ - if (typeof(ty) == "undefined") { - + /* Shiffman used function overloading here too, but since we can't + * in JavaScript we instead check whether or not ty is undefined. */ + if (typeof ty == 'undefined') { let targetX = this.child.a.x; let targetY = this.child.a.y; this.follow(targetX, targetY); - } else { - let target = new p5.Vector(tx, ty); let dir = p5.Vector.sub(target, this.a); this.angle = dir.heading(); @@ -45,23 +38,19 @@ class Segment { dir.setMag(this.len); dir.mult(-1); this.a = p5.Vector.add(target, dir); - } } - calculateB() { let dx = this.len * cos(this.angle); - let dy = this.len * sin(this.angle) + let dy = this.len * sin(this.angle); this.b.set(this.a.x + dx, this.a.y + dy); } - update() { this.calculateB(); } - show() { stroke(255); strokeWeight(this.sw); diff --git a/CodingChallenges/CC_064.2_InverseKinematics/P5/sketch.js b/CodingChallenges/CC_064.2_InverseKinematics/P5/sketch.js index abbc91c67d..6ea230b7c8 100644 --- a/CodingChallenges/CC_064.2_InverseKinematics/P5/sketch.js +++ b/CodingChallenges/CC_064.2_InverseKinematics/P5/sketch.js @@ -3,7 +3,6 @@ let tentacle; - function setup() { createCanvas(600, 400); @@ -21,7 +20,6 @@ function setup() { tentacle = current; } - function draw() { background(51); @@ -37,5 +35,3 @@ function draw() { next = next.par; } } - - diff --git a/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/robotarm.js b/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/robotarm.js index fe5d608364..10a61b2a33 100644 --- a/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/robotarm.js +++ b/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/robotarm.js @@ -5,51 +5,51 @@ // Transcribe to Javascript: Chuck England class RobotArm { - constructor(x, y, numSegs, segLen, angle) { - this.base = createVector(x, y); - this.segs = []; - this.segs[0] = new Segment(x, y, segLen, angle, 0); - for (let i = 1; i < numSegs; i++) { - this.addSegment(segLen, 0, i + 1); - } + constructor(x, y, numSegs, segLen, angle) { + this.base = createVector(x, y); + this.segs = []; + this.segs[0] = new Segment(x, y, segLen, angle, 0); + for (let i = 1; i < numSegs; i++) { + this.addSegment(segLen, 0, i + 1); } + } - addSegment(len, angle) { - let c = this.segs[this.segs.length - 1]; - let s = new Segment(0, 0, len, angle, this.segs.length); - c.parent = s; - this.segs.push(s); - s.follow(c.a.x, c.a.y); - return s; - } - - update() { - for (let i = 0; i < this.segs.length; i++) { - const seg = this.segs[i]; - seg.update(); - if (i === 0) { - seg.follow(mouseX, mouseY); - } else { - const previous = this.segs[i - 1]; - seg.follow(previous.a.x, previous.a.y); - } - } + addSegment(len, angle) { + let c = this.segs[this.segs.length - 1]; + let s = new Segment(0, 0, len, angle, this.segs.length); + c.parent = s; + this.segs.push(s); + s.follow(c.a.x, c.a.y); + return s; + } - const last = this.segs.length - 1; - const s = this.segs[last]; - s.a.x = this.base.x; - s.a.y = this.base.y; - s.reCalculate(); - for (let i = last - 1; i >= 0; i--) { - const seg = this.segs[i]; - const next = this.segs[i + 1]; - seg.a.x = next.b.x; - seg.a.y = next.b.y; - seg.reCalculate(); - } + update() { + for (let i = 0; i < this.segs.length; i++) { + const seg = this.segs[i]; + seg.update(); + if (i === 0) { + seg.follow(mouseX, mouseY); + } else { + const previous = this.segs[i - 1]; + seg.follow(previous.a.x, previous.a.y); + } } - show() { - this.segs.forEach(s => s.show()); + const last = this.segs.length - 1; + const s = this.segs[last]; + s.a.x = this.base.x; + s.a.y = this.base.y; + s.reCalculate(); + for (let i = last - 1; i >= 0; i--) { + const seg = this.segs[i]; + const next = this.segs[i + 1]; + seg.a.x = next.b.x; + seg.a.y = next.b.y; + seg.reCalculate(); } -} \ No newline at end of file + } + + show() { + this.segs.forEach(s => s.show()); + } +} diff --git a/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/segment.js b/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/segment.js index d1476981fb..0ae59090d1 100644 --- a/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/segment.js +++ b/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/segment.js @@ -5,55 +5,55 @@ // Transcribe to Javascript: Chuck England class Segment { - constructor(x, y, len, angle, id) { - this.a = createVector(x, y); - this.len = len; - this.angle = angle; - this.id = id; - this.parent = null; - this.reCalculate(); - } - - createParent(len, angle, id) { - let parent = new Segment(0, 0, len, angle, id); - this.parent = parent; - parent.follow(this.a.x, this.a.y); - return parent; - } - - reCalculate() { - let dx = cos(this.angle) * this.len; - let dy = sin(this.angle) * this.len; - this.b = createVector(this.a.x + dx, this.a.y + dy); - } - - follow(tx, ty) { - let target = createVector(tx, ty); - let dir = p5.Vector.sub(target, this.a); - this.angle = dir.heading(); - - dir.setMag(this.len); - dir.mult(-1); - - this.a = p5.Vector.add(target, dir); - } - - update() { - this.reCalculate(); - } - - show() { - colorMode(HSB); - let clr = color(map(this.id, 0, 39, 0, 255), 255, 255); - colorMode(RGB); - stroke(clr); - strokeWeight(4); - line(this.a.x, this.a.y, this.b.x, this.b.y); - - noStroke(); - fill(51); - strokeWeight(2); - ellipse(this.a.x, this.a.y, 2, 2); - ellipse(this.b.x, this.b.y, 2, 2); - } -} \ No newline at end of file + constructor(x, y, len, angle, id) { + this.a = createVector(x, y); + this.len = len; + this.angle = angle; + this.id = id; + this.parent = null; + this.reCalculate(); + } + + createParent(len, angle, id) { + let parent = new Segment(0, 0, len, angle, id); + this.parent = parent; + parent.follow(this.a.x, this.a.y); + return parent; + } + + reCalculate() { + let dx = cos(this.angle) * this.len; + let dy = sin(this.angle) * this.len; + this.b = createVector(this.a.x + dx, this.a.y + dy); + } + + follow(tx, ty) { + let target = createVector(tx, ty); + let dir = p5.Vector.sub(target, this.a); + this.angle = dir.heading(); + + dir.setMag(this.len); + dir.mult(-1); + + this.a = p5.Vector.add(target, dir); + } + + update() { + this.reCalculate(); + } + + show() { + colorMode(HSB); + let clr = color(map(this.id, 0, 39, 0, 255), 255, 255); + colorMode(RGB); + stroke(clr); + strokeWeight(4); + line(this.a.x, this.a.y, this.b.x, this.b.y); + + noStroke(); + fill(51); + strokeWeight(2); + ellipse(this.a.x, this.a.y, 2, 2); + ellipse(this.b.x, this.b.y, 2, 2); + } +} diff --git a/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/sketch.js b/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/sketch.js index e8ad1144d2..90de712023 100644 --- a/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/sketch.js +++ b/CodingChallenges/CC_064.3_InverseKinematics_fixed/P5/sketch.js @@ -9,14 +9,14 @@ const segLen = 15; const numSegs = 40; function setup() { - createCanvas(windowWidth, windowHeight); + createCanvas(windowWidth, windowHeight); - robotarm = new RobotArm(width / 2, height, numSegs, segLen, 0); + robotarm = new RobotArm(width / 2, height, numSegs, segLen, 0); } function draw() { - background(51); + background(51); - robotarm.update(); - robotarm.show(); -} \ No newline at end of file + robotarm.update(); + robotarm.show(); +} diff --git a/CodingChallenges/CC_064.4_InverseKinematics_array/P5/segment.js b/CodingChallenges/CC_064.4_InverseKinematics_array/P5/segment.js index f9057f4bdc..6192a109a8 100644 --- a/CodingChallenges/CC_064.4_InverseKinematics_array/P5/segment.js +++ b/CodingChallenges/CC_064.4_InverseKinematics_array/P5/segment.js @@ -5,57 +5,57 @@ // Tanscription to Javascript: Chuck England class Segment { - constructor(x, y, len, i) { - this.angle = 0; - this.b = createVector(); - if (x instanceof Segment) { - // create from vector x, with len y - this.sw = map(len, 0, 20, 1, 10); - this.a = x.b.copy(); - this.len = y; - this.calculateB(); - } else { - // create new vector - this.a = createVector(x, y); - this.sw = map(i, 0, 20, 1, 10); - this.len = len; - this.calculateB(); - } + constructor(x, y, len, i) { + this.angle = 0; + this.b = createVector(); + if (x instanceof Segment) { + // create from vector x, with len y + this.sw = map(len, 0, 20, 1, 10); + this.a = x.b.copy(); + this.len = y; + this.calculateB(); + } else { + // create new vector + this.a = createVector(x, y); + this.sw = map(i, 0, 20, 1, 10); + this.len = len; + this.calculateB(); } + } - followChild(child) { - let targetX = child.a.x; - let targetY = child.a.y; - this.follow(targetX, targetY); - } + followChild(child) { + let targetX = child.a.x; + let targetY = child.a.y; + this.follow(targetX, targetY); + } - follow(tx, ty) { - let target = createVector(tx, ty); - let dir = p5.Vector.sub(target, this.a); - this.angle = dir.heading(); - dir.setMag(this.len); - dir.mult(-1); - this.a = p5.Vector.add(target, dir); - } + follow(tx, ty) { + let target = createVector(tx, ty); + let dir = p5.Vector.sub(target, this.a); + this.angle = dir.heading(); + dir.setMag(this.len); + dir.mult(-1); + this.a = p5.Vector.add(target, dir); + } - setA(pos) { - this.a = pos.copy(); - this.calculateB(); - } + setA(pos) { + this.a = pos.copy(); + this.calculateB(); + } - calculateB() { - let dx = this.len * cos(this.angle); - let dy = this.len * sin(this.angle); - this.b.set(this.a.x + dx, this.a.y + dy); - } + calculateB() { + let dx = this.len * cos(this.angle); + let dy = this.len * sin(this.angle); + this.b.set(this.a.x + dx, this.a.y + dy); + } - update() { - this.calculateB(); - } + update() { + this.calculateB(); + } - show() { - stroke(255); - strokeWeight(4); - line(this.a.x, this.a.y, this.b.x, this.b.y); - } + show() { + stroke(255); + strokeWeight(4); + line(this.a.x, this.a.y, this.b.x, this.b.y); + } } diff --git a/CodingChallenges/CC_064.4_InverseKinematics_array/P5/sketch.js b/CodingChallenges/CC_064.4_InverseKinematics_array/P5/sketch.js index 090621fed8..0984abe346 100644 --- a/CodingChallenges/CC_064.4_InverseKinematics_array/P5/sketch.js +++ b/CodingChallenges/CC_064.4_InverseKinematics_array/P5/sketch.js @@ -11,43 +11,43 @@ let vel; let gravity; function setup() { - createCanvas(800, 600); - pos = createVector(0, 0); - vel = createVector(2, 1.3); - gravity = createVector(0, 0.1); - vel.mult(3); - - let da = TWO_PI / 2; - for (let a = 0; a < TWO_PI; a += da) { - let x = width / 2 + cos(a) * 300; - let y = height / 2 + sin(a) * 300; - tentacles.push(new Tentacle(x, y)); - } + createCanvas(800, 600); + pos = createVector(0, 0); + vel = createVector(2, 1.3); + gravity = createVector(0, 0.1); + vel.mult(3); + + let da = TWO_PI / 2; + for (let a = 0; a < TWO_PI; a += da) { + let x = width / 2 + cos(a) * 300; + let y = height / 2 + sin(a) * 300; + tentacles.push(new Tentacle(x, y)); + } } function draw() { - background(51); - noFill(); - ellipse(width / 2, height / 2, 400, 400); - for (let i = 0; i < tentacles.length; i++) { - let t = tentacles[i]; - t.update(); - t.show(); - } - - pos.add(vel); - vel.add(gravity); - noStroke(); - fill(100, 255, 0); - ellipse(pos.x, pos.y, 32, 32); - - if (pos.x > width || pos.x < 0) { - vel.x *= -1; - } - - if (pos.y > height) { - pos.y = height; - vel.y *= -1; - vel.mult(0.95); - } + background(51); + noFill(); + ellipse(width / 2, height / 2, 400, 400); + for (let i = 0; i < tentacles.length; i++) { + let t = tentacles[i]; + t.update(); + t.show(); + } + + pos.add(vel); + vel.add(gravity); + noStroke(); + fill(100, 255, 0); + ellipse(pos.x, pos.y, 32, 32); + + if (pos.x > width || pos.x < 0) { + vel.x *= -1; + } + + if (pos.y > height) { + pos.y = height; + vel.y *= -1; + vel.mult(0.95); + } } diff --git a/CodingChallenges/CC_064.4_InverseKinematics_array/P5/tentacle.js b/CodingChallenges/CC_064.4_InverseKinematics_array/P5/tentacle.js index 8feee0921e..87234d321d 100644 --- a/CodingChallenges/CC_064.4_InverseKinematics_array/P5/tentacle.js +++ b/CodingChallenges/CC_064.4_InverseKinematics_array/P5/tentacle.js @@ -5,37 +5,37 @@ // Tanscription to Javascript: Chuck England class Tentacle { - constructor(x, y) { - this.segments = []; - this.base = createVector(x, y); - this.len = 50; - this.segments[0] = new Segment(300, 200, this.len, 0); - for (let i = 1; i < 5; i++) { - this.segments[i] = new Segment(this.segments[i - 1], this.len, i); - } + constructor(x, y) { + this.segments = []; + this.base = createVector(x, y); + this.len = 50; + this.segments[0] = new Segment(300, 200, this.len, 0); + for (let i = 1; i < 5; i++) { + this.segments[i] = new Segment(this.segments[i - 1], this.len, i); } + } - update() { - let total = this.segments.length; - let end = this.segments[total - 1]; - end.follow(pos.x, pos.y); - end.update(); + update() { + let total = this.segments.length; + let end = this.segments[total - 1]; + end.follow(pos.x, pos.y); + end.update(); - for (let i = total - 2; i >= 0; i--) { - this.segments[i].followChild(this.segments[i + 1]); - this.segments[i].update(); - } + for (let i = total - 2; i >= 0; i--) { + this.segments[i].followChild(this.segments[i + 1]); + this.segments[i].update(); + } - this.segments[0].setA(this.base); + this.segments[0].setA(this.base); - for (let i = 1; i < total; i++) { - this.segments[i].setA(this.segments[i - 1].b); - } + for (let i = 1; i < total; i++) { + this.segments[i].setA(this.segments[i - 1].b); } + } - show() { - for (let i = 0; i < this.segments.length; i++) { - this.segments[i].show(); - } + show() { + for (let i = 0; i < this.segments.length; i++) { + this.segments[i].show(); } + } } diff --git a/CodingChallenges/CC_065.1_binary_tree/P5/node.js b/CodingChallenges/CC_065.1_binary_tree/P5/node.js index 93e2f5094e..2c02aecbea 100644 --- a/CodingChallenges/CC_065.1_binary_tree/P5/node.js +++ b/CodingChallenges/CC_065.1_binary_tree/P5/node.js @@ -21,7 +21,7 @@ Node.prototype.search = function(val) { return this.right.search(val); } return null; -} +}; Node.prototype.visit = function() { if (this.left != null) { @@ -31,14 +31,14 @@ Node.prototype.visit = function() { if (this.right != null) { this.right.visit(); } -} +}; Node.prototype.addNode = function(n) { if (n.value < this.value) { if (this.left == null) { this.left = n; } else { - this.left.addNode(n) + this.left.addNode(n); } } else if (n.value > this.value) { if (this.right == null) { @@ -47,4 +47,4 @@ Node.prototype.addNode = function(n) { this.right.addNode(n); } } -} +}; diff --git a/CodingChallenges/CC_065.1_binary_tree/P5/tree.js b/CodingChallenges/CC_065.1_binary_tree/P5/tree.js index ed639c45f0..cf3fc37e44 100644 --- a/CodingChallenges/CC_065.1_binary_tree/P5/tree.js +++ b/CodingChallenges/CC_065.1_binary_tree/P5/tree.js @@ -12,12 +12,12 @@ function Tree() { Tree.prototype.traverse = function() { this.root.visit(); -} +}; Tree.prototype.search = function(val) { var found = this.root.search(val); return found; -} +}; Tree.prototype.addValue = function(val) { var n = new Node(val); @@ -26,4 +26,4 @@ Tree.prototype.addValue = function(val) { } else { this.root.addNode(n); } -} +}; diff --git a/CodingChallenges/CC_065.2_binary_tree_viz/P5/node.js b/CodingChallenges/CC_065.2_binary_tree_viz/P5/node.js index 2d21ede87f..4d0a961c58 100644 --- a/CodingChallenges/CC_065.2_binary_tree_viz/P5/node.js +++ b/CodingChallenges/CC_065.2_binary_tree_viz/P5/node.js @@ -23,7 +23,7 @@ Node.prototype.search = function(val) { return this.right.search(val); } return null; -} +}; Node.prototype.visit = function(parent) { if (this.left != null) { @@ -41,7 +41,7 @@ Node.prototype.visit = function(parent) { if (this.right != null) { this.right.visit(this); } -} +}; Node.prototype.addNode = function(n) { if (n.value < this.value) { @@ -50,16 +50,15 @@ Node.prototype.addNode = function(n) { this.left.x = this.x - 50; this.left.y = this.y + 20; } else { - this.left.addNode(n) + this.left.addNode(n); } } else if (n.value > this.value) { if (this.right == null) { this.right = n; this.right.x = this.x + 50; this.right.y = this.y + 20; - } else { this.right.addNode(n); } } -} +}; diff --git a/CodingChallenges/CC_065.2_binary_tree_viz/P5/tree.js b/CodingChallenges/CC_065.2_binary_tree_viz/P5/tree.js index b2957daf23..4a6135e4b8 100644 --- a/CodingChallenges/CC_065.2_binary_tree_viz/P5/tree.js +++ b/CodingChallenges/CC_065.2_binary_tree_viz/P5/tree.js @@ -12,12 +12,12 @@ function Tree() { Tree.prototype.traverse = function() { this.root.visit(this.root); -} +}; Tree.prototype.search = function(val) { var found = this.root.search(val); return found; -} +}; Tree.prototype.addValue = function(val) { var n = new Node(val); @@ -28,4 +28,4 @@ Tree.prototype.addValue = function(val) { } else { this.root.addNode(n); } -} +}; diff --git a/CodingChallenges/CC_066_timer/P5/sketch.js b/CodingChallenges/CC_066_timer/P5/sketch.js index ab91a1259d..5339e99e67 100644 --- a/CodingChallenges/CC_066_timer/P5/sketch.js +++ b/CodingChallenges/CC_066_timer/P5/sketch.js @@ -19,14 +19,13 @@ function convertSeconds(s) { var ding; function preload() { - ding = loadSound("ding.mp3"); + ding = loadSound('ding.mp3'); } function setup() { noCanvas(); startTime = millis(); - var params = getURLParams(); console.log(params); if (params.minute) { @@ -48,5 +47,4 @@ function setup() { //counter = 0; } } - } diff --git a/CodingChallenges/CC_067_Pong/P5/paddle.js b/CodingChallenges/CC_067_Pong/P5/paddle.js index a3d1ac97b6..7b4a230d23 100644 --- a/CodingChallenges/CC_067_Pong/P5/paddle.js +++ b/CodingChallenges/CC_067_Pong/P5/paddle.js @@ -1,31 +1,29 @@ class Paddle { - constructor(isLeft) { - this.y = height/2; - this.w = 20; - this.h = 100; - this.ychange = 0; - - if (isLeft) { - this.x = this.w; - } else { - this.x = width - this.w; - } - - - } - - update() { - this.y += this.ychange; - this.y = constrain(this.y, this.h/2, height-this.h/2); - } - - move(steps) { - this.ychange = steps; - } - - show() { - fill(255); - rectMode(CENTER); - rect(this.x, this.y, this.w, this.h); + constructor(isLeft) { + this.y = height / 2; + this.w = 20; + this.h = 100; + this.ychange = 0; + + if (isLeft) { + this.x = this.w; + } else { + this.x = width - this.w; } + } + + update() { + this.y += this.ychange; + this.y = constrain(this.y, this.h / 2, height - this.h / 2); + } + + move(steps) { + this.ychange = steps; + } + + show() { + fill(255); + rectMode(CENTER); + rect(this.x, this.y, this.w, this.h); + } } diff --git a/CodingChallenges/CC_067_Pong/P5/puck.js b/CodingChallenges/CC_067_Pong/P5/puck.js index a0415aa199..3f66be6526 100644 --- a/CodingChallenges/CC_067_Pong/P5/puck.js +++ b/CodingChallenges/CC_067_Pong/P5/puck.js @@ -1,82 +1,83 @@ class Puck { - constructor() { - this.x = width/2; - this.y = height/2; - this.xspeed = 0; - this.yspeed = 0; - this.r = 12; - - this.reset(); + constructor() { + this.x = width / 2; + this.y = height / 2; + this.xspeed = 0; + this.yspeed = 0; + this.r = 12; + + this.reset(); + } + + checkPaddleLeft(p) { + if ( + this.y - this.r < p.y + p.h / 2 && + this.y + this.r > p.y - p.h / 2 && + this.x - this.r < p.x + p.w / 2 + ) { + if (this.x > p.x) { + let diff = this.y - (p.y - p.h / 2); + let rad = radians(45); + let angle = map(diff, 0, p.h, -rad, rad); + this.xspeed = 5 * cos(angle); + this.yspeed = 5 * sin(angle); + this.x = p.x + p.w / 2 + this.r; + } } - - checkPaddleLeft(p) { - if (this.y - this.r < p.y + p.h/2 && - this.y + this.r > p.y - p.h/2 && - this.x - this.r < p.x + p.w/2) { - - if (this.x > p.x) { - let diff = this.y - (p.y - p.h/2); - let rad = radians(45); - let angle = map(diff, 0, p.h, -rad, rad); - this.xspeed = 5 * cos(angle); - this.yspeed = 5 * sin(angle); - this.x = p.x + p.w/2 + this.r; - } - - } + } + checkPaddleRight(p) { + if ( + this.y - this.r < p.y + p.h / 2 && + this.y + this.r > p.y - p.h / 2 && + this.x + this.r > p.x - p.w / 2 + ) { + if (this.x < p.x) { + let diff = this.y - (p.y - p.h / 2); + let angle = map(diff, 0, p.h, radians(225), radians(135)); + this.xspeed = 5 * cos(angle); + this.yspeed = 5 * sin(angle); + this.x = p.x - p.w / 2 - this.r; + } } - checkPaddleRight(p) { - if (this.y - this.r < p.y + p.h/2 && - this.y + this.r > p.y - p.h/2 && - this.x + this.r > p.x - p.w/2) { - - if (this.x < p.x) { - let diff = this.y - (p.y - p.h/2); - let angle = map(diff, 0, p.h, radians(225), radians(135)); - this.xspeed = 5 * cos(angle); - this.yspeed = 5 * sin(angle); - this.x = p.x - p.w/2 - this.r; - } - } + } + + update() { + this.x += this.xspeed; + this.y += this.yspeed; + } + + reset() { + this.x = width / 2; + this.y = height / 2; + let angle = random(-PI / 4, PI / 4); + this.xspeed = 5 * Math.cos(angle); + this.yspeed = 5 * Math.sin(angle); + + if (random(1) < 0.5) { + this.xspeed *= -1; } - - update() { - this.x += this.xspeed; - this.y += this.yspeed; + } + + edges() { + if (this.y < 0 || this.y > height) { + this.yspeed *= -1; } - - reset() { - this.x = width/2; - this.y = height/2; - let angle = random(-PI/4, PI/4); - this.xspeed = 5 * Math.cos(angle); - this.yspeed = 5 * Math.sin(angle); - - if (random(1) < 0.5) { - this.xspeed *= -1; - } + + if (this.x - this.r > width) { + ding.play(); + leftscore++; + this.reset(); } - - edges() { - if (this.y < 0 || this.y > height) { - this.yspeed *= -1; - } - - if (this.x - this.r > width) { - ding.play(); - leftscore++; - this.reset(); - } - - if (this.x + this.r < 0) { - ding.play(); - rightscore++; - this.reset(); - } - } - - show() { - fill(255); - ellipse(this.x, this.y, this.r*2); + + if (this.x + this.r < 0) { + ding.play(); + rightscore++; + this.reset(); } + } + + show() { + fill(255); + ellipse(this.x, this.y, this.r * 2); + } } diff --git a/CodingChallenges/CC_067_Pong/P5/sketch.js b/CodingChallenges/CC_067_Pong/P5/sketch.js index 7116f39f62..09c8a7e83f 100644 --- a/CodingChallenges/CC_067_Pong/P5/sketch.js +++ b/CodingChallenges/CC_067_Pong/P5/sketch.js @@ -5,51 +5,50 @@ let leftscore = 0; let rightscore = 0; function setup() { - createCanvas(600, 400); - ding = loadSound("data/ding.mp3"); - puck = new Puck(); - left = new Paddle(true); - right = new Paddle(false); + createCanvas(600, 400); + ding = loadSound('data/ding.mp3'); + puck = new Puck(); + left = new Paddle(true); + right = new Paddle(false); } function draw() { - background(0); - - puck.checkPaddleRight(right); - puck.checkPaddleLeft(left); - - left.show(); - right.show(); - left.update(); - right.update(); - - puck.update(); - puck.edges(); - puck.show(); - - fill(255); - textSize(32); - text(leftscore, 32, 40); - text(rightscore, width-64, 40); -} + background(0); + + puck.checkPaddleRight(right); + puck.checkPaddleLeft(left); + + left.show(); + right.show(); + left.update(); + right.update(); + puck.update(); + puck.edges(); + puck.show(); + + fill(255); + textSize(32); + text(leftscore, 32, 40); + text(rightscore, width - 64, 40); +} function keyReleased() { - left.move(0); - right.move(0); + left.move(0); + right.move(0); } function keyPressed() { - console.log(key); - if (key == 'A') { - left.move(-10); - } else if (key == 'Z') { - left.move(10); - } - - if (key == 'J') { - right.move(-10); - } else if (key == 'M') { - right.move(10); - } + console.log(key); + if (key == 'A') { + left.move(-10); + } else if (key == 'Z') { + left.move(10); + } + + if (key == 'J') { + right.move(-10); + } else if (key == 'M') { + right.move(10); + } } diff --git a/CodingChallenges/CC_068_BFS_kevin_bacon/P5/graph.js b/CodingChallenges/CC_068_BFS_kevin_bacon/P5/graph.js index eb82aefba0..c103c5eff9 100644 --- a/CodingChallenges/CC_068_BFS_kevin_bacon/P5/graph.js +++ b/CodingChallenges/CC_068_BFS_kevin_bacon/P5/graph.js @@ -19,18 +19,17 @@ Graph.prototype.reset = function() { this.nodes[i].searched = false; this.nodes[i].parent = null; } -} +}; Graph.prototype.setStart = function(actor) { this.start = this.graph[actor]; return this.start; -} +}; Graph.prototype.setEnd = function(actor) { this.end = this.graph[actor]; return this.end; -} - +}; Graph.prototype.addNode = function(n) { // Node into array @@ -38,9 +37,9 @@ Graph.prototype.addNode = function(n) { var title = n.value; // Node into "hash" this.graph[title] = n; -} +}; Graph.prototype.getNode = function(actor) { var n = this.graph[actor]; return n; -} +}; diff --git a/CodingChallenges/CC_068_BFS_kevin_bacon/P5/node.js b/CodingChallenges/CC_068_BFS_kevin_bacon/P5/node.js index 67c9c121af..2f4e9dfd06 100644 --- a/CodingChallenges/CC_068_BFS_kevin_bacon/P5/node.js +++ b/CodingChallenges/CC_068_BFS_kevin_bacon/P5/node.js @@ -18,4 +18,4 @@ Node.prototype.addEdge = function(neighbor) { this.edges.push(neighbor); // Both directions! neighbor.edges.push(this); -} +}; diff --git a/CodingChallenges/CC_068_BFS_kevin_bacon/P5/sketch.js b/CodingChallenges/CC_068_BFS_kevin_bacon/P5/sketch.js index f6d74bd01a..a299ad4603 100644 --- a/CodingChallenges/CC_068_BFS_kevin_bacon/P5/sketch.js +++ b/CodingChallenges/CC_068_BFS_kevin_bacon/P5/sketch.js @@ -47,20 +47,19 @@ function bfs() { graph.reset(); var start = graph.setStart(dropdown.value()); // var start = graph.setStart("Kevin Bacon"); - var end = graph.setEnd("Kevin Bacon"); + var end = graph.setEnd('Kevin Bacon'); console.log(graph); var queue = []; - start.searched = true; queue.push(start); while (queue.length > 0) { var current = queue.shift(); if (current == end) { - console.log("Found " + current.value); + console.log('Found ' + current.value); break; } var edges = current.edges; @@ -85,9 +84,9 @@ function bfs() { var txt = ''; for (var i = path.length - 1; i >= 0; i--) { var n = path[i]; - txt += n.value + txt += n.value; if (i != 0) { - txt += ' --> ' + txt += ' --> '; } } createP(txt); diff --git a/CodingChallenges/CC_069_steering_evolution/P5/sketch.js b/CodingChallenges/CC_069_steering_evolution/P5/sketch.js index 7c72033ac6..5b94bce031 100644 --- a/CodingChallenges/CC_069_steering_evolution/P5/sketch.js +++ b/CodingChallenges/CC_069_steering_evolution/P5/sketch.js @@ -9,7 +9,6 @@ // https://editor.p5js.org/codingtrain/sketches/xgQNXkxx1 - var vehicles = []; var food = []; var poison = []; @@ -37,10 +36,6 @@ function setup() { } debug = createCheckbox(); - - - - } function mouseDragged() { @@ -62,7 +57,6 @@ function draw() { poison.push(createVector(x, y)); } - for (var i = 0; i < food.length; i++) { fill(0, 255, 0); noStroke(); @@ -92,6 +86,5 @@ function draw() { food.push(createVector(x, y)); vehicles.splice(i, 1); } - } } diff --git a/CodingChallenges/CC_069_steering_evolution/P5/vehicle.js b/CodingChallenges/CC_069_steering_evolution/P5/vehicle.js index 009f8f4950..365054c1d3 100644 --- a/CodingChallenges/CC_069_steering_evolution/P5/vehicle.js +++ b/CodingChallenges/CC_069_steering_evolution/P5/vehicle.js @@ -53,7 +53,6 @@ function Vehicle(x, y, dna) { // Method to update location this.update = function() { - this.health -= 0.005; // Update velocity @@ -63,12 +62,12 @@ function Vehicle(x, y, dna) { this.position.add(this.velocity); // Reset accelerationelertion to 0 each cycle this.acceleration.mult(0); - } + }; this.applyForce = function(force) { // We could add mass here if we want A = F / M this.acceleration.add(force); - } + }; this.behaviors = function(good, bad) { var steerG = this.eat(good, 0.2, this.dna[2]); @@ -79,7 +78,7 @@ function Vehicle(x, y, dna) { this.applyForce(steerG); this.applyForce(steerB); - } + }; this.clone = function() { if (random(1) < 0.002) { @@ -87,7 +86,7 @@ function Vehicle(x, y, dna) { } else { return null; } - } + }; this.eat = function(list, nutrition, perception) { var record = Infinity; @@ -113,12 +112,11 @@ function Vehicle(x, y, dna) { } return createVector(0, 0); - } + }; // A method that calculates a steering force towards a target // STEER = DESIRED MINUS VELOCITY this.seek = function(target) { - var desired = p5.Vector.sub(target, this.position); // A vector pointing from the location to the target // Scale to maximum speed @@ -130,11 +128,11 @@ function Vehicle(x, y, dna) { return steer; //this.applyForce(steer); - } + }; this.dead = function() { - return (this.health < 0) - } + return this.health < 0; + }; this.display = function() { // Draw a triangle rotated in the direction of velocity @@ -144,7 +142,6 @@ function Vehicle(x, y, dna) { translate(this.position.x, this.position.y); rotate(angle); - if (debug.checked()) { strokeWeight(3); stroke(0, 255, 0); @@ -171,8 +168,7 @@ function Vehicle(x, y, dna) { endShape(CLOSE); pop(); - } - + }; this.boundaries = function() { var d = 25; @@ -198,5 +194,5 @@ function Vehicle(x, y, dna) { steer.limit(this.maxforce); this.applyForce(steer); } - } + }; } diff --git a/CodingChallenges/CC_070.1_similarity_score/P5/sketch.js b/CodingChallenges/CC_070.1_similarity_score/P5/sketch.js index f01ed426f3..b3a0310e9f 100644 --- a/CodingChallenges/CC_070.1_similarity_score/P5/sketch.js +++ b/CodingChallenges/CC_070.1_similarity_score/P5/sketch.js @@ -35,7 +35,6 @@ function setup() { resultP = createP(''); - function euclideanSimilarity() { var name1 = dropdown1.value(); var name2 = dropdown2.value(); @@ -49,7 +48,6 @@ function setup() { var j = titles.indexOf('timestamp'); titles.splice(j, 1); - var sumSquares = 0; for (var i = 0; i < titles.length; i++) { var title = titles[i]; @@ -65,6 +63,4 @@ function setup() { var similarity = 1 / (1 + d); resultP.html(similarity); } - - } diff --git a/CodingChallenges/CC_070.2_nearest_neighbors/P5/sketch.js b/CodingChallenges/CC_070.2_nearest_neighbors/P5/sketch.js index 6d9dbb6d21..515b63eaa2 100644 --- a/CodingChallenges/CC_070.2_nearest_neighbors/P5/sketch.js +++ b/CodingChallenges/CC_070.2_nearest_neighbors/P5/sketch.js @@ -71,14 +71,8 @@ function setup() { resultP.parent(div); } - // console.log(similarityScores); - } - - - - } function euclideanDistance(name1, name2) { @@ -91,7 +85,6 @@ function euclideanDistance(name1, name2) { var j = titles.indexOf('timestamp'); titles.splice(j, 1); - var sumSquares = 0; for (var i = 0; i < titles.length; i++) { var title = titles[i]; diff --git a/CodingChallenges/CC_070.3_movie_recommender/P5/sketch.js b/CodingChallenges/CC_070.3_movie_recommender/P5/sketch.js index 54b13dedfd..8b148b5cc0 100644 --- a/CodingChallenges/CC_070.3_movie_recommender/P5/sketch.js +++ b/CodingChallenges/CC_070.3_movie_recommender/P5/sketch.js @@ -39,7 +39,6 @@ function setup() { } } - var button = createButton('submit'); button.mousePressed(predictRatings); resultP = createP(''); @@ -58,9 +57,6 @@ function setup() { findNearestNeighbors(newUser); } - - - function findNearestNeighbors(user) { for (var i = 0; i < resultDivs.length; i++) { resultDivs[i].remove(); @@ -82,11 +78,9 @@ function setup() { return score2 - score1; } - for (var i = 0; i < data.titles.length; i++) { var title = data.titles[i]; if (user[title] == null) { - var k = 5; var weightedSum = 0; var similaritySum = 0; @@ -105,16 +99,9 @@ function setup() { var div = createDiv(title + ': ' + stars); resultDivs.push(div); div.parent(resultP); - - - - - } } - - // var k = 5; // for (var i = 0; i < k; i++) { // var name = data.users[i].name; @@ -124,18 +111,11 @@ function setup() { // div.parent(resultP); // } - // console.log(similarityScores); - } - - - - } function euclideanDistance(ratings1, ratings2) { - var titles = data.titles; var sumSquares = 0; diff --git a/CodingChallenges/CC_071_minesweeper/P5/cell.js b/CodingChallenges/CC_071_minesweeper/P5/cell.js index 93a7349acd..37f2e6ffa3 100644 --- a/CodingChallenges/CC_071_minesweeper/P5/cell.js +++ b/CodingChallenges/CC_071_minesweeper/P5/cell.js @@ -35,7 +35,7 @@ Cell.prototype.show = function() { } } } -} +}; Cell.prototype.countBees = function() { if (this.bee) { @@ -58,11 +58,11 @@ Cell.prototype.countBees = function() { } } this.neighborCount = total; -} +}; Cell.prototype.contains = function(x, y) { - return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.w); -} + return x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.w; +}; Cell.prototype.reveal = function() { this.revealed = true; @@ -70,7 +70,7 @@ Cell.prototype.reveal = function() { // flood fill time this.floodFill(); } -} +}; Cell.prototype.floodFill = function() { for (var xoff = -1; xoff <= 1; xoff++) { @@ -89,4 +89,4 @@ Cell.prototype.floodFill = function() { } } } -} +}; diff --git a/CodingChallenges/CC_071_minesweeper/P5/sketch.js b/CodingChallenges/CC_071_minesweeper/P5/sketch.js index 690719559d..0fb3e8d7f8 100644 --- a/CodingChallenges/CC_071_minesweeper/P5/sketch.js +++ b/CodingChallenges/CC_071_minesweeper/P5/sketch.js @@ -39,7 +39,6 @@ function setup() { } } - for (var n = 0; n < totalBees; n++) { var index = floor(random(options.length)); var choice = options[index]; @@ -50,13 +49,11 @@ function setup() { grid[i][j].bee = true; } - for (var i = 0; i < cols; i++) { for (var j = 0; j < rows; j++) { grid[i][j].countBees(); } } - } function gameOver() { @@ -76,7 +73,6 @@ function mousePressed() { if (grid[i][j].bee) { gameOver(); } - } } } diff --git a/CodingChallenges/CC_072_Frogger/P5/car.js b/CodingChallenges/CC_072_Frogger/P5/car.js index 8c8908dfc3..0f18cdb0a6 100644 --- a/CodingChallenges/CC_072_Frogger/P5/car.js +++ b/CodingChallenges/CC_072_Frogger/P5/car.js @@ -1,23 +1,21 @@ class Car extends Rectangle { + constructor(x, y, width, height, speed) { + super(x, y, width, height); + this.speed = speed; + } - constructor(x, y, width, height, speed) { - super(x, y, width, height); - this.speed = speed; - } - - show(){ - fill(255); - rect(this.x, this.y, this.width, this.height); - } + show() { + fill(255); + rect(this.x, this.y, this.width, this.height); + } - update(){ - this.x += this.speed; + update() { + this.x += this.speed; - if(this.speed > 0 && this.x > width+grid){ - this.x = - this.width - grid; - } else if(this.speed < 0 && this.x < -this.width-grid){ - this.x = width + grid; - } + if (this.speed > 0 && this.x > width + grid) { + this.x = -this.width - grid; + } else if (this.speed < 0 && this.x < -this.width - grid) { + this.x = width + grid; } - + } } diff --git a/CodingChallenges/CC_072_Frogger/P5/frog.js b/CodingChallenges/CC_072_Frogger/P5/frog.js index 992d888882..f36762cbe3 100644 --- a/CodingChallenges/CC_072_Frogger/P5/frog.js +++ b/CodingChallenges/CC_072_Frogger/P5/frog.js @@ -1,31 +1,28 @@ -class Frog extends Rectangle{ - - constructor(x, y, width){ - super(x, y, width, width); - this.attached = null; - } - - attach(log){ - this.attached = log; +class Frog extends Rectangle { + constructor(x, y, width) { + super(x, y, width, width); + this.attached = null; + } + + attach(log) { + this.attached = log; + } + + update() { + if (this.attached != null) { + this.x += this.attached.speed; } + this.x = constrain(this.x, 0, width - this.width); + } - update(){ - if(this.attached != null) { - this.x += this.attached.speed; - } - - this.x = constrain(this.x, 0, width-this.width); - } + show() { + fill(0, 255, 0, 200); + rect(this.x, this.y, this.width, this.width); + } - show(){ - fill(0, 255, 0, 200); - rect(this.x, this.y, this.width, this.width); - - } - - move(xdir, ydir){ - this.x += xdir * grid; - this.y += ydir * grid; - } + move(xdir, ydir) { + this.x += xdir * grid; + this.y += ydir * grid; + } } diff --git a/CodingChallenges/CC_072_Frogger/P5/log.js b/CodingChallenges/CC_072_Frogger/P5/log.js index 65ee4aeb9b..bb01c6f6e3 100644 --- a/CodingChallenges/CC_072_Frogger/P5/log.js +++ b/CodingChallenges/CC_072_Frogger/P5/log.js @@ -1,7 +1,5 @@ class Log extends Car { - - constructor(x, y, width, height, speed) { - super(x, y, width, height, speed); - } - + constructor(x, y, width, height, speed) { + super(x, y, width, height, speed); + } } diff --git a/CodingChallenges/CC_072_Frogger/P5/rectangle.js b/CodingChallenges/CC_072_Frogger/P5/rectangle.js index f12012516a..86213de2ec 100644 --- a/CodingChallenges/CC_072_Frogger/P5/rectangle.js +++ b/CodingChallenges/CC_072_Frogger/P5/rectangle.js @@ -1,26 +1,27 @@ class Rectangle { + constructor(x, y, width, height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } - constructor(x, y, width, height){ - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } + intersects(otherRectangle) { + let left = this.x; + let right = this.x + this.width; + let top = this.y; + let bottom = this.y + this.height; - intersects(otherRectangle){ - let left = this.x - let right = this.x + this.width; - let top = this.y; - let bottom = this.y + this.height; + let oleft = otherRectangle.x; + let oright = otherRectangle.x + otherRectangle.width; + let otop = otherRectangle.y; + let obottom = otherRectangle.y + otherRectangle.height; - let oleft = otherRectangle.x - let oright = otherRectangle.x + otherRectangle.width; - let otop = otherRectangle.y; - let obottom = otherRectangle.y + otherRectangle.height; - - return !(left >= oright || - right <= oleft || - top >= obottom || - bottom <= otop ); - } + return !( + left >= oright || + right <= oleft || + top >= obottom || + bottom <= otop + ); + } } diff --git a/CodingChallenges/CC_072_Frogger/P5/sketch.js b/CodingChallenges/CC_072_Frogger/P5/sketch.js index c000dd96e7..3bc953bf40 100644 --- a/CodingChallenges/CC_072_Frogger/P5/sketch.js +++ b/CodingChallenges/CC_072_Frogger/P5/sketch.js @@ -3,114 +3,111 @@ let cars = []; let logs = []; let grid = 50; -function resetGame(){ - frog = new Frog(width / 2 - grid / 2, height - grid, grid); - frog.attach(null); +function resetGame() { + frog = new Frog(width / 2 - grid / 2, height - grid, grid); + frog.attach(null); } -function setup(){ - createCanvas(500,500); - resetGame(); +function setup() { + createCanvas(500, 500); + resetGame(); - let index = 0; + let index = 0; - // ROW 1 - for (let i = 0; i < 2; i++) { - let x = i * 300; - cars[index] = new Car(x, height - grid * 2, grid * 2, grid, 2); - index ++; - } + // ROW 1 + for (let i = 0; i < 2; i++) { + let x = i * 300; + cars[index] = new Car(x, height - grid * 2, grid * 2, grid, 2); + index++; + } - // ROW 2 - for (i = 0; i < 2; i++) { - let x = i * 200 + 150; - cars[index] = new Car(x, height - grid * 3, grid, grid, -3.5); - index ++; - } + // ROW 2 + for (i = 0; i < 2; i++) { + let x = i * 200 + 150; + cars[index] = new Car(x, height - grid * 3, grid, grid, -3.5); + index++; + } - // ROW 3 - for (i = 0; i < 4; i++) { - let x = i * 150 + 25; - cars[index] = new Car(x, height - grid * 4, grid, grid, 1.2); - index ++; - } + // ROW 3 + for (i = 0; i < 4; i++) { + let x = i * 150 + 25; + cars[index] = new Car(x, height - grid * 4, grid, grid, 1.2); + index++; + } - // ROW 5 - index = 0; - for (i = 0; i < 2; i++) { - let x = i * 250 + 100; - logs[index] = new Log(x, height - grid * 6, grid * 3, grid, 2.3); - index ++; - } + // ROW 5 + index = 0; + for (i = 0; i < 2; i++) { + let x = i * 250 + 100; + logs[index] = new Log(x, height - grid * 6, grid * 3, grid, 2.3); + index++; + } - // ROW 6 - for (i = 0; i < 3; i++) { - let x = i * 200 + 30; - logs[index] = new Log(x, height - grid * 7, grid * 2, grid, -1.3); - index ++; - } + // ROW 6 + for (i = 0; i < 3; i++) { + let x = i * 200 + 30; + logs[index] = new Log(x, height - grid * 7, grid * 2, grid, -1.3); + index++; + } - // ROW 7 - for (i = 0; i < 2; i++) { - let x = i * 400 + 10; - logs[index] = new Log(x, height - grid * 8, grid * 4, grid, 0.5); - index ++; - } + // ROW 7 + for (i = 0; i < 2; i++) { + let x = i * 400 + 10; + logs[index] = new Log(x, height - grid * 8, grid * 4, grid, 0.5); + index++; + } } -function draw(){ - - background(0); - // Safety lines - fill(255, 100); - rect(0, 0, width,grid*2); - rect(0, height-grid,width,grid); - rect(0, height-grid*5,width,grid); - - - for(let i = 0; i < cars.length; i++){ - cars[i].update(); - cars[i].show(); - - if(frog.intersects(cars[i])){ - resetGame(); - } +function draw() { + background(0); + // Safety lines + fill(255, 100); + rect(0, 0, width, grid * 2); + rect(0, height - grid, width, grid); + rect(0, height - grid * 5, width, grid); + + for (let i = 0; i < cars.length; i++) { + cars[i].update(); + cars[i].show(); + + if (frog.intersects(cars[i])) { + resetGame(); } - - for(i = 0; i < logs.length; i++){ - logs[i].update(); - logs[i].show(); + } + + for (i = 0; i < logs.length; i++) { + logs[i].update(); + logs[i].show(); + } + + if (frog.y < height - grid * 5 && frog.y > grid * 2) { + let ok = false; + + for (i = 0; i < logs.length; i++) { + if (frog.intersects(logs[i])) { + ok = true; + frog.attach(logs[i]); + } } - - if (frog.y < height - grid * 5 && frog.y > grid*2) { - let ok = false; - - for(i = 0; i 0) { let message = { diff --git a/CodingChallenges/CC_084_Word_Definition_Extension/JavaScript/sketch/sketch.js b/CodingChallenges/CC_084_Word_Definition_Extension/JavaScript/sketch/sketch.js index c7b74fd66d..d28526fed1 100644 --- a/CodingChallenges/CC_084_Word_Definition_Extension/JavaScript/sketch/sketch.js +++ b/CodingChallenges/CC_084_Word_Definition_Extension/JavaScript/sketch/sketch.js @@ -15,7 +15,7 @@ function setup() { &useCanonical=false &includeTags=false &api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5 - ` + `; url = url.replace(/\s+/g, ''); loadJSON(url, gotData); @@ -23,6 +23,5 @@ function setup() { createP(data[0].text).style('font-size', '48pt'); } - //createP(word); } diff --git a/CodingChallenges/CC_085_The_Game_of_Life/P5/sketch.js b/CodingChallenges/CC_085_The_Game_of_Life/P5/sketch.js index 83b0d7bee0..a4f491c969 100644 --- a/CodingChallenges/CC_085_The_Game_of_Life/P5/sketch.js +++ b/CodingChallenges/CC_085_The_Game_of_Life/P5/sketch.js @@ -63,17 +63,12 @@ function draw() { } else { next[i][j] = state; } - } } grid = next; - - - } - function countNeighbors(grid, x, y) { let sum = 0; for (let i = -1; i < 2; i++) { diff --git a/CodingChallenges/CC_087_3D_Knots/P5/sketch.js b/CodingChallenges/CC_087_3D_Knots/P5/sketch.js index 1243c12ca6..f822eb2930 100644 --- a/CodingChallenges/CC_087_3D_Knots/P5/sketch.js +++ b/CodingChallenges/CC_087_3D_Knots/P5/sketch.js @@ -20,33 +20,33 @@ let vectors = []; let beta = 0; function setup() { - createCanvas(600, 400, WEBGL); + createCanvas(600, 400, WEBGL); } function draw() { - background(0); - rotateY(angle); - angle += 0.03; - - let r = 100 * (0.8 + 1.6 * sin(6 * beta)); - let theta = 2 * beta; - let phi = 0.6 * PI * sin(12 * beta); - let x = r * cos(phi) * cos(theta); - let y = r * cos(phi) * sin(theta); - let z = r * sin(phi); - stroke(255, r, 255); - - vectors.push(createVector(x, y, z)); - - beta += 0.01; - - noFill(); - stroke(255); - strokeWeight(8); - beginShape(); - for (let i = 0; i < vectors.length; i++) { - let v = vectors[i]; - vertex(v.x, v.y, v.z); - } - endShape(); + background(0); + rotateY(angle); + angle += 0.03; + + let r = 100 * (0.8 + 1.6 * sin(6 * beta)); + let theta = 2 * beta; + let phi = 0.6 * PI * sin(12 * beta); + let x = r * cos(phi) * cos(theta); + let y = r * cos(phi) * sin(theta); + let z = r * sin(phi); + stroke(255, r, 255); + + vectors.push(createVector(x, y, z)); + + beta += 0.01; + + noFill(); + stroke(255); + strokeWeight(8); + beginShape(); + for (let i = 0; i < vectors.length; i++) { + let v = vectors[i]; + vertex(v.x, v.y, v.z); + } + endShape(); } diff --git a/CodingChallenges/CC_088_snowfall/P5/sketch.js b/CodingChallenges/CC_088_snowfall/P5/sketch.js index e9acde385d..8612834e2f 100644 --- a/CodingChallenges/CC_088_snowfall/P5/sketch.js +++ b/CodingChallenges/CC_088_snowfall/P5/sketch.js @@ -10,7 +10,6 @@ let gravity; let zOff = 0; - let spritesheet; let textures = []; @@ -18,7 +17,6 @@ function preload() { spritesheet = loadImage('flakes32.png'); } - function setup() { createCanvas(windowWidth, windowHeight); gravity = createVector(0, 0.3); @@ -30,18 +28,12 @@ function setup() { } } - for (let i = 0; i < 400; i++) { let x = random(width); let y = random(height); let design = random(textures); snow.push(new Snowflake(x, y, design)); } - - - - - } function draw() { @@ -68,5 +60,4 @@ function draw() { // snow.splice(i, 1); // } // } - } diff --git a/CodingChallenges/CC_088_snowfall/P5/snowflake.js b/CodingChallenges/CC_088_snowfall/P5/snowflake.js index c43d8d1927..850a94eb28 100644 --- a/CodingChallenges/CC_088_snowfall/P5/snowflake.js +++ b/CodingChallenges/CC_088_snowfall/P5/snowflake.js @@ -6,11 +6,9 @@ // Edited Video: https://youtu.be/cl-mHFCGzYk function getRandomSize() { - let r = pow(random(0, 1), 3); return constrain(r * 32, 2, 32); - // let r = randomGaussian() * 2.5; // return constrain(abs(r * r), 2, 36); // while (true) { @@ -22,9 +20,7 @@ function getRandomSize() { // } } - class Snowflake { - constructor(sx, sy, img) { let x = sx || random(width); let y = sy || random(-100, -10); @@ -33,13 +29,11 @@ class Snowflake { this.vel = createVector(0, 0); this.acc = createVector(); this.angle = random(TWO_PI); - this.dir = (random(1) > 0.5) ? 1 : -1; + this.dir = random(1) > 0.5 ? 1 : -1; this.xOff = 0; this.r = getRandomSize(); } - - applyForce(force) { // Parallax Effect hack let f = force.copy(); @@ -60,7 +54,6 @@ class Snowflake { } update() { - this.xOff = sin(this.angle * 2) * 2 * this.r; this.vel.add(this.acc); @@ -85,8 +78,7 @@ class Snowflake { this.pos.x = -this.r; } - this.angle += this.dir * this.vel.mag() / 200; - + this.angle += (this.dir * this.vel.mag()) / 200; } render() { @@ -99,14 +91,9 @@ class Snowflake { imageMode(CENTER); image(this.img, 0, 0, this.r, this.r); pop(); - - } // offScreen() { // return (this.pos.y > height + this.r); // } - - - } diff --git a/CodingChallenges/CC_089_langtonsant/P5/sketch.js b/CodingChallenges/CC_089_langtonsant/P5/sketch.js index fc0a892963..cd2a4bdc39 100644 --- a/CodingChallenges/CC_089_langtonsant/P5/sketch.js +++ b/CodingChallenges/CC_089_langtonsant/P5/sketch.js @@ -10,9 +10,9 @@ let ANTLEFT = 3; function setup() { createCanvas(400, 400); - grid = make2DArray(width,height); - x = width/2; - y = height/2; + grid = make2DArray(width, height); + x = width / 2; + y = height / 2; dir = ANTUP; } @@ -41,19 +41,18 @@ function moveForward() { x--; } - if (x > width-1) { + if (x > width - 1) { x = 0; } else if (x < 0) { - x = width-1; + x = width - 1; } - if (y > height-1) { + if (y > height - 1) { y = 0; } else if (y < 0) { - y = height-1; + y = height - 1; } } - function draw() { strokeWeight(1); for (let n = 0; n < 100; n++) { diff --git a/CodingChallenges/CC_090_dithering/P5/sketch.js b/CodingChallenges/CC_090_dithering/P5/sketch.js index 1b4d9fea6e..2d77b934d6 100644 --- a/CodingChallenges/CC_090_dithering/P5/sketch.js +++ b/CodingChallenges/CC_090_dithering/P5/sketch.js @@ -1,7 +1,7 @@ let kitten; function preload() { - kitten = loadImage("data/kitten.jpg"); + kitten = loadImage('data/kitten.jpg'); } function setup() { @@ -42,7 +42,7 @@ function setColorAtIndex(img, x, y, clr) { // The step 0 is always included, so the number of steps // is actually steps + 1 function closestStep(max, steps, value) { - return round(steps * value / 255) * floor(255 / steps); + return round((steps * value) / 255) * floor(255 / steps); } function makeDithered(img, steps) { diff --git a/CodingChallenges/CC_091_snakesladders/P5/player.js b/CodingChallenges/CC_091_snakesladders/P5/player.js index 01d37cfb16..6c1e6e7a71 100644 --- a/CodingChallenges/CC_091_snakesladders/P5/player.js +++ b/CodingChallenges/CC_091_snakesladders/P5/player.js @@ -3,7 +3,6 @@ // A player class Player { - // Call a reset function to initialize constructor() { this.reset(); @@ -14,19 +13,19 @@ class Player { this.spot = -1; // Where I am now this.next = -1; // Where I'm going this.roll = -1; // What was my latest roll - } - + } + // random die roll 1 - 6 rollDie() { this.roll = floor(random(1, 7)); this.next = this.spot + this.roll; } - + // Update spot to next move() { this.spot = this.next; } - + // Highlight the tiles ahead showPreview() { let start = max(0, this.spot); @@ -34,22 +33,20 @@ class Player { for (let i = start; i <= end; i++) { tiles[i].highlight(); } - } - + // Is player on a Snake or Ladder? isSnadder() { let tile = tiles[this.spot]; - return (tile && tile.snadder !== 0); + return tile && tile.snadder !== 0; } - + // Move according to the Snake or Ladder moveSnadder() { let tile = tiles[this.spot]; this.spot += tile.snadder; } - // Display on the current tile show() { let current = tiles[this.spot]; diff --git a/CodingChallenges/CC_091_snakesladders/P5/sketch.js b/CodingChallenges/CC_091_snakesladders/P5/sketch.js index 2eb17c86dd..3d8de9ea46 100644 --- a/CodingChallenges/CC_091_snakesladders/P5/sketch.js +++ b/CodingChallenges/CC_091_snakesladders/P5/sketch.js @@ -37,7 +37,7 @@ function setup() { for (let i = 0; i < cols * rows; i++) { let tile = new Tile(x, y, resolution, i, i + 1); tiles.push(tile); - x = x + (resolution * dir); + x = x + resolution * dir; // Move along a winding path up the rows if (x >= width || x <= -resolution) { dir *= -1; @@ -56,7 +56,9 @@ function setup() { // Pick random Ladders for (let i = 0; i < 3; i++) { let index = floor(random(0, tiles.length - cols)); - tiles[index].snadder = floor(random(cols - (index % cols), tiles.length - index - 1)); + tiles[index].snadder = floor( + random(cols - (index % cols), tiles.length - index - 1) + ); } // A new player @@ -115,4 +117,4 @@ function draw() { if (avg) { avgP.html(avg); } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_091_snakesladders/P5/tile.js b/CodingChallenges/CC_091_snakesladders/P5/tile.js index 7b16c25f5f..3fb57a3c3b 100644 --- a/CodingChallenges/CC_091_snakesladders/P5/tile.js +++ b/CodingChallenges/CC_091_snakesladders/P5/tile.js @@ -3,7 +3,6 @@ // Each tile on the board class Tile { - constructor(x, y, wh, index, next) { this.x = x; this.y = y; @@ -20,29 +19,29 @@ class Tile { this.color = 100; } } - + // Find center getCenter() { let cx = this.x + this.wh / 2; let cy = this.y + this.wh / 2; // TODO: change to p5.Vector? return [cx, cy]; - } - + } + // Draw rectangle show() { fill(this.color); noStroke(); rect(this.x, this.y, this.wh, this.wh); } - + // Highlight over rectangle highlight() { fill(0, 0, 255, 100); noStroke(); rect(this.x, this.y, this.wh, this.wh); } - + // If it's connected to another tile // with a snake or a ladder showSnadders() { diff --git a/CodingChallenges/CC_092_xor/P5/libraries/matrix.js b/CodingChallenges/CC_092_xor/P5/libraries/matrix.js index 0ea3aa8919..e1c8a6a706 100644 --- a/CodingChallenges/CC_092_xor/P5/libraries/matrix.js +++ b/CodingChallenges/CC_092_xor/P5/libraries/matrix.js @@ -4,7 +4,9 @@ class Matrix { constructor(rows, cols) { this.rows = rows; this.cols = cols; - this.data = Array(this.rows).fill().map(() => Array(this.cols).fill(0)); + this.data = Array(this.rows) + .fill() + .map(() => Array(this.cols).fill(0)); } static fromArray(arr) { @@ -18,8 +20,9 @@ class Matrix { } // Return a new Matrix a-b - return new Matrix(a.rows, a.cols) - .map((_, i, j) => a.data[i][j] - b.data[i][j]); + return new Matrix(a.rows, a.cols).map( + (_, i, j) => a.data[i][j] - b.data[i][j] + ); } toArray() { @@ -49,26 +52,26 @@ class Matrix { } static transpose(matrix) { - return new Matrix(matrix.cols, matrix.rows) - .map((_, i, j) => matrix.data[j][i]); + return new Matrix(matrix.cols, matrix.rows).map( + (_, i, j) => matrix.data[j][i] + ); } static multiply(a, b) { // Matrix product if (a.cols !== b.rows) { - console.log('Columns of A must match rows of B.') + console.log('Columns of A must match rows of B.'); return; } - return new Matrix(a.rows, b.cols) - .map((e, i, j) => { - // Dot product of values in col - let sum = 0; - for (let k = 0; k < a.cols; k++) { - sum += a.data[i][k] * b.data[k][j]; - } - return sum; - }); + return new Matrix(a.rows, b.cols).map((e, i, j) => { + // Dot product of values in col + let sum = 0; + for (let k = 0; k < a.cols; k++) { + sum += a.data[i][k] * b.data[k][j]; + } + return sum; + }); } multiply(n) { @@ -99,8 +102,9 @@ class Matrix { static map(matrix, func) { // Apply a function to every element of matrix - return new Matrix(matrix.rows, matrix.cols) - .map((e, i, j) => func(matrix.data[i][j], i, j)); + return new Matrix(matrix.rows, matrix.cols).map((e, i, j) => + func(matrix.data[i][j], i, j) + ); } print() { @@ -124,4 +128,4 @@ class Matrix { if (typeof module !== 'undefined') { module.exports = Matrix; -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_092_xor/P5/libraries/nn.js b/CodingChallenges/CC_092_xor/P5/libraries/nn.js index a6a403aeb8..498d5dedb2 100644 --- a/CodingChallenges/CC_092_xor/P5/libraries/nn.js +++ b/CodingChallenges/CC_092_xor/P5/libraries/nn.js @@ -14,10 +14,9 @@ let sigmoid = new ActivationFunction( let tanh = new ActivationFunction( x => Math.tanh(x), - y => 1 - (y * y) + y => 1 - y * y ); - class NeuralNetwork { constructor(input_nodes, hidden_nodes, output_nodes) { this.input_nodes = input_nodes; @@ -36,11 +35,9 @@ class NeuralNetwork { this.setLearningRate(); this.setActivationFunction(); - } predict(input_array) { - // Generating the Hidden Outputs let inputs = Matrix.fromArray(input_array); let hidden = Matrix.multiply(this.weights_ih, inputs); @@ -91,7 +88,6 @@ class NeuralNetwork { gradients.multiply(output_errors); gradients.multiply(this.learning_rate); - // Calculate deltas let hidden_T = Matrix.transpose(hidden); let weight_ho_deltas = Matrix.multiply(gradients, hidden_T); @@ -131,7 +127,11 @@ class NeuralNetwork { if (typeof data == 'string') { data = JSON.parse(data); } - let nn = new NeuralNetwork(data.input_nodes, data.hidden_nodes, data.output_nodes); + let nn = new NeuralNetwork( + data.input_nodes, + data.hidden_nodes, + data.output_nodes + ); nn.weights_ih = Matrix.deserialize(data.weights_ih); nn.weights_ho = Matrix.deserialize(data.weights_ho); nn.bias_h = Matrix.deserialize(data.bias_h); @@ -139,5 +139,4 @@ class NeuralNetwork { nn.learning_rate = data.learning_rate; return nn; } - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_092_xor/P5/sketch.js b/CodingChallenges/CC_092_xor/P5/sketch.js index 782a2de62c..863e3f5648 100644 --- a/CodingChallenges/CC_092_xor/P5/sketch.js +++ b/CodingChallenges/CC_092_xor/P5/sketch.js @@ -10,7 +10,8 @@ let nn; let lr_slider; -let training_data = [{ +let training_data = [ + { inputs: [0, 0], outputs: [0] }, @@ -32,7 +33,6 @@ function setup() { createCanvas(400, 400); nn = new NeuralNetwork(2, 4, 1); lr_slider = createSlider(0.01, 0.5, 0.1, 0.01); - } function draw() { @@ -59,7 +59,4 @@ function draw() { rect(i * resolution, j * resolution, resolution, resolution); } } - - - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_093_DoublePendulum/P5/sketch.js b/CodingChallenges/CC_093_DoublePendulum/P5/sketch.js index 32f3e268e1..8b2f299159 100644 --- a/CodingChallenges/CC_093_DoublePendulum/P5/sketch.js +++ b/CodingChallenges/CC_093_DoublePendulum/P5/sketch.js @@ -47,7 +47,7 @@ function draw() { let a1_a = (num1 + num2 + num3 * num4) / den; num1 = 2 * sin(a1 - a2); - num2 = (a1_v * a1_v * r1 * (m1 + m2)); + num2 = a1_v * a1_v * r1 * (m1 + m2); num3 = g * (m1 + m2) * cos(a1); num4 = a2_v * a2_v * r2 * m2 * cos(a1 - a2); den = r2 * (2 * m1 + m2 - m2 * cos(2 * a1 - 2 * a2)); @@ -86,4 +86,4 @@ function draw() { px2 = x2; py2 = y2; -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_094_2048/P5/config.js b/CodingChallenges/CC_094_2048/P5/config.js index cd65d0a94b..b411be11d7 100644 --- a/CodingChallenges/CC_094_2048/P5/config.js +++ b/CodingChallenges/CC_094_2048/P5/config.js @@ -1,46 +1,46 @@ let colorsSizes = { - "2": { + '2': { size: 64, - color: "#F35956" + color: '#F35956' }, - "4": { + '4': { size: 64, - color: "#F35956" + color: '#F35956' }, - "8": { + '8': { size: 64, - color: "#49BB6C" + color: '#49BB6C' }, - "16": { + '16': { size: 64, - color: "#2494C1" + color: '#2494C1' }, - "32": { + '32': { size: 64, - color: "#9659A7" + color: '#9659A7' }, - "64": { + '64': { size: 64, - color: "#F1C500" + color: '#F1C500' }, - "128": { + '128': { size: 36, - color: "#FF5956" + color: '#FF5956' }, - "256": { + '256': { size: 36, - color: "#F1C5FF" + color: '#F1C5FF' }, - "512": { + '512': { size: 36, - color: "#00000" + color: '#00000' }, - "1024": { + '1024': { size: 64, - color: "#24FFC1" + color: '#24FFC1' }, - "2048": { + '2048': { size: 64, - color: "#A659A9" - }, -} + color: '#A659A9' + } +}; diff --git a/CodingChallenges/CC_094_2048/P5/game.js b/CodingChallenges/CC_094_2048/P5/game.js index 047a7a2fe9..59e5dc1a06 100644 --- a/CodingChallenges/CC_094_2048/P5/game.js +++ b/CodingChallenges/CC_094_2048/P5/game.js @@ -49,7 +49,6 @@ function isGameWon() { return false; } - function isGameOver() { for (let i = 0; i < 4; i++) { for (let j = 0; j < 4; j++) { diff --git a/CodingChallenges/CC_094_2048/P5/sketch.js b/CodingChallenges/CC_094_2048/P5/sketch.js index ae1a3983d9..df13468c3d 100644 --- a/CodingChallenges/CC_094_2048/P5/sketch.js +++ b/CodingChallenges/CC_094_2048/P5/sketch.js @@ -69,14 +69,13 @@ function keyPressed() { let gameover = isGameOver(); if (gameover) { - console.log("GAME OVER"); + console.log('GAME OVER'); } let gamewon = isGameWon(); if (gamewon) { - console.log("GAME WON"); + console.log('GAME WON'); } - } } diff --git a/CodingChallenges/CC_096_Visualizing_the_Digits_of_Pi/P5/sketch.js b/CodingChallenges/CC_096_Visualizing_the_Digits_of_Pi/P5/sketch.js index d3acdd5eb7..d2deffa831 100644 --- a/CodingChallenges/CC_096_Visualizing_the_Digits_of_Pi/P5/sketch.js +++ b/CodingChallenges/CC_096_Visualizing_the_Digits_of_Pi/P5/sketch.js @@ -11,15 +11,14 @@ let counts = new Array(10); let index = 0; function preload() { - pi = loadStrings("pi-1million.txt"); + pi = loadStrings('pi-1million.txt'); } function setup() { createCanvas(420, 420); - //println(pi.length()); - const sdigits = pi[0].split(""); + const sdigits = pi[0].split(''); //println(sdigits.length); digits = int(sdigits); @@ -33,7 +32,6 @@ function setup() { } function draw() { - translate(width / 2, height / 2); const digit = digits[index]; @@ -53,5 +51,4 @@ function draw() { stroke(255, 50); line(x1, y1, x2, y2); - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_098.1_QuadTree/P5/quadtree.js b/CodingChallenges/CC_098.1_QuadTree/P5/quadtree.js index b70b00d918..a040a1e216 100644 --- a/CodingChallenges/CC_098.1_QuadTree/P5/quadtree.js +++ b/CodingChallenges/CC_098.1_QuadTree/P5/quadtree.js @@ -25,20 +25,22 @@ class Rectangle { } contains(point) { - return (point.x >= this.x - this.w && + return ( + point.x >= this.x - this.w && point.x < this.x + this.w && point.y >= this.y - this.h && - point.y < this.y + this.h); + point.y < this.y + this.h + ); } intersects(range) { - return !(range.x - range.w > this.x + this.w || + return !( + range.x - range.w > this.x + this.w || range.x + range.w < this.x - this.w || range.y - range.h > this.y + this.h || - range.y + range.h < this.y - this.h); + range.y + range.h < this.y - this.h + ); } - - } class QuadTree { @@ -66,7 +68,6 @@ class QuadTree { } insert(point) { - if (!this.boundary.contains(point)) { return false; } @@ -112,13 +113,17 @@ class QuadTree { return found; } - show() { stroke(255); noFill(); strokeWeight(1); rectMode(CENTER); - rect(this.boundary.x, this.boundary.y, this.boundary.w * 2, this.boundary.h * 2); + rect( + this.boundary.x, + this.boundary.y, + this.boundary.w * 2, + this.boundary.h * 2 + ); for (let p of this.points) { strokeWeight(2); point(p.x, p.y); @@ -131,9 +136,4 @@ class QuadTree { this.southwest.show(); } } - - - - - } diff --git a/CodingChallenges/CC_098.1_QuadTree/P5/sketch.js b/CodingChallenges/CC_098.1_QuadTree/P5/sketch.js index ff81f58242..a66d433677 100644 --- a/CodingChallenges/CC_098.1_QuadTree/P5/sketch.js +++ b/CodingChallenges/CC_098.1_QuadTree/P5/sketch.js @@ -31,7 +31,7 @@ function draw() { stroke(0, 255, 0); rectMode(CENTER); let range = new Rectangle(mouseX, mouseY, 25, 25); - + // This check has been introduced due to a bug discussed in https://github.com/CodingTrain/website/pull/556 if (mouseX < width && mouseY < height) { rect(range.x, range.y, range.w * 2, range.h * 2); @@ -41,5 +41,4 @@ function draw() { point(p.x, p.y); } } - } diff --git a/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/particle.js b/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/particle.js index 71fabd0f2e..0274232aad 100644 --- a/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/particle.js +++ b/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/particle.js @@ -18,7 +18,7 @@ class Particle { intersects(other) { let d = dist(this.x, this.y, other.x, other.y); - return (d < this.r + other.r); + return d < this.r + other.r; } setHighlight(value) { @@ -39,5 +39,4 @@ class Particle { } ellipse(this.x, this.y, this.r * 2); } - } diff --git a/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/quadtree.js b/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/quadtree.js index cf726292fc..002a0bf6d9 100644 --- a/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/quadtree.js +++ b/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/quadtree.js @@ -25,21 +25,22 @@ class Rectangle { } contains(point) { - return (point.x >= this.x - this.w && + return ( + point.x >= this.x - this.w && point.x <= this.x + this.w && point.y >= this.y - this.h && - point.y <= this.y + this.h); + point.y <= this.y + this.h + ); } - intersects(range) { - return !(range.x - range.w > this.x + this.w || + return !( + range.x - range.w > this.x + this.w || range.x + range.w < this.x - this.w || range.y - range.h > this.y + this.h || - range.y + range.h < this.y - this.h); + range.y + range.h < this.y - this.h + ); } - - } // circle class for a circle shaped query @@ -55,12 +56,11 @@ class Circle { // check if the point is in the circle by checking if the euclidean distance of // the point and the center of the circle if smaller or equal to the radius of // the circle - let d = Math.pow((point.x - this.x), 2) + Math.pow((point.y - this.y), 2); + let d = Math.pow(point.x - this.x, 2) + Math.pow(point.y - this.y, 2); return d <= this.rSquared; } intersects(range) { - var xDist = Math.abs(range.x - this.x); var yDist = Math.abs(range.y - this.y); @@ -70,15 +70,13 @@ class Circle { var w = range.w; var h = range.h; - var edges = Math.pow((xDist - w), 2) + Math.pow((yDist - h), 2); + var edges = Math.pow(xDist - w, 2) + Math.pow(yDist - h, 2); // no intersection - if (xDist > (r + w) || yDist > (r + h)) - return false; + if (xDist > r + w || yDist > r + h) return false; // intersection within the circle - if (xDist <= w || yDist <= h) - return true; + if (xDist <= w || yDist <= h) return true; // intersection on the edge of the circle return edges <= this.rSquared; @@ -94,7 +92,9 @@ class QuadTree { throw TypeError('boundary should be a Rectangle'); } if (typeof capacity !== 'number') { - throw TypeError(`capacity should be a number but is a ${typeof capacity}`); + throw TypeError( + `capacity should be a number but is a ${typeof capacity}` + ); } if (capacity < 1) { throw RangeError('capacity must be greater than 0'); @@ -137,8 +137,12 @@ class QuadTree { this.subdivide(); } - if (this.northeast.insert(point) || this.northwest.insert(point) || - this.southeast.insert(point) || this.southwest.insert(point)) { + if ( + this.northeast.insert(point) || + this.northwest.insert(point) || + this.southeast.insert(point) || + this.southwest.insert(point) + ) { return true; } } @@ -166,5 +170,4 @@ class QuadTree { return found; } - } diff --git a/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/sketch.js b/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/sketch.js index 1bc6638537..9f961f202e 100644 --- a/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/sketch.js +++ b/CodingChallenges/CC_098.3_QuadTree_Collisions/P5/sketch.js @@ -8,7 +8,6 @@ // For more: // https://github.com/CodingTrain/QuadTree - let particles = []; function setup() { @@ -21,7 +20,6 @@ function setup() { function draw() { background(0); - let boundary = new Rectangle(300, 200, 600, 400); let qtree = new QuadTree(boundary, 4); @@ -29,7 +27,6 @@ function draw() { let point = new Point(p.x, p.y, p); qtree.insert(point); - p.move(); p.render(); p.setHighlight(false); @@ -46,5 +43,4 @@ function draw() { } } } - } diff --git a/CodingChallenges/CC_099_ColorPredictor/P5/sketch.js b/CodingChallenges/CC_099_ColorPredictor/P5/sketch.js index 5d6104cb9b..fda1cf8f40 100644 --- a/CodingChallenges/CC_099_ColorPredictor/P5/sketch.js +++ b/CodingChallenges/CC_099_ColorPredictor/P5/sketch.js @@ -12,7 +12,7 @@ let r, g, b; let brain; -let which = "black"; +let which = 'black'; let wButton; let bButton; @@ -39,7 +39,6 @@ function setup() { } pickColor(); - } function mousePressed() { @@ -53,11 +52,9 @@ function mousePressed() { // // brain.train(inputs, targets); - pickColor(); } - function colorPredictor(r, g, b) { console.log(floor(r + g + b)); let inputs = [r / 255, g / 255, b / 255]; @@ -65,9 +62,9 @@ function colorPredictor(r, g, b) { //console.log(outputs); if (outputs[0] > outputs[1]) { - return "black"; + return 'black'; } else { - return "white"; + return 'white'; } // if (r + g + b > 300) { @@ -85,7 +82,6 @@ function trainColor(r, g, b) { } } - function draw() { background(r, g, b); strokeWeight(4); @@ -96,18 +92,16 @@ function draw() { noStroke(); fill(0); textAlign(CENTER, CENTER); - text("black", 150, 100); + text('black', 150, 100); fill(255); - text("white", 450, 100); + text('white', 450, 100); let which = colorPredictor(r, g, b); - if (which === "black") { + if (which === 'black') { fill(0); ellipse(150, 200, 60); } else { fill(255); ellipse(450, 200, 60); } - - } diff --git a/CodingChallenges/CC_100.1_NeuroEvolution_FlappyBird/P5/bird.js b/CodingChallenges/CC_100.1_NeuroEvolution_FlappyBird/P5/bird.js index 669a8638eb..d19e7b0680 100755 --- a/CodingChallenges/CC_100.1_NeuroEvolution_FlappyBird/P5/bird.js +++ b/CodingChallenges/CC_100.1_NeuroEvolution_FlappyBird/P5/bird.js @@ -13,7 +13,6 @@ class Bird { this.lift = -12; this.velocity = 0; - this.score = 0; this.fitness = 0; if (brain) { @@ -21,7 +20,6 @@ class Bird { } else { this.brain = new NeuralNetwork(5, 8, 2); } - } show() { @@ -39,19 +37,17 @@ class Bird { } think(pipes) { - // Find the closest pipe let closest = null; let closestD = Infinity; for (let i = 0; i < pipes.length; i++) { - let d = (pipes[i].x + pipes[i].w) - this.x; + let d = pipes[i].x + pipes[i].w - this.x; if (d < closestD && d > 0) { closest = pipes[i]; closestD = d; } } - let inputs = []; inputs[0] = this.y / height; inputs[1] = closest.top / height; @@ -63,11 +59,10 @@ class Bird { if (output[0] > output[1]) { this.up(); } - } offScreen() { - return (this.y > height || this.y < 0); + return this.y > height || this.y < 0; } update() { @@ -77,5 +72,4 @@ class Bird { //this.velocity *= 0.9; this.y += this.velocity; } - } diff --git a/CodingChallenges/CC_100.1_NeuroEvolution_FlappyBird/P5/pipe.js b/CodingChallenges/CC_100.1_NeuroEvolution_FlappyBird/P5/pipe.js index 1d4d6d616a..d9c5844de8 100755 --- a/CodingChallenges/CC_100.1_NeuroEvolution_FlappyBird/P5/pipe.js +++ b/CodingChallenges/CC_100.1_NeuroEvolution_FlappyBird/P5/pipe.js @@ -5,10 +5,9 @@ // Neuro-Evolution Flappy Bird class Pipe { - constructor() { this.spacing = 125; - this.top = random(height / 6, 3 / 4 * height); + this.top = random(height / 6, (3 / 4) * height); this.bottom = height - (this.top + this.spacing); this.x = width; this.w = 80; diff --git a/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/bird.js b/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/bird.js index 669a8638eb..d19e7b0680 100755 --- a/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/bird.js +++ b/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/bird.js @@ -13,7 +13,6 @@ class Bird { this.lift = -12; this.velocity = 0; - this.score = 0; this.fitness = 0; if (brain) { @@ -21,7 +20,6 @@ class Bird { } else { this.brain = new NeuralNetwork(5, 8, 2); } - } show() { @@ -39,19 +37,17 @@ class Bird { } think(pipes) { - // Find the closest pipe let closest = null; let closestD = Infinity; for (let i = 0; i < pipes.length; i++) { - let d = (pipes[i].x + pipes[i].w) - this.x; + let d = pipes[i].x + pipes[i].w - this.x; if (d < closestD && d > 0) { closest = pipes[i]; closestD = d; } } - let inputs = []; inputs[0] = this.y / height; inputs[1] = closest.top / height; @@ -63,11 +59,10 @@ class Bird { if (output[0] > output[1]) { this.up(); } - } offScreen() { - return (this.y > height || this.y < 0); + return this.y > height || this.y < 0; } update() { @@ -77,5 +72,4 @@ class Bird { //this.velocity *= 0.9; this.y += this.velocity; } - } diff --git a/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/pipe.js b/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/pipe.js index c32a098dbd..9c42c44897 100755 --- a/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/pipe.js +++ b/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/pipe.js @@ -5,10 +5,9 @@ // Neuro-Evolution Flappy Bird class Pipe { - constructor() { this.spacing = 125; - this.top = random(height / 6, 3 / 4 * height); + this.top = random(height / 6, (3 / 4) * height); this.bottom = height - (this.top + this.spacing); this.x = width; this.w = 80; diff --git a/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/sketch.js b/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/sketch.js index 0c77006844..2ea3ca2f74 100755 --- a/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/sketch.js +++ b/CodingChallenges/CC_100.5_NeuroEvolution_FlappyBird/P5/sketch.js @@ -18,11 +18,10 @@ let counter = 0; let brainJSON; function preload() { - brainJSON = loadJSON("best_bird.json"); + brainJSON = loadJSON('best_bird.json'); //brainJSON = loadJSON("bad_bird.json"); } - function setup() { createCanvas(640, 480); slider = createSlider(1, 10, 1); @@ -31,7 +30,6 @@ function setup() { } function draw() { - for (let n = 0; n < slider.value(); n++) { if (counter % 75 == 0) { pipes.push(new Pipe()); @@ -42,7 +40,7 @@ function draw() { pipes[i].update(); if (pipes[i].hits(bird)) { - console.log("collision"); + console.log('collision'); } if (pipes[i].offscreen()) { pipes.splice(i, 1); @@ -50,15 +48,12 @@ function draw() { } if (bird.offScreen()) { - console.log("bottom"); + console.log('bottom'); } - bird.think(pipes); bird.update(); - - // All the drawing stuff background(0); diff --git a/CodingChallenges/CC_104_tf_linear_regression/P5/sketch.js b/CodingChallenges/CC_104_tf_linear_regression/P5/sketch.js index 7aa828036c..b2c509d4ca 100755 --- a/CodingChallenges/CC_104_tf_linear_regression/P5/sketch.js +++ b/CodingChallenges/CC_104_tf_linear_regression/P5/sketch.js @@ -20,7 +20,10 @@ function setup() { } function loss(pred, labels) { - return pred.sub(labels).square().mean(); + return pred + .sub(labels) + .square() + .mean(); } function predict(x) { @@ -38,7 +41,6 @@ function mousePressed() { } function draw() { - tf.tidy(() => { if (x_vals.length > 0) { const ys = tf.tensor1d(y_vals); @@ -56,7 +58,6 @@ function draw() { point(px, py); } - const lineX = [0, 1]; const ys = tf.tidy(() => predict(lineX)); @@ -72,7 +73,6 @@ function draw() { strokeWeight(2); line(x1, y1, x2, y2); - console.log(tf.memory().numTensors); //noLoop(); } diff --git a/CodingChallenges/CC_105_tf_polynomial_regression/P5/sketch.js b/CodingChallenges/CC_105_tf_polynomial_regression/P5/sketch.js index bb967d758e..358f0d93f8 100755 --- a/CodingChallenges/CC_105_tf_polynomial_regression/P5/sketch.js +++ b/CodingChallenges/CC_105_tf_polynomial_regression/P5/sketch.js @@ -23,20 +23,24 @@ function setup() { } function loss(pred, labels) { - return pred.sub(labels).square().mean(); + return pred + .sub(labels) + .square() + .mean(); } function predict(x) { const xs = tf.tensor1d(x); // y = ax^3 + bx^2 + cx + d - const ys = xs.pow(tf.scalar(3)).mul(a) + const ys = xs + .pow(tf.scalar(3)) + .mul(a) .add(xs.square().mul(b)) .add(xs.mul(c)) .add(d); return ys; } - function mousePressed() { dragging = true; } @@ -70,7 +74,6 @@ function draw() { point(px, py); } - const curveX = []; for (let x = -1; x <= 1; x += 0.05) { curveX.push(x); diff --git a/CodingChallenges/CC_106_xor_tfjs/P5/sketch.js b/CodingChallenges/CC_106_xor_tfjs/P5/sketch.js index 1c2a61e5c8..c1fe223759 100644 --- a/CodingChallenges/CC_106_xor_tfjs/P5/sketch.js +++ b/CodingChallenges/CC_106_xor_tfjs/P5/sketch.js @@ -20,12 +20,7 @@ const train_xs = tf.tensor2d([ [0, 1], [1, 1] ]); -const train_ys = tf.tensor2d([ - [0], - [1], - [1], - [0] -]); +const train_ys = tf.tensor2d([[0], [1], [1], [0]]); function setup() { createCanvas(400, 400); @@ -43,7 +38,6 @@ function setup() { } xs = tf.tensor2d(inputs); - model = tf.sequential(); let hidden = tf.layers.dense({ inputShape: [2], @@ -61,10 +55,9 @@ function setup() { model.compile({ optimizer: optimizer, loss: 'meanSquaredError' - }) + }); setTimeout(train, 10); - } function train() { @@ -84,10 +77,6 @@ function trainModel() { function draw() { background(0); - - - - tf.tidy(() => { // Get the predictions let ys = model.predict(xs); @@ -97,16 +86,19 @@ function draw() { let index = 0; for (let i = 0; i < cols; i++) { for (let j = 0; j < rows; j++) { - let br = y_values[index] * 255 + let br = y_values[index] * 255; fill(br); rect(i * resolution, j * resolution, resolution, resolution); fill(255 - br); textSize(8); textAlign(CENTER, CENTER); - text(nf(y_values[index], 1, 2), i * resolution + resolution / 2, j * resolution + resolution / 2) + text( + nf(y_values[index], 1, 2), + i * resolution + resolution / 2, + j * resolution + resolution / 2 + ); index++; } } }); - } diff --git a/CodingChallenges/CC_107_sandpiles/P5/sketch.js b/CodingChallenges/CC_107_sandpiles/P5/sketch.js index 8035d18e16..9dc3b13be1 100644 --- a/CodingChallenges/CC_107_sandpiles/P5/sketch.js +++ b/CodingChallenges/CC_107_sandpiles/P5/sketch.js @@ -7,10 +7,10 @@ let defaultColor = [255, 0, 0]; let colors = [ - [255, 255, 0], - [ 0, 185, 63], - [ 0, 104, 255], - [122, 0, 229] + [255, 255, 0], + [0, 185, 63], + [0, 104, 255], + [122, 0, 229] ]; let sandpiles; @@ -23,7 +23,7 @@ function setup() { sandpiles = new Array(width).fill().map(i => new Array(height).fill(0)); nextpiles = new Array(width).fill().map(i => new Array(height).fill(0)); - sandpiles[width/2][height/2] = 1000000000; + sandpiles[width / 2][height / 2] = 1000000000; background(defaultColor[0], defaultColor[1], defaultColor[2]); } @@ -40,14 +40,10 @@ function topple() { let num = sandpiles[x][y]; if (num >= 4) { nextpiles[x][y] -= 4; - if (x+1 < width) - nextpiles[x+1][y]++; - if (x-1 >= 0) - nextpiles[x-1][y]++; - if (y+1 < height) - nextpiles[x][y+1]++; - if (y-1 >= 0) - nextpiles[x][y-1]++; + if (x + 1 < width) nextpiles[x + 1][y]++; + if (x - 1 >= 0) nextpiles[x - 1][y]++; + if (y + 1 < height) nextpiles[x][y + 1]++; + if (y - 1 >= 0) nextpiles[x][y - 1]++; } } } @@ -74,7 +70,7 @@ function render() { } let pix = (x + y * width) * 4; - pixels[pix ] = col[0]; + pixels[pix] = col[0]; pixels[pix + 1] = col[1]; pixels[pix + 2] = col[2]; // pixels[pix + 3] = 255; diff --git a/CodingChallenges/CC_108_barnsley_fern/P5/sketch.js b/CodingChallenges/CC_108_barnsley_fern/P5/sketch.js index 9c2f235278..87ff329697 100644 --- a/CodingChallenges/CC_108_barnsley_fern/P5/sketch.js +++ b/CodingChallenges/CC_108_barnsley_fern/P5/sketch.js @@ -2,45 +2,42 @@ let x = 0; let y = 0; function setup() { - createCanvas(600, 600); - background(0); + createCanvas(600, 600); + background(0); } function draw() { - for(let i = 0; i < 100; i++){ + for (let i = 0; i < 100; i++) { drawPoint(); nextPoint(); - } - + } } function drawPoint() { - stroke(255); - strokeWeight(2); - let px = map(x, -2.1820, 2.6558, 0, width); - let py = map(y, 0, 9.9983, height, 0); - - point(px, py); - + stroke(255); + strokeWeight(2); + let px = map(x, -2.182, 2.6558, 0, width); + let py = map(y, 0, 9.9983, height, 0); + point(px, py); } function nextPoint() { - let nextX; - let nextY; - let r = random(1); + let nextX; + let nextY; + let r = random(1); - if (r < 0.01) { - nextY = 0.16 * y; - nextX = 0; - } else if (r < 0.86) { - nextX = 0.85 * x + 0.04 * y; - nextY = -0.04 * x + 0.85 * y + 1.6; - } else if (r < 0.93) { - nextX = 0.2 * x + -0.26 * y; - nextY = 0.23 * x + 0.22 * y + 1.6; - } else { - nextX = -0.15 * x + 0.28 * y; - nextY = 0.26 * x + 0.24 * y + 0.44; - } - x = nextX; - y = nextY; -} \ No newline at end of file + if (r < 0.01) { + nextY = 0.16 * y; + nextX = 0; + } else if (r < 0.86) { + nextX = 0.85 * x + 0.04 * y; + nextY = -0.04 * x + 0.85 * y + 1.6; + } else if (r < 0.93) { + nextX = 0.2 * x + -0.26 * y; + nextY = 0.23 * x + 0.22 * y + 1.6; + } else { + nextX = -0.15 * x + 0.28 * y; + nextY = 0.26 * x + 0.24 * y + 0.44; + } + x = nextX; + y = nextY; +} diff --git a/CodingChallenges/CC_109_subscriber_map/P5/sketch.js b/CodingChallenges/CC_109_subscriber_map/P5/sketch.js index 73e0562bb4..6c01cef181 100755 --- a/CodingChallenges/CC_109_subscriber_map/P5/sketch.js +++ b/CodingChallenges/CC_109_subscriber_map/P5/sketch.js @@ -18,14 +18,13 @@ const options = { lat: 0, lng: 0, zoom: 1.5, - style: "http://{s}.tile.osm.org/{z}/{x}/{y}.png" -} + style: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png' +}; function preload() { youtubeData = loadTable('subscribers_geo.csv', 'header'); //youtubeData = loadTable('watch_time_geo.csv', 'header'); countries = loadJSON('countries.json'); - } function setup() { @@ -68,8 +67,6 @@ function setup() { //console.log(data); - - // console.log(countries); //console.log(youtubeData); } @@ -83,7 +80,4 @@ function draw() { const scl = pow(2, zoom); // * sin(frameCount * 0.1); ellipse(pix.x, pix.y, country.diameter * scl); } - - - } diff --git a/CodingChallenges/CC_110.2_recaman_music/P5/sketch.js b/CodingChallenges/CC_110.2_recaman_music/P5/sketch.js index 1bff9f4491..fd6dc6cdd7 100644 --- a/CodingChallenges/CC_110.2_recaman_music/P5/sketch.js +++ b/CodingChallenges/CC_110.2_recaman_music/P5/sketch.js @@ -8,7 +8,7 @@ let attackLevel = 1; let releaseLevel = 0; -let attackTime = 0.01 +let attackTime = 0.01; let decayTime = 0.1; let susPercent = 0.5; let releaseTime = 0.5; @@ -45,7 +45,6 @@ class Arc { arc(x, 0, diameter, diameter, 0, PI); } } - } function setup() { diff --git a/CodingChallenges/CC_111_animated_sprite/P5/sketch.js b/CodingChallenges/CC_111_animated_sprite/P5/sketch.js index d7e299167e..8a603b8161 100755 --- a/CodingChallenges/CC_111_animated_sprite/P5/sketch.js +++ b/CodingChallenges/CC_111_animated_sprite/P5/sketch.js @@ -20,7 +20,6 @@ function preload() { spritesheet = loadImage('horse/horse.png'); } - function setup() { createCanvas(640, 480); let frames = spritedata.frames; @@ -44,4 +43,4 @@ function draw() { } // image(animation[frameCount % animation.length], 0, 0); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_111_animated_sprite/P5/sprite.js b/CodingChallenges/CC_111_animated_sprite/P5/sprite.js index 1ebe85363d..d2ece760e7 100755 --- a/CodingChallenges/CC_111_animated_sprite/P5/sprite.js +++ b/CodingChallenges/CC_111_animated_sprite/P5/sprite.js @@ -32,4 +32,4 @@ class Sprite { this.x = -this.w; } } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_112_3D_Rendering/P5/matrix.js b/CodingChallenges/CC_112_3D_Rendering/P5/matrix.js index e172903851..1d2b0e38d3 100644 --- a/CodingChallenges/CC_112_3D_Rendering/P5/matrix.js +++ b/CodingChallenges/CC_112_3D_Rendering/P5/matrix.js @@ -10,66 +10,66 @@ // https://youtu.be/tzsgS19RRc8 function vecToMatrix(v) { - let m = []; - for (let i = 0; i < 3; i++) { - m[i] = []; - } - m[0][0] = v.x; - m[1][0] = v.y; - m[2][0] = v.z; - return m; + let m = []; + for (let i = 0; i < 3; i++) { + m[i] = []; + } + m[0][0] = v.x; + m[1][0] = v.y; + m[2][0] = v.z; + return m; } function matrixToVec(m) { - return createVector(m[0][0], m[1][0], m.length > 2 ? m[2][0] : 0); + return createVector(m[0][0], m[1][0], m.length > 2 ? m[2][0] : 0); } function logMatrix(m) { - const cols = m[0].length; - const rows = m.length; - console.log(rows + "x" + cols); - console.log("----------------"); - let s = ''; - for (let i = 0; i < rows; i++) { - for (let j = 0; j < cols; j++) { - s += (m[i][j] + " "); - } - console.log(s); + const cols = m[0].length; + const rows = m.length; + console.log(rows + 'x' + cols); + console.log('----------------'); + let s = ''; + for (let i = 0; i < rows; i++) { + for (let j = 0; j < cols; j++) { + s += m[i][j] + ' '; } - console.log(); + console.log(s); + } + console.log(); } function matmulvec(a, vec) { - let m = vecToMatrix(vec); - let r = matmul(a, m); - return matrixToVec(r); + let m = vecToMatrix(vec); + let r = matmul(a, m); + return matrixToVec(r); } function matmul(a, b) { - if (b instanceof p5.Vector) { - return matmulvec(a, b); - } + if (b instanceof p5.Vector) { + return matmulvec(a, b); + } - let colsA = a[0].length; - let rowsA = a.length; - let colsB = b[0].length; - let rowsB = b.length; + let colsA = a[0].length; + let rowsA = a.length; + let colsB = b[0].length; + let rowsB = b.length; - if (colsA !== rowsB) { - console.error("Columns of A must match rows of B"); - return null; - } + if (colsA !== rowsB) { + console.error('Columns of A must match rows of B'); + return null; + } - result = []; - for (let j = 0; j < rowsA; j++) { - result[j] = []; - for (let i = 0; i < colsB; i++) { - let sum = 0; - for (let n = 0; n < colsA; n++) { - sum += a[j][n] * b[n][i]; - } - result[j][i] = sum; - } + result = []; + for (let j = 0; j < rowsA; j++) { + result[j] = []; + for (let i = 0; i < colsB; i++) { + let sum = 0; + for (let n = 0; n < colsA; n++) { + sum += a[j][n] * b[n][i]; + } + result[j][i] = sum; } - return result; + } + return result; } diff --git a/CodingChallenges/CC_112_3D_Rendering/P5/sketch.js b/CodingChallenges/CC_112_3D_Rendering/P5/sketch.js index d9f38f55bc..1ff4725eec 100644 --- a/CodingChallenges/CC_112_3D_Rendering/P5/sketch.js +++ b/CodingChallenges/CC_112_3D_Rendering/P5/sketch.js @@ -11,79 +11,79 @@ let angle = 0; let points = []; const projection = [ - [1, 0, 0], - [0, 1, 0], + [1, 0, 0], + [0, 1, 0] ]; function setup() { - createCanvas(600, 400); - - points[0] = createVector(-0.5, -0.5, -0.5); - points[1] = createVector(0.5, -0.5, -0.5); - points[2] = createVector(0.5, 0.5, -0.5); - points[3] = createVector(-0.5, 0.5, -0.5); - points[4] = createVector(-0.5, -0.5, 0.5); - points[5] = createVector(0.5, -0.5, 0.5); - points[6] = createVector(0.5, 0.5, 0.5); - points[7] = createVector(-0.5, 0.5, 0.5); + createCanvas(600, 400); + + points[0] = createVector(-0.5, -0.5, -0.5); + points[1] = createVector(0.5, -0.5, -0.5); + points[2] = createVector(0.5, 0.5, -0.5); + points[3] = createVector(-0.5, 0.5, -0.5); + points[4] = createVector(-0.5, -0.5, 0.5); + points[5] = createVector(0.5, -0.5, 0.5); + points[6] = createVector(0.5, 0.5, 0.5); + points[7] = createVector(-0.5, 0.5, 0.5); } function draw() { - background(0); - translate(width / 2, height / 2); - - const rotationZ = [ - [cos(angle), -sin(angle), 0], - [sin(angle), cos(angle), 0], - [0, 0, 1], - ]; - - const rotationX = [ - [1, 0, 0], - [0, cos(angle), -sin(angle)], - [0, sin(angle), cos(angle)], - ]; - - const rotationY = [ - [cos(angle), 0, sin(angle)], - [0, 1, 0], - [-sin(angle), 0, cos(angle)], - ]; - - let projected = []; - - for (let i = 0; i < points.length; i++) { - let rotated = matmul(rotationY, points[i]); - rotated = matmul(rotationX, rotated); - rotated = matmul(rotationZ, rotated); - let projected2d = matmul(projection, rotated); - projected2d.mult(200); - projected[i] = projected2d; - //point(projected2d.x, projected2d.y); - } - - for (let i = 0; i < projected.length; i++) { - stroke(255); - strokeWeight(16); - noFill(); - const v = projected[i]; - point(v.x, v.y); - } - - // Connecting - for (let i = 0; i < 4; i++) { - connect(i, (i + 1) % 4, projected); - connect(i + 4, ((i + 1) % 4) + 4, projected); - connect(i, i + 4, projected); - } - - angle += 0.03; + background(0); + translate(width / 2, height / 2); + + const rotationZ = [ + [cos(angle), -sin(angle), 0], + [sin(angle), cos(angle), 0], + [0, 0, 1] + ]; + + const rotationX = [ + [1, 0, 0], + [0, cos(angle), -sin(angle)], + [0, sin(angle), cos(angle)] + ]; + + const rotationY = [ + [cos(angle), 0, sin(angle)], + [0, 1, 0], + [-sin(angle), 0, cos(angle)] + ]; + + let projected = []; + + for (let i = 0; i < points.length; i++) { + let rotated = matmul(rotationY, points[i]); + rotated = matmul(rotationX, rotated); + rotated = matmul(rotationZ, rotated); + let projected2d = matmul(projection, rotated); + projected2d.mult(200); + projected[i] = projected2d; + //point(projected2d.x, projected2d.y); + } + + for (let i = 0; i < projected.length; i++) { + stroke(255); + strokeWeight(16); + noFill(); + const v = projected[i]; + point(v.x, v.y); + } + + // Connecting + for (let i = 0; i < 4; i++) { + connect(i, (i + 1) % 4, projected); + connect(i + 4, ((i + 1) % 4) + 4, projected); + connect(i, i + 4, projected); + } + + angle += 0.03; } function connect(i, j, points) { - const a = points[i]; - const b = points[j]; - strokeWeight(1); - stroke(255); - line(a.x, a.y, b.x, b.y); -} \ No newline at end of file + const a = points[i]; + const b = points[j]; + strokeWeight(1); + stroke(255); + line(a.x, a.y, b.x, b.y); +} diff --git a/CodingChallenges/CC_113_Hypercube/P5/P4Vector.js b/CodingChallenges/CC_113_Hypercube/P5/P4Vector.js index d1445be517..379004edd2 100644 --- a/CodingChallenges/CC_113_Hypercube/P5/P4Vector.js +++ b/CodingChallenges/CC_113_Hypercube/P5/P4Vector.js @@ -9,19 +9,18 @@ // Matrix Multiplication // https://youtu.be/tzsgS19RRc8 - class P4Vector { - constructor(x, y, z, w) { - this.x = x || 0; - this.y = y || 0; - this.z = z || 0; - this.w = w || 0; - } + constructor(x, y, z, w) { + this.x = x || 0; + this.y = y || 0; + this.z = z || 0; + this.w = w || 0; + } - mult(f) { - this.x *= f; - this.y *= f; - this.z *= f; - this.w *= f; - } + mult(f) { + this.x *= f; + this.y *= f; + this.z *= f; + this.w *= f; + } } diff --git a/CodingChallenges/CC_113_Hypercube/P5/matrix.js b/CodingChallenges/CC_113_Hypercube/P5/matrix.js index 9073d329b8..3fec9e447d 100644 --- a/CodingChallenges/CC_113_Hypercube/P5/matrix.js +++ b/CodingChallenges/CC_113_Hypercube/P5/matrix.js @@ -10,90 +10,90 @@ // https://youtu.be/tzsgS19RRc8 function vecToMatrix(v) { - let m = []; - for (let i = 0; i < 3; i++) { - m[i] = []; - } - m[0][0] = v.x; - m[1][0] = v.y; - m[2][0] = v.z; - return m; + let m = []; + for (let i = 0; i < 3; i++) { + m[i] = []; + } + m[0][0] = v.x; + m[1][0] = v.y; + m[2][0] = v.z; + return m; } function vec4ToMatrix(v) { - let m = vecToMatrix(v); - m[3] = []; - m[3][0] = v.w; - return m; + let m = vecToMatrix(v); + m[3] = []; + m[3][0] = v.w; + return m; } function matrixToVec(m) { - return createVector(m[0][0], m[1][0], m[2][0]); + return createVector(m[0][0], m[1][0], m[2][0]); } function matrixToVec4(m) { - let r = new P4Vector(m[0][0], m[1][0], m[2][0], 0); - if (m.length > 3) { - r.w = m[3][0]; - } - return r; + let r = new P4Vector(m[0][0], m[1][0], m[2][0], 0); + if (m.length > 3) { + r.w = m[3][0]; + } + return r; } function logMatrix(m) { - const cols = m[0].length; - const rows = m.length; - console.log(rows + "x" + cols); - console.log("----------------"); - let s = ''; - for (let i = 0; i < rows; i++) { - for (let j = 0; j < cols; j++) { - s += (m[i][j] + " "); - } - console.log(s); + const cols = m[0].length; + const rows = m.length; + console.log(rows + 'x' + cols); + console.log('----------------'); + let s = ''; + for (let i = 0; i < rows; i++) { + for (let j = 0; j < cols; j++) { + s += m[i][j] + ' '; } - console.log(); + console.log(s); + } + console.log(); } function matmulvec(a, vec) { - let m = vecToMatrix(vec); - let r = matmul(a, m); - return matrixToVec(r); + let m = vecToMatrix(vec); + let r = matmul(a, m); + return matrixToVec(r); } function matmulvec4(a, vec) { - let m = vec4ToMatrix(vec); - let r = matmul(a, m); - return matrixToVec4(r); + let m = vec4ToMatrix(vec); + let r = matmul(a, m); + return matrixToVec4(r); } function matmul(a, b) { - if (b instanceof p5.Vector) { - return matmulvec(a, b); - } - if (b instanceof P4Vector) { - return matmulvec4(a, b); - } + if (b instanceof p5.Vector) { + return matmulvec(a, b); + } + if (b instanceof P4Vector) { + return matmulvec4(a, b); + } - let colsA = a[0].length; - let rowsA = a.length; - let colsB = b[0].length; - let rowsB = b.length; + let colsA = a[0].length; + let rowsA = a.length; + let colsB = b[0].length; + let rowsB = b.length; - if (colsA !== rowsB) { - console.error("Columns of A must match rows of B"); - return null; - } + if (colsA !== rowsB) { + console.error('Columns of A must match rows of B'); + return null; + } - result = []; - for (let j = 0; j < rowsA; j++) { - result[j] = []; - for (let i = 0; i < colsB; i++) { - let sum = 0; - for (let n = 0; n < colsA; n++) { - sum += a[j][n] * b[n][i]; - } - result[j][i] = sum; - } + result = []; + for (let j = 0; j < rowsA; j++) { + result[j] = []; + for (let i = 0; i < colsB; i++) { + let sum = 0; + for (let n = 0; n < colsA; n++) { + sum += a[j][n] * b[n][i]; + } + result[j][i] = sum; } - return result; + } + return result; } diff --git a/CodingChallenges/CC_113_Hypercube/P5/sketch.js b/CodingChallenges/CC_113_Hypercube/P5/sketch.js index 714b3eedcc..28fa683245 100644 --- a/CodingChallenges/CC_113_Hypercube/P5/sketch.js +++ b/CodingChallenges/CC_113_Hypercube/P5/sketch.js @@ -14,96 +14,96 @@ let angle = 0; let points = []; function setup() { - let size = min(windowWidth, windowHeight); - createCanvas(size, size, WEBGL); - points[0] = new P4Vector(-1, -1, -1, 1); - points[1] = new P4Vector(1, -1, -1, 1); - points[2] = new P4Vector(1, 1, -1, 1); - points[3] = new P4Vector(-1, 1, -1, 1); - points[4] = new P4Vector(-1, -1, 1, 1); - points[5] = new P4Vector(1, -1, 1, 1); - points[6] = new P4Vector(1, 1, 1, 1); - points[7] = new P4Vector(-1, 1, 1, 1); - points[8] = new P4Vector(-1, -1, -1, -1); - points[9] = new P4Vector(1, -1, -1, -1); - points[10] = new P4Vector(1, 1, -1, -1); - points[11] = new P4Vector(-1, 1, -1, -1); - points[12] = new P4Vector(-1, -1, 1, -1); - points[13] = new P4Vector(1, -1, 1, -1); - points[14] = new P4Vector(1, 1, 1, -1); - points[15] = new P4Vector(-1, 1, 1, -1); + let size = min(windowWidth, windowHeight); + createCanvas(size, size, WEBGL); + points[0] = new P4Vector(-1, -1, -1, 1); + points[1] = new P4Vector(1, -1, -1, 1); + points[2] = new P4Vector(1, 1, -1, 1); + points[3] = new P4Vector(-1, 1, -1, 1); + points[4] = new P4Vector(-1, -1, 1, 1); + points[5] = new P4Vector(1, -1, 1, 1); + points[6] = new P4Vector(1, 1, 1, 1); + points[7] = new P4Vector(-1, 1, 1, 1); + points[8] = new P4Vector(-1, -1, -1, -1); + points[9] = new P4Vector(1, -1, -1, -1); + points[10] = new P4Vector(1, 1, -1, -1); + points[11] = new P4Vector(-1, 1, -1, -1); + points[12] = new P4Vector(-1, -1, 1, -1); + points[13] = new P4Vector(1, -1, 1, -1); + points[14] = new P4Vector(1, 1, 1, -1); + points[15] = new P4Vector(-1, 1, 1, -1); } function draw() { - background(0); - rotateX(-PI / 2); - let projected3d = []; - - for (let i = 0; i < points.length; i++) { - const v = points[i]; - - const rotationXY = [ - [cos(angle), -sin(angle), 0, 0], - [sin(angle), cos(angle), 0, 0], - [0, 0, 1, 0], - [0, 0, 0, 1], - ]; - - const rotationZW = [ - [1, 0, 0, 0], - [0, 1, 0, 0], - [0, 0, cos(angle), -sin(angle)], - [0, 0, sin(angle), cos(angle)] - ]; - - let rotated = matmul(rotationXY, v); - rotated = matmul(rotationZW, rotated); - - let distance = 2; - let w = 1 / (distance - rotated.w); - - const projection = [ - [w, 0, 0, 0], - [0, w, 0, 0], - [0, 0, w, 0], - ]; - - let projected = matmul(projection, rotated); - projected.mult(width / 8); - projected3d[i] = projected; - - stroke(255, 200); - strokeWeight(32); - noFill(); - - point(projected.x, projected.y, projected.z); - } - - // Connecting - for (let i = 0; i < 4; i++) { - connect(0, i, (i + 1) % 4, projected3d); - connect(0, i + 4, ((i + 1) % 4) + 4, projected3d); - connect(0, i, i + 4, projected3d); - } - - for (let i = 0; i < 4; i++) { - connect(8, i, (i + 1) % 4, projected3d); - connect(8, i + 4, ((i + 1) % 4) + 4, projected3d); - connect(8, i, i + 4, projected3d); - } - - for (let i = 0; i < 8; i++) { - connect(0, i, i + 8, projected3d); - } - - //angle = map(mouseX, 0, width, 0, TWO_PI); - angle += 0.02; + background(0); + rotateX(-PI / 2); + let projected3d = []; + + for (let i = 0; i < points.length; i++) { + const v = points[i]; + + const rotationXY = [ + [cos(angle), -sin(angle), 0, 0], + [sin(angle), cos(angle), 0, 0], + [0, 0, 1, 0], + [0, 0, 0, 1] + ]; + + const rotationZW = [ + [1, 0, 0, 0], + [0, 1, 0, 0], + [0, 0, cos(angle), -sin(angle)], + [0, 0, sin(angle), cos(angle)] + ]; + + let rotated = matmul(rotationXY, v); + rotated = matmul(rotationZW, rotated); + + let distance = 2; + let w = 1 / (distance - rotated.w); + + const projection = [ + [w, 0, 0, 0], + [0, w, 0, 0], + [0, 0, w, 0] + ]; + + let projected = matmul(projection, rotated); + projected.mult(width / 8); + projected3d[i] = projected; + + stroke(255, 200); + strokeWeight(32); + noFill(); + + point(projected.x, projected.y, projected.z); + } + + // Connecting + for (let i = 0; i < 4; i++) { + connect(0, i, (i + 1) % 4, projected3d); + connect(0, i + 4, ((i + 1) % 4) + 4, projected3d); + connect(0, i, i + 4, projected3d); + } + + for (let i = 0; i < 4; i++) { + connect(8, i, (i + 1) % 4, projected3d); + connect(8, i + 4, ((i + 1) % 4) + 4, projected3d); + connect(8, i, i + 4, projected3d); + } + + for (let i = 0; i < 8; i++) { + connect(0, i, i + 8, projected3d); + } + + //angle = map(mouseX, 0, width, 0, TWO_PI); + angle += 0.02; } function connect(offset, i, j, points) { - strokeWeight(4); - stroke(255); - const a = points[i + offset]; - const b = points[j + offset]; - line(a.x, a.y, a.z, b.x, b.y, b.z); + strokeWeight(4); + stroke(255); + const a = points[i + offset]; + const b = points[j + offset]; + line(a.x, a.y, a.z, b.x, b.y, b.z); } diff --git a/CodingChallenges/CC_114_BubbleSortViz/P5/sketch.js b/CodingChallenges/CC_114_BubbleSortViz/P5/sketch.js index cf47dd2f32..492cdd64d8 100644 --- a/CodingChallenges/CC_114_BubbleSortViz/P5/sketch.js +++ b/CodingChallenges/CC_114_BubbleSortViz/P5/sketch.js @@ -31,7 +31,7 @@ function draw() { } } } else { - console.log("finished"); + console.log('finished'); noLoop(); } i++; @@ -46,4 +46,4 @@ function swap(arr, a, b) { let temp = arr[a]; arr[a] = arr[b]; arr[b] = temp; -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_115_Snake_Game_Redux/P5/sketch.js b/CodingChallenges/CC_115_Snake_Game_Redux/P5/sketch.js index 2e89c8ef2e..258ea5ee0f 100644 --- a/CodingChallenges/CC_115_Snake_Game_Redux/P5/sketch.js +++ b/CodingChallenges/CC_115_Snake_Game_Redux/P5/sketch.js @@ -24,7 +24,6 @@ function foodLocation() { let x = floor(random(w)); let y = floor(random(h)); food = createVector(x, y); - } function keyPressed() { @@ -39,7 +38,6 @@ function keyPressed() { } else if (key == ' ') { snake.grow(); } - } function draw() { @@ -51,9 +49,8 @@ function draw() { snake.update(); snake.show(); - if (snake.endGame()) { - print("END GAME"); + print('END GAME'); background(255, 0, 0); noLoop(); } @@ -61,4 +58,4 @@ function draw() { noStroke(); fill(255, 0, 0); rect(food.x, food.y, 1, 1); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_115_Snake_Game_Redux/P5/snake.js b/CodingChallenges/CC_115_Snake_Game_Redux/P5/snake.js index 9cdbcd8da9..274f12babc 100644 --- a/CodingChallenges/CC_115_Snake_Game_Redux/P5/snake.js +++ b/CodingChallenges/CC_115_Snake_Game_Redux/P5/snake.js @@ -6,7 +6,6 @@ // https://youtu.be/OMoVcohRgZA class Snake { - constructor() { this.body = []; this.body[0] = createVector(floor(w / 2), floor(h / 2)); @@ -63,8 +62,7 @@ class Snake { for (let i = 0; i < this.body.length; i++) { fill(0); noStroke(); - rect(this.body[i].x, this.body[i].y, 1, 1) + rect(this.body[i].x, this.body[i].y, 1, 1); } } - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_116_Lissajous/P5/curve.js b/CodingChallenges/CC_116_Lissajous/P5/curve.js index 4c5c9e76f4..9c596e0bdc 100644 --- a/CodingChallenges/CC_116_Lissajous/P5/curve.js +++ b/CodingChallenges/CC_116_Lissajous/P5/curve.js @@ -1,38 +1,38 @@ class Curve { - constructor() { - this.path = []; - this.current = createVector(); - } + constructor() { + this.path = []; + this.current = createVector(); + } - setX(x) { - this.current.x = x; - } + setX(x) { + this.current.x = x; + } - setY(y) { - this.current.y = y; - } + setY(y) { + this.current.y = y; + } - addPoint() { - this.path.push(this.current); - } + addPoint() { + this.path.push(this.current); + } - reset() { - this.path = []; - } - - show() { - stroke(255); - strokeWeight(1); - noFill(); - beginShape(); - for (let i = 0; i < this.path.length; i++) { - const v = this.path[i]; - vertex(v.x, v.y); - } - endShape(); + reset() { + this.path = []; + } - strokeWeight(8); - point(this.current.x, this.current.y); - this.current = createVector(); + show() { + stroke(255); + strokeWeight(1); + noFill(); + beginShape(); + for (let i = 0; i < this.path.length; i++) { + const v = this.path[i]; + vertex(v.x, v.y); } -} \ No newline at end of file + endShape(); + + strokeWeight(8); + point(this.current.x, this.current.y); + this.current = createVector(); + } +} diff --git a/CodingChallenges/CC_116_Lissajous/P5/sketch.js b/CodingChallenges/CC_116_Lissajous/P5/sketch.js index 917c07f6c2..e0a92f7ddf 100644 --- a/CodingChallenges/CC_116_Lissajous/P5/sketch.js +++ b/CodingChallenges/CC_116_Lissajous/P5/sketch.js @@ -16,84 +16,84 @@ let rows; let curves = []; function setup() { - createCanvas(windowWidth, windowHeight); - cols = width / w - 1; - rows = height / w - 1; + createCanvas(windowWidth, windowHeight); + cols = width / w - 1; + rows = height / w - 1; - for (let j = 0; j < rows; j++) { - curves[j] = []; - for (let i = 0; i < cols; i++) { - curves[j][i] = new Curve(); - } + for (let j = 0; j < rows; j++) { + curves[j] = []; + for (let i = 0; i < cols; i++) { + curves[j][i] = new Curve(); } + } } function draw() { - background(51); - let d = w - 0.2 * w; - let r = d / 2; + background(51); + let d = w - 0.2 * w; + let r = d / 2; - noFill(); + noFill(); + stroke(255); + for (let i = 0; i < cols; i++) { + let cx = w + i * w + w / 2; + let cy = w / 2; + strokeWeight(1); stroke(255); - for (let i = 0; i < cols; i++) { - let cx = w + i * w + w / 2; - let cy = w / 2; - strokeWeight(1); - stroke(255); - ellipse(cx, cy, d, d); - let x = r * cos(angle * (i + 1) - HALF_PI); - let y = r * sin(angle * (i + 1) - HALF_PI); - strokeWeight(8); - stroke(255); - point(cx + x, cy + y); - stroke(255, 150); - strokeWeight(1); - line(cx + x, 0, cx + x, height); + ellipse(cx, cy, d, d); + let x = r * cos(angle * (i + 1) - HALF_PI); + let y = r * sin(angle * (i + 1) - HALF_PI); + strokeWeight(8); + stroke(255); + point(cx + x, cy + y); + stroke(255, 150); + strokeWeight(1); + line(cx + x, 0, cx + x, height); - for (let j = 0; j < rows; j++) { - curves[j][i].setX(cx + x); - } + for (let j = 0; j < rows; j++) { + curves[j][i].setX(cx + x); } + } - noFill(); + noFill(); + stroke(255); + for (let j = 0; j < rows; j++) { + let cx = w / 2; + let cy = w + j * w + w / 2; + strokeWeight(1); stroke(255); - for (let j = 0; j < rows; j++) { - let cx = w / 2; - let cy = w + j * w + w / 2; - strokeWeight(1); - stroke(255); - ellipse(cx, cy, d, d); - let x = r * cos(angle * (j + 1) - HALF_PI); - let y = r * sin(angle * (j + 1) - HALF_PI); - strokeWeight(8); - stroke(255); - point(cx + x, cy + y); - stroke(255, 150); - strokeWeight(1); - line(0, cy + y, width, cy + y); + ellipse(cx, cy, d, d); + let x = r * cos(angle * (j + 1) - HALF_PI); + let y = r * sin(angle * (j + 1) - HALF_PI); + strokeWeight(8); + stroke(255); + point(cx + x, cy + y); + stroke(255, 150); + strokeWeight(1); + line(0, cy + y, width, cy + y); - for (let i = 0; i < cols; i++) { - curves[j][i].setY(cy + y); - } + for (let i = 0; i < cols; i++) { + curves[j][i].setY(cy + y); } + } - for (let j = 0; j < rows; j++) { - for (let i = 0; i < cols; i++) { - curves[j][i].addPoint(); - curves[j][i].show(); - } + for (let j = 0; j < rows; j++) { + for (let i = 0; i < cols; i++) { + curves[j][i].addPoint(); + curves[j][i].show(); } + } - angle -= 0.01; + angle -= 0.01; - if (angle < -TWO_PI) { - for (let j = 0; j < rows; j++) { - for (let i = 0; i < cols; i++) { - curves[j][i].reset(); - } - } - saveCanvas("lissajous.png"); - angle = 0; - noLoop(); + if (angle < -TWO_PI) { + for (let j = 0; j < rows; j++) { + for (let i = 0; i < cols; i++) { + curves[j][i].reset(); + } } -} \ No newline at end of file + saveCanvas('lissajous.png'); + angle = 0; + noLoop(); + } +} diff --git a/CodingChallenges/CC_118_Mastodon_TreeBot/Node/bot.js b/CodingChallenges/CC_118_Mastodon_TreeBot/Node/bot.js index e00929baad..7941bd06aa 100644 --- a/CodingChallenges/CC_118_Mastodon_TreeBot/Node/bot.js +++ b/CodingChallenges/CC_118_Mastodon_TreeBot/Node/bot.js @@ -6,22 +6,21 @@ // 1: https://youtu.be/luxczHFn1rU // 2: https://youtu.be/PUPWPjjkNqQ - require('dotenv').config(); const Mastodon = require('mastodon-api'); const util = require('util'); const fs = require('fs'); const exec = util.promisify(require('child_process').exec); -console.log("Mastodon Bot starting..."); +console.log('Mastodon Bot starting...'); const M = new Mastodon({ client_key: process.env.CLIENT_KEY, client_secret: process.env.CLIENT_SECRET, access_token: process.env.ACCESS_TOKEN, timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests. - api_url: 'https://botsin.space/api/v1/', // optional, defaults to https://mastodon.social/api/v1/ -}) + api_url: 'https://botsin.space/api/v1/' // optional, defaults to https://mastodon.social/api/v1/ +}); const cmd = 'processing-java --sketch=`pwd`/treegen --run'; @@ -37,17 +36,15 @@ stream.on('message', response => { const results = content.match(regex); let angle = -1; if (results) { - angle = results[0] + angle = results[0]; } toot(acct, id, angle) .then(response => console.log(response)) .catch(error => console.error(error)); } - }); - //tooter(); //setInterval(tooter, 24 * 60 * 60 * 1000); @@ -56,8 +53,8 @@ async function toot(acct, reply_id, angle) { const params = { status: `@${acct} Please specify an angle in degrees using digits`, in_reply_to_id: reply_id - } - const response = await M.post('statuses', params) + }; + const response = await M.post('statuses', params); return { success: true, angle: -1 @@ -72,7 +69,7 @@ async function toot(acct, reply_id, angle) { const params1 = { file: stream, description: `A randomly generated fractal tree with ${angle}` - } + }; const response2 = await M.post('media', params1); const id = response2.data.id; @@ -81,11 +78,11 @@ async function toot(acct, reply_id, angle) { status: `@${acct} Behold my beautiful tree with angle ${angle} degrees`, in_reply_to_id: reply_id, media_ids: [id] - } - const response3 = await M.post('statuses', params2) + }; + const response3 = await M.post('statuses', params2); return { success: true, angle: angle }; } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_119_Binary_to_Decimal_Conversion/P5/bit.js b/CodingChallenges/CC_119_Binary_to_Decimal_Conversion/P5/bit.js index a83bc5f568..67e9a8730d 100644 --- a/CodingChallenges/CC_119_Binary_to_Decimal_Conversion/P5/bit.js +++ b/CodingChallenges/CC_119_Binary_to_Decimal_Conversion/P5/bit.js @@ -5,7 +5,6 @@ // https://editor.p5js.org/codingtrain/sketches/HJn1hOPjX class Bit { - constructor(x, y, d) { this.x = x; this.y = y; @@ -24,7 +23,6 @@ class Bit { } } - show() { stroke(255); if (this.state) { @@ -34,7 +32,4 @@ class Bit { } ellipse(this.x, this.y, this.diameter); } - - - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_119_Binary_to_Decimal_Conversion/P5/sketch.js b/CodingChallenges/CC_119_Binary_to_Decimal_Conversion/P5/sketch.js index 6a30ca4e5e..c04e8c25a5 100644 --- a/CodingChallenges/CC_119_Binary_to_Decimal_Conversion/P5/sketch.js +++ b/CodingChallenges/CC_119_Binary_to_Decimal_Conversion/P5/sketch.js @@ -22,9 +22,6 @@ function setup() { byte[i] = new Bit(w / 2 + i * w, 50, w - 4); byte[i].setState(1); } - - - } function draw() { @@ -36,10 +33,6 @@ function draw() { } decimalP.html(binaryToDecimal(num)); - - - - } function binaryToDecimal(val) { @@ -49,4 +42,4 @@ function binaryToDecimal(val) { sum += parseInt(bit) * pow(2, i); } return sum; -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_120_Bit_Shifting/P5/bit.js b/CodingChallenges/CC_120_Bit_Shifting/P5/bit.js index ca5fa1f603..767360b450 100644 --- a/CodingChallenges/CC_120_Bit_Shifting/P5/bit.js +++ b/CodingChallenges/CC_120_Bit_Shifting/P5/bit.js @@ -9,7 +9,6 @@ // https://editor.p5js.org/codingtrain/sketches/Hk8CVYvi7 class Bit { - constructor(x, y, d) { this.x = x; this.y = y; @@ -28,12 +27,10 @@ class Bit { } } - show() { stroke(255); strokeWeight(2); fill(this.state ? 255 : 51); ellipse(this.x, this.y, this.diameter); } - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_120_Bit_Shifting/P5/sketch.js b/CodingChallenges/CC_120_Bit_Shifting/P5/sketch.js index c8ddbe6a17..4fc57c3411 100644 --- a/CodingChallenges/CC_120_Bit_Shifting/P5/sketch.js +++ b/CodingChallenges/CC_120_Bit_Shifting/P5/sketch.js @@ -24,7 +24,6 @@ function setup() { } } - function shiftBits() { let num = getBinaryString(); let val = binaryToDecimal(num); @@ -33,9 +32,6 @@ function shiftBits() { for (let i = 0; i < 8; i++) { byte[i].setState(num.charAt(i)); } - - - } function getBinaryString() { @@ -45,7 +41,6 @@ function getBinaryString() { num += byte[i].state ? '1' : '0'; } return num; - } function draw() { @@ -54,14 +49,12 @@ function draw() { decimalP.html(binaryToDecimal(num)); } - function mousePressed() { for (let i = 0; i < byte.length; i++) { byte[i].toggle(mouseX, mouseY); } } - function decimalToBinary(num) { let bits = ''; let rem = num; @@ -74,8 +67,6 @@ function decimalToBinary(num) { return bits; } - - function binaryToDecimal(val) { let sum = 0; for (let i = 0; i < val.length; i++) { @@ -83,4 +74,4 @@ function binaryToDecimal(val) { sum += parseInt(bit) * pow(2, i); } return sum; -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_121_Logo_1/P5/sketch.js b/CodingChallenges/CC_121_Logo_1/P5/sketch.js index 2bf942e184..47c597cfc3 100644 --- a/CodingChallenges/CC_121_Logo_1/P5/sketch.js +++ b/CodingChallenges/CC_121_Logo_1/P5/sketch.js @@ -6,7 +6,6 @@ // https://youtu.be/i-k04yzfMpw // https://editor.p5js.org/codingtrain/sketches/ryTuOf3gN - let editor; let turtle; @@ -39,4 +38,4 @@ function goTurtle() { index++; } pop(); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_121_Logo_1/P5/turtle.js b/CodingChallenges/CC_121_Logo_1/P5/turtle.js index cb1e356b4c..e1c423657e 100644 --- a/CodingChallenges/CC_121_Logo_1/P5/turtle.js +++ b/CodingChallenges/CC_121_Logo_1/P5/turtle.js @@ -7,22 +7,22 @@ // https://editor.p5js.org/codingtrain/sketches/ryTuOf3gN const commands = { - fd: function (amt) { + fd: function(amt) { turtle.forward(amt); }, - bd: function (amt) { + bd: function(amt) { turtle.forward(-amt); }, - rt: function (angle) { + rt: function(angle) { turtle.right(angle); }, - lt: function (angle) { + lt: function(angle) { turtle.right(-angle); }, - pu: function () { + pu: function() { turtle.pen = false; }, - pd: function () { + pd: function() { turtle.pen = true; } }; @@ -54,4 +54,4 @@ class Turtle { right(angle) { rotate(angle); } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_121_Logo_2/P5/command.js b/CodingChallenges/CC_121_Logo_2/P5/command.js index eb29389fc1..135e349822 100644 --- a/CodingChallenges/CC_121_Logo_2/P5/command.js +++ b/CodingChallenges/CC_121_Logo_2/P5/command.js @@ -10,4 +10,4 @@ class Command { this.arg = arg; this.commands = []; } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_121_Logo_2/P5/parser.js b/CodingChallenges/CC_121_Logo_2/P5/parser.js index 59a90f693e..03b7409bf4 100644 --- a/CodingChallenges/CC_121_Logo_2/P5/parser.js +++ b/CodingChallenges/CC_121_Logo_2/P5/parser.js @@ -15,7 +15,9 @@ class Parser { } getRepeat() { - while (this.text.charAt(this.index++) !== '[' && this.remainingTokens()) { /* empty */ } + while (this.text.charAt(this.index++) !== '[' && this.remainingTokens()) { + /* empty */ + } let start = this.index; let bracketCount = 1; @@ -78,6 +80,4 @@ class Parser { } return commands; } - - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_121_Logo_2/P5/sketch.js b/CodingChallenges/CC_121_Logo_2/P5/sketch.js index 9799c3ace4..dd051b7166 100644 --- a/CodingChallenges/CC_121_Logo_2/P5/sketch.js +++ b/CodingChallenges/CC_121_Logo_2/P5/sketch.js @@ -12,7 +12,7 @@ function setup() { angleMode(DEGREES); background(0); turtle = new Turtle(100, 100, 0); - editor = select("#code"); + editor = select('#code'); editor.input(goTurtle); goTurtle(); } @@ -21,7 +21,7 @@ function execute(commands) { for (let command of commands) { let name = command.name; let arg = command.arg; - if (name === "repeat") { + if (name === 'repeat') { for (let i = 0; i < arg; i++) { execute(command.commands); } @@ -41,4 +41,4 @@ function goTurtle() { console.log(commands); execute(commands); pop(); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_121_Logo_2/P5/turtle.js b/CodingChallenges/CC_121_Logo_2/P5/turtle.js index d66458833f..d13d2fbf97 100644 --- a/CodingChallenges/CC_121_Logo_2/P5/turtle.js +++ b/CodingChallenges/CC_121_Logo_2/P5/turtle.js @@ -5,25 +5,25 @@ // https://editor.p5js.org/codingtrain/sketches/BJqG8zhlN const commandLookUp = { - "fd": function (amt) { + fd: function(amt) { turtle.forward(amt); }, - "bd": function (amt) { + bd: function(amt) { turtle.forward(-amt); }, - "rt": function (angle) { + rt: function(angle) { turtle.right(angle); }, - "lt": function (angle) { + lt: function(angle) { turtle.right(-angle); }, - "pu": function () { + pu: function() { turtle.pen = false; }, - "pd": function () { + pd: function() { turtle.pen = true; } -} +}; class Turtle { constructor(x, y, angle) { @@ -52,6 +52,4 @@ class Turtle { right(angle) { rotate(angle); } - - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_122_QuickDraw_1/Node/public/sketch.js b/CodingChallenges/CC_122_QuickDraw_1/Node/public/sketch.js index b4bbcf572b..beb9e25ba8 100644 --- a/CodingChallenges/CC_122_QuickDraw_1/Node/public/sketch.js +++ b/CodingChallenges/CC_122_QuickDraw_1/Node/public/sketch.js @@ -20,7 +20,6 @@ function newCat() { loadJSON('/cat', gotCat); } - function draw() { if (cat) { let x = cat[strokeIndex][0][index]; @@ -53,4 +52,4 @@ function gotCat(data) { background(250); cat = data.drawing; console.log(cat); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_122_QuickDraw_1/Node/server.js b/CodingChallenges/CC_122_QuickDraw_1/Node/server.js index 3284f48b73..7282f2d42d 100644 --- a/CodingChallenges/CC_122_QuickDraw_1/Node/server.js +++ b/CodingChallenges/CC_122_QuickDraw_1/Node/server.js @@ -12,23 +12,23 @@ const ndjson = require('ndjson'); let rainbows = []; fs.createReadStream('rainbow.ndjson') .pipe(ndjson.parse()) - .on('data', function (obj) { + .on('data', function(obj) { rainbows.push(obj); - }) + }); let cats = []; fs.createReadStream('cat.ndjson') .pipe(ndjson.parse()) - .on('data', function (obj) { + .on('data', function(obj) { cats.push(obj); - }) + }); const express = require('express'); const app = express(); const port = 3000; app.listen(port, () => { - console.log(`Example app listening on port ${port}!`) + console.log(`Example app listening on port ${port}!`); }); app.get('/rainbow', (request, response) => { @@ -41,4 +41,4 @@ app.get('/cat', (request, response) => { response.send(cats[index]); }); -app.use(express.static('public')) \ No newline at end of file +app.use(express.static('public')); diff --git a/CodingChallenges/CC_122_QuickDraw_2/P5/sketch.js b/CodingChallenges/CC_122_QuickDraw_2/P5/sketch.js index 829d059439..a85f36d581 100644 --- a/CodingChallenges/CC_122_QuickDraw_2/P5/sketch.js +++ b/CodingChallenges/CC_122_QuickDraw_2/P5/sketch.js @@ -6,7 +6,8 @@ // Part 1: https://youtu.be/yLuk0twx8Hc // https://thecodingtrain.com/CodingChallenges/122.1-quick-draw -const url = 'https://quickdrawfiles.appspot.com/drawing/cat?isAnimated=false&format=json&key=' +const url = + 'https://quickdrawfiles.appspot.com/drawing/cat?isAnimated=false&format=json&key='; let strokeIndex = 0; let index = 0; @@ -29,7 +30,6 @@ function newCat() { loadJSON(url + apiKey, gotCat); } - function gotCat(data) { background(220); cat = data.drawing; diff --git a/CodingChallenges/CC_123_ChaosGame_1/P5/sketch.js b/CodingChallenges/CC_123_ChaosGame_1/P5/sketch.js index 97372cbd19..a4cf3f28e9 100644 --- a/CodingChallenges/CC_123_ChaosGame_1/P5/sketch.js +++ b/CodingChallenges/CC_123_ChaosGame_1/P5/sketch.js @@ -29,7 +29,6 @@ function setup() { } function draw() { - for (let i = 0; i < 100; i++) { strokeWeight(2); point(x, y); @@ -38,7 +37,6 @@ function draw() { stroke(255, 0, 255); x = lerp(x, ax, 0.5); y = lerp(y, ay, 0.5); - } else if (r == 1) { stroke(0, 255, 255); x = lerp(x, bx, 0.5); @@ -49,4 +47,4 @@ function draw() { y = lerp(y, cy, 0.5); } } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_123_ChaosGame_2/P5/sketch.js b/CodingChallenges/CC_123_ChaosGame_2/P5/sketch.js index db6bc4e672..2e43699434 100644 --- a/CodingChallenges/CC_123_ChaosGame_2/P5/sketch.js +++ b/CodingChallenges/CC_123_ChaosGame_2/P5/sketch.js @@ -17,7 +17,7 @@ function setup() { for (let i = 0; i < n; i++) { // let v = createVector(random(width), random(height)); - let angle = i * TWO_PI / n; + let angle = (i * TWO_PI) / n; let v = p5.Vector.fromAngle(angle); v.mult(width / 2); v.add(width / 2, height / 2); @@ -38,7 +38,6 @@ function reset() { } function draw() { - if (frameCount % 100 == 0) { //reset(); } @@ -54,4 +53,4 @@ function draw() { } previous = next; } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_124_Flocking_Boids/P5/boid.js b/CodingChallenges/CC_124_Flocking_Boids/P5/boid.js index ffd9b282db..47293ad589 100644 --- a/CodingChallenges/CC_124_Flocking_Boids/P5/boid.js +++ b/CodingChallenges/CC_124_Flocking_Boids/P5/boid.js @@ -32,7 +32,12 @@ class Boid { let steering = createVector(); let total = 0; for (let other of boids) { - let d = dist(this.position.x, this.position.y, other.position.x, other.position.y); + let d = dist( + this.position.x, + this.position.y, + other.position.x, + other.position.y + ); if (other != this && d < perceptionRadius) { steering.add(other.velocity); total++; @@ -52,7 +57,12 @@ class Boid { let steering = createVector(); let total = 0; for (let other of boids) { - let d = dist(this.position.x, this.position.y, other.position.x, other.position.y); + let d = dist( + this.position.x, + this.position.y, + other.position.x, + other.position.y + ); if (other != this && d < perceptionRadius) { let diff = p5.Vector.sub(this.position, other.position); diff.div(d * d); @@ -74,7 +84,12 @@ class Boid { let steering = createVector(); let total = 0; for (let other of boids) { - let d = dist(this.position.x, this.position.y, other.position.x, other.position.y); + let d = dist( + this.position.x, + this.position.y, + other.position.x, + other.position.y + ); if (other != this && d < perceptionRadius) { steering.add(other.position); total++; diff --git a/CodingChallenges/CC_125_Fourier_Series/P5/sketch.js b/CodingChallenges/CC_125_Fourier_Series/P5/sketch.js index e6cdc0dd8d..3dd7b1af3d 100644 --- a/CodingChallenges/CC_125_Fourier_Series/P5/sketch.js +++ b/CodingChallenges/CC_125_Fourier_Series/P5/sketch.js @@ -41,7 +41,6 @@ function draw() { } wave.unshift(y); - translate(200, 0); line(x - 200, y, 0, wave[0]); beginShape(); diff --git a/CodingChallenges/CC_126_Toothpicks/P5/sketch.js b/CodingChallenges/CC_126_Toothpicks/P5/sketch.js index 497e791479..2799c31c8c 100644 --- a/CodingChallenges/CC_126_Toothpicks/P5/sketch.js +++ b/CodingChallenges/CC_126_Toothpicks/P5/sketch.js @@ -45,4 +45,4 @@ function draw() { } picks = picks.concat(next); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_126_Toothpicks/P5/toothpick.js b/CodingChallenges/CC_126_Toothpicks/P5/toothpick.js index f31bc7cbd1..75839efad7 100644 --- a/CodingChallenges/CC_126_Toothpicks/P5/toothpick.js +++ b/CodingChallenges/CC_126_Toothpicks/P5/toothpick.js @@ -5,7 +5,6 @@ // https://editor.p5js.org/codingtrain/sketches/SJMl3u5xN class Toothpick { - constructor(x, y, d) { this.newPick = true; @@ -23,8 +22,7 @@ class Toothpick { } } - - intersects(x,y) { + intersects(x, y) { if (this.ax == x && this.ay == y) { return true; } else if (this.bx == x && this.by == y) { @@ -34,9 +32,7 @@ class Toothpick { } } - - - createA(others) { + createA(others) { let available = true; for (let other of others) { if (other != this && other.intersects(this.ax, this.ay)) { @@ -51,7 +47,7 @@ class Toothpick { } } - createB(others) { + createB(others) { let available = true; for (let other of others) { if (other != this && other.intersects(this.bx, this.by)) { diff --git a/CodingChallenges/CC_127_Snowflake_Brownian/P5/particle.js b/CodingChallenges/CC_127_Snowflake_Brownian/P5/particle.js index 0be59e3cb0..c578746a13 100644 --- a/CodingChallenges/CC_127_Snowflake_Brownian/P5/particle.js +++ b/CodingChallenges/CC_127_Snowflake_Brownian/P5/particle.js @@ -5,7 +5,6 @@ // https://editor.p5js.org/codingtrain/sketches/SJcAeCpgE class Particle { - constructor(radius, angle) { this.pos = p5.Vector.fromAngle(angle); this.pos.mult(radius); @@ -17,7 +16,7 @@ class Particle { this.pos.y += random(-3, 3); let angle = this.pos.heading(); - angle = constrain(angle, 0, PI/6); + angle = constrain(angle, 0, PI / 6); let magnitude = this.pos.mag(); this.pos = p5.Vector.fromAngle(angle); this.pos.setMag(magnitude); @@ -32,7 +31,7 @@ class Particle { intersects(snowflake) { let result = false; for (let s of snowflake) { - let d = dist(s.pos.x, s.pos.y, this.pos.x, this.pos.y); + let d = dist(s.pos.x, s.pos.y, this.pos.x, this.pos.y); if (d < this.r * 2) { result = true; break; @@ -42,6 +41,6 @@ class Particle { } finished() { - return (this.pos.x < 1); + return this.pos.x < 1; } } diff --git a/CodingChallenges/CC_127_Snowflake_Brownian/P5/sketch.js b/CodingChallenges/CC_127_Snowflake_Brownian/P5/sketch.js index 7c8076cabb..20ff74bd18 100644 --- a/CodingChallenges/CC_127_Snowflake_Brownian/P5/sketch.js +++ b/CodingChallenges/CC_127_Snowflake_Brownian/P5/sketch.js @@ -9,12 +9,12 @@ let snowflake = []; function setup() { createCanvas(600, 600); - current = new Particle(width/2, 0); + current = new Particle(width / 2, 0); } function draw() { - translate(width/2, height/2); - rotate(PI/6); + translate(width / 2, height / 2); + rotate(PI / 6); background(0); let count = 0; @@ -31,10 +31,10 @@ function draw() { } snowflake.push(current); - current = new Particle(width/2, 0); + current = new Particle(width / 2, 0); for (let i = 0; i < 6; i++) { - rotate(PI/3); + rotate(PI / 3); current.show(); for (let p of snowflake) { p.show(); diff --git a/CodingChallenges/CC_128_SketchRNN_Snowflakes/P5/sketch.js b/CodingChallenges/CC_128_SketchRNN_Snowflakes/P5/sketch.js index 4166c62eeb..44e324ccb0 100644 --- a/CodingChallenges/CC_128_SketchRNN_Snowflakes/P5/sketch.js +++ b/CodingChallenges/CC_128_SketchRNN_Snowflakes/P5/sketch.js @@ -13,12 +13,12 @@ let pen; function setup() { createCanvas(windowWidth, windowHeight); setupNewSketch(); - model = ml5.SketchRNN("snowflake", modelReady); + model = ml5.SketchRNN('snowflake', modelReady); background(0); } function modelReady() { - console.log("model ready"); + console.log('model ready'); model.reset(); model.generate(gotSketch); } @@ -28,7 +28,7 @@ function draw() { if (strokePath != null) { let newX = x + strokePath.dx * 0.2; let newY = y + strokePath.dy * 0.2; - if (pen == "down") { + if (pen == 'down') { stroke(255); strokeWeight(2); line(x, y, newX, newY); @@ -38,14 +38,14 @@ function draw() { x = newX; y = newY; - if (pen !== "end") { + if (pen !== 'end') { model.generate(gotSketch); } else { - console.log("drawing complete"); + console.log('drawing complete'); // In the video forgot to reset the pen to "down" // along with the x,y position so here is a new // function that takes care of both! - setupNewSketch(); + setupNewSketch(); model.reset(); model.generate(gotSketch); } @@ -62,7 +62,7 @@ function gotSketch(error, s) { } function setupNewSketch() { - pen = "down"; + pen = 'down'; x = random(-width / 2, width / 2); y = random(-height / 2, height / 2); } diff --git a/CodingChallenges/CC_129_Koch_Snowflake/P5/segment.js b/CodingChallenges/CC_129_Koch_Snowflake/P5/segment.js index 4efd0f22f9..8b54df45f4 100644 --- a/CodingChallenges/CC_129_Koch_Snowflake/P5/segment.js +++ b/CodingChallenges/CC_129_Koch_Snowflake/P5/segment.js @@ -5,28 +5,27 @@ // https://editor.p5js.org/codingtrain/sketches/SJHcVCAgN class Segment { - constructor(a, b) { this.a = a.copy(); this.b = b.copy(); } - - generate() { + + generate() { let children = []; - + let v = p5.Vector.sub(this.b, this.a); v.div(3); - + // Segment 0 let b1 = p5.Vector.add(this.a, v); children[0] = new Segment(this.a, b1); - + // Segment 3 let a1 = p5.Vector.sub(this.b, v); children[3] = new Segment(a1, this.b); - - v.rotate(-PI/3); - let c = p5.Vector.add(b1,v); + + v.rotate(-PI / 3); + let c = p5.Vector.add(b1, v); // Segment 2 children[1] = new Segment(b1, c); @@ -34,7 +33,7 @@ class Segment { children[2] = new Segment(c, a1); return children; } - + show() { stroke(255); line(this.a.x, this.a.y, this.b.x, this.b.y); diff --git a/CodingChallenges/CC_129_Koch_Snowflake/P5/sketch.js b/CodingChallenges/CC_129_Koch_Snowflake/P5/sketch.js index 008f97fdcc..97a5bcf54f 100644 --- a/CodingChallenges/CC_129_Koch_Snowflake/P5/sketch.js +++ b/CodingChallenges/CC_129_Koch_Snowflake/P5/sketch.js @@ -19,9 +19,9 @@ function setup() { let s1 = new Segment(a, b); let len = p5.Vector.dist(a, b); - let h = len * sqrt(3) / 2; - let c = createVector(300, 100+h); - + let h = (len * sqrt(3)) / 2; + let c = createVector(300, 100 + h); + let s2 = new Segment(b, c); let s3 = new Segment(c, a); segments.push(s1); @@ -41,7 +41,6 @@ function mousePressed() { segments = nextGeneration; } - function draw() { background(0); translate(0, 100); diff --git a/CodingChallenges/CC_130_Fourier_Transform_3/P5/sketch.js b/CodingChallenges/CC_130_Fourier_Transform_3/P5/sketch.js index 31e43f9c75..0383072144 100644 --- a/CodingChallenges/CC_130_Fourier_Transform_3/P5/sketch.js +++ b/CodingChallenges/CC_130_Fourier_Transform_3/P5/sketch.js @@ -62,4 +62,3 @@ function draw() { path = []; } } - diff --git a/CodingChallenges/CC_131_BouncingDVDLogo/P5/sketch.js b/CodingChallenges/CC_131_BouncingDVDLogo/P5/sketch.js index 8809ce04cb..b2998435a1 100644 --- a/CodingChallenges/CC_131_BouncingDVDLogo/P5/sketch.js +++ b/CodingChallenges/CC_131_BouncingDVDLogo/P5/sketch.js @@ -15,7 +15,7 @@ let dvd; let r, g, b; function preload() { - dvd = loadImage("dvd_logo.png"); + dvd = loadImage('dvd_logo.png'); } function setup() { @@ -31,7 +31,6 @@ function pickColor() { r = random(100, 256); g = random(100, 256); b = random(100, 256); - } function draw() { @@ -41,7 +40,6 @@ function draw() { tint(r, g, b); image(dvd, x, y); - x = x + xspeed; y = y + yspeed; diff --git a/CodingChallenges/CC_132_FluidSimulation/P5/fluid.js b/CodingChallenges/CC_132_FluidSimulation/P5/fluid.js index f7e25c5ba7..1b7d913311 100644 --- a/CodingChallenges/CC_132_FluidSimulation/P5/fluid.js +++ b/CodingChallenges/CC_132_FluidSimulation/P5/fluid.js @@ -5,96 +5,94 @@ let t = 0; // function to use 1D array and fake the extra two dimensions --> 3D function IX(x, y) { - return x + y*N; + return x + y * N; } // Fluid cube class class Fluid { - constructor(dt, diffusion, viscosity) { - this.size = N; - this.dt = dt; - this.diff = diffusion; - this.visc = viscosity; + constructor(dt, diffusion, viscosity) { + this.size = N; + this.dt = dt; + this.diff = diffusion; + this.visc = viscosity; - this.s = new Array(N*N).fill(0); - this.density = new Array(N*N).fill(0); + this.s = new Array(N * N).fill(0); + this.density = new Array(N * N).fill(0); - this.Vx = new Array(N*N).fill(0); - this.Vy = new Array(N*N).fill(0); + this.Vx = new Array(N * N).fill(0); + this.Vy = new Array(N * N).fill(0); - this.Vx0 = new Array(N*N).fill(0); - this.Vy0 = new Array(N*N).fill(0); - } + this.Vx0 = new Array(N * N).fill(0); + this.Vy0 = new Array(N * N).fill(0); + } - // step method - step() { - let N = this.size; - let visc = this.visc; - let diff = this.diff; - let dt = this.dt; - let Vx = this.Vx; - let Vy = this.Vy; - let Vx0 = this.Vx0; - let Vy0 = this.Vy0; - let s = this.s; - let density = this.density; + // step method + step() { + let N = this.size; + let visc = this.visc; + let diff = this.diff; + let dt = this.dt; + let Vx = this.Vx; + let Vy = this.Vy; + let Vx0 = this.Vx0; + let Vy0 = this.Vy0; + let s = this.s; + let density = this.density; + diffuse(1, Vx0, Vx, visc, dt); + diffuse(2, Vy0, Vy, visc, dt); - diffuse(1, Vx0, Vx, visc, dt); - diffuse(2, Vy0, Vy, visc, dt); + project(Vx0, Vy0, Vx, Vy); - project(Vx0, Vy0, Vx, Vy); + advect(1, Vx, Vx0, Vx0, Vy0, dt); + advect(2, Vy, Vy0, Vx0, Vy0, dt); - advect(1, Vx, Vx0, Vx0, Vy0, dt); - advect(2, Vy, Vy0, Vx0, Vy0, dt); + project(Vx, Vy, Vx0, Vy0); + diffuse(0, s, density, diff, dt); + advect(0, density, s, Vx, Vy, dt); + } - project(Vx, Vy, Vx0, Vy0); - diffuse(0, s, density, diff, dt); - advect(0, density, s, Vx, Vy, dt); - } + // method to add density + addDensity(x, y, amount) { + let index = IX(x, y); + this.density[index] += amount; + } - // method to add density - addDensity(x, y, amount) { - let index = IX(x, y); - this.density[index] += amount; - } + // method to add velocity + addVelocity(x, y, amountX, amountY) { + let index = IX(x, y); + this.Vx[index] += amountX; + this.Vy[index] += amountY; + } - // method to add velocity - addVelocity(x, y, amountX, amountY) { - let index = IX(x, y); - this.Vx[index] += amountX; - this.Vy[index] += amountY; + // function to render density + renderD() { + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + let x = i * SCALE; + let y = j * SCALE; + let d = this.density[IX(i, j)]; + fill(d); + noStroke(); + rect(x, y, SCALE, SCALE); + } } + } - // function to render density - renderD() { - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - let x = i * SCALE; - let y = j * SCALE; - let d = this.density[IX(i, j)]; - fill(d); - noStroke(); - rect(x, y, SCALE, SCALE); - } - } - } - - // function to render velocity - renderV() { - for (let i = 0; i < N; i++) { - for (let j = 0; j < N; j++) { - let x = i * SCALE; - let y = j * SCALE; - let vx = this.Vx[IX(i, j, k)]; - let vy = this.Vy[IX(i, j, k)]; - this.canvas.stroke(0); - - if (!(abs(vx) < 0.1 && abs(vy) <= 0.1)) { - line(x, y, x+vx*SCALE, y+vy*SCALE ); - } - } + // function to render velocity + renderV() { + for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + let x = i * SCALE; + let y = j * SCALE; + let vx = this.Vx[IX(i, j, k)]; + let vy = this.Vy[IX(i, j, k)]; + this.canvas.stroke(0); + + if (!(abs(vx) < 0.1 && abs(vy) <= 0.1)) { + line(x, y, x + vx * SCALE, y + vy * SCALE); } + } } + } } - diff --git a/CodingChallenges/CC_132_FluidSimulation/P5/fluid_utils.js b/CodingChallenges/CC_132_FluidSimulation/P5/fluid_utils.js index 4a238dcd6f..7988baf27c 100644 --- a/CodingChallenges/CC_132_FluidSimulation/P5/fluid_utils.js +++ b/CodingChallenges/CC_132_FluidSimulation/P5/fluid_utils.js @@ -7,11 +7,10 @@ - dt : flaot */ function diffuse(b, x, x0, diff, dt) { - let a = dt * diff * (N - 2) * (N - 2); - lin_solve(b, x, x0, a, 1 + 6 * a); + let a = dt * diff * (N - 2) * (N - 2); + lin_solve(b, x, x0, a, 1 + 6 * a); } - /* Function of solving linear differential equation - b : int @@ -21,20 +20,24 @@ function diffuse(b, x, x0, diff, dt) { - c : float */ function lin_solve(b, x, x0, a, c) { - let cRecip = 1.0 / c; - for (let t = 0; t < iter; t++) { - for (let j = 1; j < N - 1; j++) { - for (let i = 1; i < N - 1; i++) { - x[IX(i, j)] = (x0[IX(i, j)] - + a*(x[IX(i+1, j)] + x[IX(i-1, j)] - + x[IX(i, j+1)] + x[IX(i, j-1)])) * cRecip; - } - } - set_bnd(b, x); + let cRecip = 1.0 / c; + for (let t = 0; t < iter; t++) { + for (let j = 1; j < N - 1; j++) { + for (let i = 1; i < N - 1; i++) { + x[IX(i, j)] = + (x0[IX(i, j)] + + a * + (x[IX(i + 1, j)] + + x[IX(i - 1, j)] + + x[IX(i, j + 1)] + + x[IX(i, j - 1)])) * + cRecip; + } } + set_bnd(b, x); + } } - /* Function of project : This operation runs through all the cells and fixes them up so everything is in equilibrium. - velocX : float[] @@ -43,27 +46,32 @@ function lin_solve(b, x, x0, a, c) { - div : float[] */ function project(velocX, velocY, p, div) { - for (let j = 1; j < N - 1; j++) { - for (let i = 1; i < N - 1; i++) { - div[IX(i, j)] = -0.5*(velocX[IX(i+1, j)] - velocX[IX(i-1, j)] - + velocY[IX(i, j+1)] - velocY[IX(i, j-1)])/N; - p[IX(i, j)] = 0; - } + for (let j = 1; j < N - 1; j++) { + for (let i = 1; i < N - 1; i++) { + div[IX(i, j)] = + (-0.5 * + (velocX[IX(i + 1, j)] - + velocX[IX(i - 1, j)] + + velocY[IX(i, j + 1)] - + velocY[IX(i, j - 1)])) / + N; + p[IX(i, j)] = 0; } + } - set_bnd(0, div); - set_bnd(0, p); - lin_solve(0, p, div, 1, 6); + set_bnd(0, div); + set_bnd(0, p); + lin_solve(0, p, div, 1, 6); - for (let j = 1; j < N - 1; j++) { - for (let i = 1; i < N - 1; i++) { - velocX[IX(i, j)] -= 0.5 * ( p[IX(i+1, j)] - p[IX(i-1, j)]) * N; - velocY[IX(i, j)] -= 0.5 * ( p[IX(i, j+1)] - p[IX(i, j-1)]) * N; - } + for (let j = 1; j < N - 1; j++) { + for (let i = 1; i < N - 1; i++) { + velocX[IX(i, j)] -= 0.5 * (p[IX(i + 1, j)] - p[IX(i - 1, j)]) * N; + velocY[IX(i, j)] -= 0.5 * (p[IX(i, j + 1)] - p[IX(i, j - 1)]) * N; } - - set_bnd(1, velocX); - set_bnd(2, velocY); + } + + set_bnd(1, velocX); + set_bnd(2, velocY); } /* @@ -77,52 +85,51 @@ function project(velocX, velocY, p, div) { - dt : float[] */ function advect(b, d, d0, velocX, velocY, dt) { - let i0, i1, j0, j1; - - let dtx = dt * (N - 2); - let dty = dt * (N - 2); - - let s0, s1, t0, t1; - let tmp1, tmp2, tmp3, x, y; - - let Nfloat = N; - let ifloat, jfloat; - let i, j, k; - - - for (j = 1, jfloat = 1; j < N - 1; j++, jfloat++) { - for (i = 1, ifloat = 1; i < N - 1; i++, ifloat++) { - tmp1 = dtx * velocX[IX(i, j)]; - tmp2 = dty * velocY[IX(i, j)]; - x = ifloat - tmp1; - y = jfloat - tmp2; - - if (x < 0.5) x = 0.5; - if (x > Nfloat + 0.5) x = Nfloat + 0.5; - i0 = Math.floor(x); - i1 = i0 + 1.0; - if (y < 0.5) y = 0.5; - if (y > Nfloat + 0.5) y = Nfloat + 0.5; - j0 = Math.floor(y); - j1 = j0 + 1.0; - - s1 = x - i0; - s0 = 1.0 - s1; - t1 = y - j0; - t0 = 1.0 - t1; - - let i0i = parseInt(i0); - let i1i = parseInt(i1); - let j0i = parseInt(j0); - let j1i = parseInt(j1); - - d[IX(i, j)] = - s0 * (t0 * d0[IX(i0i, j0i)] + t1 * d0[IX(i0i, j1i)]) + - s1 * (t0 * d0[IX(i1i, j0i)] + t1 * d0[IX(i1i, j1i)]); - } + let i0, i1, j0, j1; + + let dtx = dt * (N - 2); + let dty = dt * (N - 2); + + let s0, s1, t0, t1; + let tmp1, tmp2, tmp3, x, y; + + let Nfloat = N; + let ifloat, jfloat; + let i, j, k; + + for (j = 1, jfloat = 1; j < N - 1; j++, jfloat++) { + for (i = 1, ifloat = 1; i < N - 1; i++, ifloat++) { + tmp1 = dtx * velocX[IX(i, j)]; + tmp2 = dty * velocY[IX(i, j)]; + x = ifloat - tmp1; + y = jfloat - tmp2; + + if (x < 0.5) x = 0.5; + if (x > Nfloat + 0.5) x = Nfloat + 0.5; + i0 = Math.floor(x); + i1 = i0 + 1.0; + if (y < 0.5) y = 0.5; + if (y > Nfloat + 0.5) y = Nfloat + 0.5; + j0 = Math.floor(y); + j1 = j0 + 1.0; + + s1 = x - i0; + s0 = 1.0 - s1; + t1 = y - j0; + t0 = 1.0 - t1; + + let i0i = parseInt(i0); + let i1i = parseInt(i1); + let j0i = parseInt(j0); + let j1i = parseInt(j1); + + d[IX(i, j)] = + s0 * (t0 * d0[IX(i0i, j0i)] + t1 * d0[IX(i0i, j1i)]) + + s1 * (t0 * d0[IX(i1i, j0i)] + t1 * d0[IX(i1i, j1i)]); } - - set_bnd(b, d); + } + + set_bnd(b, d); } /* @@ -131,17 +138,17 @@ function advect(b, d, d0, velocX, velocY, dt) { - x : float[] */ function set_bnd(b, x) { - for (let i = 1; i < N - 1; i++) { - x[IX(i, 0 )] = b == 2 ? -x[IX(i, 1 )] : x[IX(i, 1 )]; - x[IX(i, N-1)] = b == 2 ? -x[IX(i, N-2)] : x[IX(i, N-2)]; - } - for (let j = 1; j < N - 1; j++) { - x[IX(0, j)] = b == 1 ? -x[IX(1, j)] : x[IX(1, j)]; - x[IX(N-1, j)] = b == 1 ? -x[IX(N-2, j)] : x[IX(N-2, j)]; - } - - x[IX(0, 0)] = 0.5 * (x[IX(1, 0)] + x[IX(0, 1)]); - x[IX(0, N-1)] = 0.5 * (x[IX(1, N-1)] + x[IX(0, N-2)]); - x[IX(N-1, 0)] = 0.5 * (x[IX(N-2, 0)] + x[IX(N-1, 1)]); - x[IX(N-1, N-1)] = 0.5 * (x[IX(N-2, N-1)] + x[IX(N-1, N-2)]); + for (let i = 1; i < N - 1; i++) { + x[IX(i, 0)] = b == 2 ? -x[IX(i, 1)] : x[IX(i, 1)]; + x[IX(i, N - 1)] = b == 2 ? -x[IX(i, N - 2)] : x[IX(i, N - 2)]; + } + for (let j = 1; j < N - 1; j++) { + x[IX(0, j)] = b == 1 ? -x[IX(1, j)] : x[IX(1, j)]; + x[IX(N - 1, j)] = b == 1 ? -x[IX(N - 2, j)] : x[IX(N - 2, j)]; + } + + x[IX(0, 0)] = 0.5 * (x[IX(1, 0)] + x[IX(0, 1)]); + x[IX(0, N - 1)] = 0.5 * (x[IX(1, N - 1)] + x[IX(0, N - 2)]); + x[IX(N - 1, 0)] = 0.5 * (x[IX(N - 2, 0)] + x[IX(N - 1, 1)]); + x[IX(N - 1, N - 1)] = 0.5 * (x[IX(N - 2, N - 1)] + x[IX(N - 1, N - 2)]); } diff --git a/CodingChallenges/CC_132_FluidSimulation/P5/sketch.js b/CodingChallenges/CC_132_FluidSimulation/P5/sketch.js index c0344761b7..e8b9bf4b81 100644 --- a/CodingChallenges/CC_132_FluidSimulation/P5/sketch.js +++ b/CodingChallenges/CC_132_FluidSimulation/P5/sketch.js @@ -1,31 +1,31 @@ let fluid; function setup() { - createCanvas(300, 300); - frameRate(22); - fluid = new Fluid(0.2, 0, 0.0000001); + createCanvas(300, 300); + frameRate(22); + fluid = new Fluid(0.2, 0, 0.0000001); } function draw() { - stroke(51); - strokeWeight(2); + stroke(51); + strokeWeight(2); - let cx = int(0.5*width/SCALE); - let cy = int(0.5*height/SCALE); - for (let i = -1; i <= 1; i++) { - for (let j = -1; j <= 1; j++) { - fluid.addDensity(cx+i, cy+j, random(50, 150)); - } - } - - for (let i = 0; i < 2; i++) { - let angle = noise(t) * TWO_PI * 2; - let v = p5.Vector.fromAngle(angle); - v.mult(0.2); - t += 0.01; - fluid.addVelocity(cx, cy, v.x, v.y); + let cx = int((0.5 * width) / SCALE); + let cy = int((0.5 * height) / SCALE); + for (let i = -1; i <= 1; i++) { + for (let j = -1; j <= 1; j++) { + fluid.addDensity(cx + i, cy + j, random(50, 150)); } + } + + for (let i = 0; i < 2; i++) { + let angle = noise(t) * TWO_PI * 2; + let v = p5.Vector.fromAngle(angle); + v.mult(0.2); + t += 0.01; + fluid.addVelocity(cx, cy, v.x, v.y); + } - fluid.step(); - fluid.renderD(); -} \ No newline at end of file + fluid.step(); + fluid.renderD(); +} diff --git a/CodingChallenges/CC_133_Times_Tables_Cardioid/P5/sketch.js b/CodingChallenges/CC_133_Times_Tables_Cardioid/P5/sketch.js index 923d4c8af1..ff08f44030 100644 --- a/CodingChallenges/CC_133_Times_Tables_Cardioid/P5/sketch.js +++ b/CodingChallenges/CC_133_Times_Tables_Cardioid/P5/sketch.js @@ -36,4 +36,4 @@ function draw() { const b = getVector(i * factor, total); line(a.x, a.y, b.x, b.y); } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_134_Heart_Curve_1/P5/sketch.js b/CodingChallenges/CC_134_Heart_Curve_1/P5/sketch.js index 32268aeec0..e7ad87ac0b 100644 --- a/CodingChallenges/CC_134_Heart_Curve_1/P5/sketch.js +++ b/CodingChallenges/CC_134_Heart_Curve_1/P5/sketch.js @@ -11,7 +11,6 @@ function setup() { createCanvas(windowWidth, windowHeight); } - function draw() { background(0); translate(width / 2, height / 2); @@ -36,4 +35,4 @@ function draw() { } a += 0.1; -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_134_Heart_Curve_2/P5/sketch.js b/CodingChallenges/CC_134_Heart_Curve_2/P5/sketch.js index b88ebc1779..df123ce7e9 100644 --- a/CodingChallenges/CC_134_Heart_Curve_2/P5/sketch.js +++ b/CodingChallenges/CC_134_Heart_Curve_2/P5/sketch.js @@ -33,7 +33,6 @@ function render(percent) { } endShape(); - if (percent < 0.5) { const a = map(percent, 0, 0.5, 0, TWO_PI); const x = 16 * pow(sin(a), 3); @@ -42,5 +41,4 @@ function render(percent) { } else { heart.splice(0, 1); } - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_135_GIF_Loop/P5/sketch.js b/CodingChallenges/CC_135_GIF_Loop/P5/sketch.js index 0d57f29a16..9a611911e4 100644 --- a/CodingChallenges/CC_135_GIF_Loop/P5/sketch.js +++ b/CodingChallenges/CC_135_GIF_Loop/P5/sketch.js @@ -20,7 +20,7 @@ function draw() { } render(percent); if (record) { - save("output/gif-" + nf(counter, 3) + ".png"); + save('output/gif-' + nf(counter, 3) + '.png'); if (counter == totalFrames - 1) { noLoop(); } diff --git a/CodingChallenges/CC_136_Polar_Noise_Loop_1/P5/sketch.js b/CodingChallenges/CC_136_Polar_Noise_Loop_1/P5/sketch.js index 0ce356542b..0b5d693706 100644 --- a/CodingChallenges/CC_136_Polar_Noise_Loop_1/P5/sketch.js +++ b/CodingChallenges/CC_136_Polar_Noise_Loop_1/P5/sketch.js @@ -32,4 +32,4 @@ function draw() { endShape(CLOSE); phase += 0.003; zoff += 0.01; -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/noiseLoop.js b/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/noiseLoop.js index 3f5460a7ab..e1ff2e0466 100644 --- a/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/noiseLoop.js +++ b/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/noiseLoop.js @@ -13,4 +13,4 @@ class NoiseLoop { let r = noise(xoff, yoff); return map(r, 0, 1, this.min, this.max); } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/particle.js b/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/particle.js index 361a418631..34f54f9a93 100644 --- a/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/particle.js +++ b/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/particle.js @@ -17,4 +17,4 @@ class Particle { fill(r, 50, b, 200); ellipse(x, y, d); } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/sketch.js b/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/sketch.js index d4229d5990..00c402b73a 100644 --- a/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/sketch.js +++ b/CodingChallenges/CC_136_Polar_Noise_Loop_2/P5/sketch.js @@ -28,4 +28,4 @@ function render(percent) { for (let p of particles) { p.render(a); } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_137_4D_Noise_Loop/P5/sketch.js b/CodingChallenges/CC_137_4D_Noise_Loop/P5/sketch.js index f01c9a4dc5..6857d9373a 100644 --- a/CodingChallenges/CC_137_4D_Noise_Loop/P5/sketch.js +++ b/CodingChallenges/CC_137_4D_Noise_Loop/P5/sketch.js @@ -3,10 +3,10 @@ // https://thecodingtrain.com/CodingChallenges/137-4d-opensimplex-noise-loop // https://youtu.be/3_0Ax95jIrk -let capturer = new CCapture( { - format: 'png', - name: 'open_simplex_noise_loop', -} ); +let capturer = new CCapture({ + format: 'png', + name: 'open_simplex_noise_loop' +}); const totalFrames = 360; let counter = 0; @@ -30,12 +30,11 @@ function setup() { function draw() { let percent = float(counter % totalFrames) / totalFrames; render(percent); - if (record && counter 0 ? 255 : 0; stroke(bright); - point(x,y) + point(x, y); yoff += increment; } xoff += increment; diff --git a/CodingChallenges/CC_138_Angry_Birds/P5/bird.js b/CodingChallenges/CC_138_Angry_Birds/P5/bird.js index ea34a349e0..cd3899d9d5 100644 --- a/CodingChallenges/CC_138_Angry_Birds/P5/bird.js +++ b/CodingChallenges/CC_138_Angry_Birds/P5/bird.js @@ -5,13 +5,12 @@ // https://editor.p5js.org/codingtrain/sketches/LbNt1nyxE class Bird { - constructor(x, y, r) { const options = { restitution: 0.5 - } + }; this.body = Matter.Bodies.circle(x, y, r, options); - Matter.Body.setMass(this.body, this.body.mass*4); + Matter.Body.setMass(this.body, this.body.mass * 4); Matter.World.add(world, this.body); this.r = r; } @@ -25,6 +24,5 @@ class Bird { imageMode(CENTER); image(dotImg, 0, 0, this.r * 2, this.r * 2); pop(); - } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_138_Angry_Birds/P5/box.js b/CodingChallenges/CC_138_Angry_Birds/P5/box.js index caa1e1d39b..5c0f13f0ff 100644 --- a/CodingChallenges/CC_138_Angry_Birds/P5/box.js +++ b/CodingChallenges/CC_138_Angry_Birds/P5/box.js @@ -5,17 +5,16 @@ // https://editor.p5js.org/codingtrain/sketches/LbNt1nyxE class Box { - constructor(x, y, w, h) { const options = { restitution: 0.5 - } + }; this.body = Matter.Bodies.rectangle(x, y, w, h, options); Matter.World.add(world, this.body); this.w = w; this.h = h; } - + show() { const pos = this.body.position; const angle = this.body.angle; @@ -26,7 +25,6 @@ class Box { rectMode(CENTER); imageMode(CENTER); image(boxImg, 0, 0, this.w, this.h); - pop(); + pop(); } - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_138_Angry_Birds/P5/ground.js b/CodingChallenges/CC_138_Angry_Birds/P5/ground.js index 45d1d45050..d889fe6977 100644 --- a/CodingChallenges/CC_138_Angry_Birds/P5/ground.js +++ b/CodingChallenges/CC_138_Angry_Birds/P5/ground.js @@ -5,7 +5,6 @@ // https://editor.p5js.org/codingtrain/sketches/LbNt1nyxE class Ground extends Box { - constructor(x, y, w, h) { super(x, y, w, h); this.body.isStatic = true; @@ -23,5 +22,4 @@ class Ground extends Box { rect(0, 0, this.w, this.h); pop(); } - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_138_Angry_Birds/P5/sketch.js b/CodingChallenges/CC_138_Angry_Birds/P5/sketch.js index 6e56fe754c..86b572f08d 100644 --- a/CodingChallenges/CC_138_Angry_Birds/P5/sketch.js +++ b/CodingChallenges/CC_138_Angry_Birds/P5/sketch.js @@ -36,8 +36,8 @@ function setup() { const mouse = Mouse.create(canvas.elt); const options = { - mouse: mouse, - } + mouse: mouse + }; // A fix for HiDPI displays mouse.pixelRatio = pixelDensity(); @@ -51,7 +51,6 @@ function keyPressed() { bird = new Bird(150, 300, 25); slingshot.attach(bird.body); } - } function mouseReleased() { @@ -69,4 +68,4 @@ function draw() { } slingshot.show(); bird.show(); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_138_Angry_Birds/P5/slingshot.js b/CodingChallenges/CC_138_Angry_Birds/P5/slingshot.js index 96b563b5f3..9d2c09d338 100644 --- a/CodingChallenges/CC_138_Angry_Birds/P5/slingshot.js +++ b/CodingChallenges/CC_138_Angry_Birds/P5/slingshot.js @@ -6,7 +6,6 @@ class SlingShot { constructor(x, y, body) { - const options = { pointA: { x: x, @@ -15,13 +14,12 @@ class SlingShot { bodyB: body, stiffness: 0.02, length: 40 - } + }; this.sling = Constraint.create(options); World.add(world, this.sling); } fly() { - this.sling.bodyB = null; } @@ -34,10 +32,8 @@ class SlingShot { line(posA.x, posA.y, posB.x, posB.y); } } - + attach(body) { - this.sling.bodyB = body; + this.sling.bodyB = body; } - - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_139_Pi_Collisions/P5/block.js b/CodingChallenges/CC_139_Pi_Collisions/P5/block.js index 2121cea6b1..69fe0af303 100644 --- a/CodingChallenges/CC_139_Pi_Collisions/P5/block.js +++ b/CodingChallenges/CC_139_Pi_Collisions/P5/block.js @@ -15,7 +15,7 @@ class Block { } hitWall() { - return (this.x <= 0) + return this.x <= 0; } reverse() { @@ -23,14 +23,13 @@ class Block { } collide(other) { - return !(this.x + this.w < other.x || - this.x > other.x + other.w); + return !(this.x + this.w < other.x || this.x > other.x + other.w); } bounce(other) { let sumM = this.m + other.m; - let newV = (this.m - other.m) / sumM * this.v; - newV += (2 * other.m / sumM) * other.v; + let newV = ((this.m - other.m) / sumM) * this.v; + newV += ((2 * other.m) / sumM) * other.v; return newV; } @@ -39,8 +38,7 @@ class Block { } show() { - const x = constrain(this.x, this.xConstraint, width); image(blockImg, x, this.y, this.w, this.w); } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_139_Pi_Collisions/P5/sketch.js b/CodingChallenges/CC_139_Pi_Collisions/P5/sketch.js index a7ff7af244..c3daf481af 100644 --- a/CodingChallenges/CC_139_Pi_Collisions/P5/sketch.js +++ b/CodingChallenges/CC_139_Pi_Collisions/P5/sketch.js @@ -26,7 +26,6 @@ function setup() { block2 = new Block(300, 100, m2, -1 / timeSteps, 20); countDiv = createDiv(count); countDiv.style('font-size', '72pt'); - } function draw() { @@ -61,4 +60,4 @@ function draw() { block2.show(); countDiv.html(nf(count, digits)); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_140_Pi_Leibniz/P5/sketch.js b/CodingChallenges/CC_140_Pi_Leibniz/P5/sketch.js index 8c67d8d9bb..63f610a0a1 100644 --- a/CodingChallenges/CC_140_Pi_Leibniz/P5/sketch.js +++ b/CodingChallenges/CC_140_Pi_Leibniz/P5/sketch.js @@ -21,9 +21,9 @@ function draw() { background(0); let den = iterations * 2 + 3; if (iterations % 2 == 0) { - pi -= (4 / den); + pi -= 4 / den; } else { - pi += (4 / den); + pi += 4 / den; } history.push(pi); @@ -42,4 +42,4 @@ function draw() { endShape(); div.html(pi); iterations++; -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_143_QuickSort/P5/sketch.js b/CodingChallenges/CC_143_QuickSort/P5/sketch.js index 6d622e71ee..1a9ae819bd 100644 --- a/CodingChallenges/CC_143_QuickSort/P5/sketch.js +++ b/CodingChallenges/CC_143_QuickSort/P5/sketch.js @@ -84,4 +84,4 @@ async function swap(arr, a, b) { function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/blackhole.js b/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/blackhole.js index f8156adcf0..64d180a8a3 100644 --- a/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/blackhole.js +++ b/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/blackhole.js @@ -21,7 +21,7 @@ class Blackhole { pull(photon) { const force = p5.Vector.sub(this.pos, photon.pos); const r = force.mag(); - const fg = G * this.mass / (r * r); + const fg = (G * this.mass) / (r * r); force.setMag(fg); photon.vel.add(force); photon.vel.setMag(c); @@ -31,7 +31,6 @@ class Blackhole { } } - show() { ellipseMode(RADIUS); fill(0); @@ -47,10 +46,5 @@ class Blackhole { strokeWeight(32); ellipse(this.pos.x, this.pos.y, this.rs * 1.5 + 16); - - } - - - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/photon.js b/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/photon.js index 8726d5a6e0..d25eee4b25 100644 --- a/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/photon.js +++ b/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/photon.js @@ -12,7 +12,6 @@ // https://editor.p5js.org/codingtrain/sketches/4DvaeH0Ur class Photon { - constructor(x, y) { this.pos = createVector(x, y); this.vel = createVector(-c, 0); @@ -38,8 +37,6 @@ class Photon { if (this.history.length > 500) { this.history.splice(0, 1); } - - } show() { @@ -55,8 +52,5 @@ class Photon { } endShape(); - } - - -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/sketch.js b/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/sketch.js index c0764936b3..68fbcd70f8 100644 --- a/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/sketch.js +++ b/CodingChallenges/CC_144_Black_Hole_Newtonian/P5/sketch.js @@ -46,4 +46,4 @@ function draw() { p.show(); } m87.show(); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/sketch.js b/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/sketch.js index 8bc5774a5d..4e3a95ab4a 100644 --- a/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/sketch.js +++ b/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/sketch.js @@ -49,11 +49,10 @@ function keyPressed() { } function draw() { - if (random(1) < 0.005) { trains.push(new Train()); } - + background(bImg); for (let t of trains) { t.move(); @@ -66,4 +65,4 @@ function draw() { unicorn.show(); unicorn.move(); -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/train.js b/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/train.js index 95fef37b75..d7b2e3d2bf 100644 --- a/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/train.js +++ b/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/train.js @@ -6,23 +6,21 @@ // https://editor.p5js.org/codingtrain/sketches/v3thq2uhk class Train { + constructor() { + this.r = 75; + this.x = width; + this.y = height - this.r; + } - constructor() { - this.r = 75; - this.x = width; - this.y = height - this.r; - } - - move() { - this.x -= 16; - } - - show() { - image(tImg, this.x, this.y, this.r, this.r); - - // fill(255, 50); - // ellipseMode(CORNER); - // ellipse(this.x, this.y, this.r, this.r); - } - - } \ No newline at end of file + move() { + this.x -= 16; + } + + show() { + image(tImg, this.x, this.y, this.r, this.r); + + // fill(255, 50); + // ellipseMode(CORNER); + // ellipse(this.x, this.y, this.r, this.r); + } +} diff --git a/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/unicorn.js b/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/unicorn.js index 93ab094aff..bbff9369b4 100644 --- a/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/unicorn.js +++ b/CodingChallenges/CC_147_Chrome_Dinosaur_Game/P5/unicorn.js @@ -6,40 +6,39 @@ // https://editor.p5js.org/codingtrain/sketches/v3thq2uhk class Unicorn { - - constructor() { - this.r = 100; - this.x = 50; - this.y = height - this.r; - this.vy = 0; - this.gravity = 3; - } - - jump() { - if (this.y == height - this.r) { - this.vy = -35; - } - } - - hits(train) { - let x1 = this.x + this.r * 0.5; - let y1 = this.y + this.r * 0.5; - let x2 = train.x + train.r * 0.5; - let y2 = train.y + train.r * 0.5; - return collideCircleCircle(x1, y1, this.r, x2, y2, train.r); - } - - move() { - this.y += this.vy; - this.vy += this.gravity; - this.y = constrain(this.y, 0, height - this.r); - } - - show() { - image(uImg, this.x, this.y, this.r, this.r); - - // fill(255, 50); - // ellipseMode(CORNER); - // ellipse(this.x, this.y, this.r, this.r); + constructor() { + this.r = 100; + this.x = 50; + this.y = height - this.r; + this.vy = 0; + this.gravity = 3; + } + + jump() { + if (this.y == height - this.r) { + this.vy = -35; } - } \ No newline at end of file + } + + hits(train) { + let x1 = this.x + this.r * 0.5; + let y1 = this.y + this.r * 0.5; + let x2 = train.x + train.r * 0.5; + let y2 = train.y + train.r * 0.5; + return collideCircleCircle(x1, y1, this.r, x2, y2, train.r); + } + + move() { + this.y += this.vy; + this.vy += this.gravity; + this.y = constrain(this.y, 0, height - this.r); + } + + show() { + image(uImg, this.x, this.y, this.r, this.r); + + // fill(255, 50); + // ellipseMode(CORNER); + // ellipse(this.x, this.y, this.r, this.r); + } +} diff --git a/CodingChallenges/CC_148_Gift_Wrapping/P5/sketch.js b/CodingChallenges/CC_148_Gift_Wrapping/P5/sketch.js index ae5b110531..4dea687315 100644 --- a/CodingChallenges/CC_148_Gift_Wrapping/P5/sketch.js +++ b/CodingChallenges/CC_148_Gift_Wrapping/P5/sketch.js @@ -18,7 +18,12 @@ function setup() { createCanvas(500, 500); let buffer = 20; for (let i = 0; i < 50; i++) { - points.push(createVector(random(buffer, width - buffer), random(buffer, height - buffer))); + points.push( + createVector( + random(buffer, width - buffer), + random(buffer, height - buffer) + ) + ); } points.sort((a, b) => a.x - b.x); leftMost = points[0]; diff --git a/CodingChallenges/CC_149_Tic_Tac_Toe/P5/sketch.js b/CodingChallenges/CC_149_Tic_Tac_Toe/P5/sketch.js index 5b636b7c95..2d63b6f789 100644 --- a/CodingChallenges/CC_149_Tic_Tac_Toe/P5/sketch.js +++ b/CodingChallenges/CC_149_Tic_Tac_Toe/P5/sketch.js @@ -6,7 +6,7 @@ let board = [ ['', '', ''], ['', '', ''], - ['', '', ''], + ['', '', ''] ]; let players = ['X', 'O']; @@ -26,7 +26,7 @@ function setup() { } function equals3(a, b, c) { - return (a == b && b == c && a != ''); + return a == b && b == c && a != ''; } function checkWinner() { @@ -59,7 +59,6 @@ function checkWinner() { } else { return winner; } - } function nextTurn() { @@ -100,7 +99,6 @@ function draw() { line(x - r, y - r, x + r, y + r); line(x + r, y - r, x - r, y + r); } - } } @@ -110,7 +108,7 @@ function draw() { let resultP = createP(''); resultP.style('font-size', '32pt'); if (result == 'tie') { - resultP.html("Tie!") + resultP.html('Tie!'); } else { resultP.html(`${result} wins!`); } diff --git a/CodingChallenges/CC_150_Ai_Rainbows_Runway/P5/sketch.js b/CodingChallenges/CC_150_Ai_Rainbows_Runway/P5/sketch.js index aa3a86d0e9..a43c5c9aaa 100644 --- a/CodingChallenges/CC_150_Ai_Rainbows_Runway/P5/sketch.js +++ b/CodingChallenges/CC_150_Ai_Rainbows_Runway/P5/sketch.js @@ -12,7 +12,7 @@ let rainbow; function setup() { createCanvas(400, 400); - createButton("rainbow").mousePressed(generateRainbow); + createButton('rainbow').mousePressed(generateRainbow); } function generateRainbow() { @@ -21,12 +21,12 @@ function generateRainbow() { for (let i = 0; i < 512; i++) { z[i] = random(-1, 1); } - const path = "http://localhost:8000/query"; + const path = 'http://localhost:8000/query'; const data = { z: z, truncation: 0.8 }; - httpPost(path, "json", data, gotImage, gotError); + httpPost(path, 'json', data, gotImage, gotError); } function gotError(error) { diff --git a/CodingChallenges/CC_151_Ukulele_Tuner/P5/sketch.js b/CodingChallenges/CC_151_Ukulele_Tuner/P5/sketch.js index 75b3d5cca6..88594de398 100644 --- a/CodingChallenges/CC_151_Ukulele_Tuner/P5/sketch.js +++ b/CodingChallenges/CC_151_Ukulele_Tuner/P5/sketch.js @@ -1,31 +1,32 @@ - // Daniel Shiffman // https://thecodingtrain.com/CodingChallenges/151-ukulele-tuner.html // https://youtu.be/F1OkDTUkKFo // https://editor.p5js.org/codingtrain/sketches/8io2zvT03 -const model_url = 'https://cdn.jsdelivr.net/gh/ml5js/ml5-data-and-models/models/pitch-detection/crepe/'; +const model_url = + 'https://cdn.jsdelivr.net/gh/ml5js/ml5-data-and-models/models/pitch-detection/crepe/'; let pitch; let mic; let freq = 0; let threshold = 1; -let notes = [{ - note: 'A', - freq: 440 -}, -{ - note: 'E', - freq: 329.6276 -}, -{ - note: 'C', - freq: 261.6256 -}, -{ - note: 'G', - freq: 391.9954 -} +let notes = [ + { + note: 'A', + freq: 440 + }, + { + note: 'E', + freq: 329.6276 + }, + { + note: 'C', + freq: 261.6256 + }, + { + note: 'G', + freq: 391.9954 + } ]; function setup() { @@ -37,12 +38,7 @@ function setup() { function listening() { console.log('listening'); - pitch = ml5.pitchDetection( - model_url, - audioContext, - mic.stream, - modelLoaded - ); + pitch = ml5.pitchDetection(model_url, audioContext, mic.stream, modelLoaded); } function draw() { @@ -52,7 +48,6 @@ function draw() { textSize(32); text(freq.toFixed(2), width / 2, height - 150); - let closestNote = -1; let recordDiff = Infinity; for (let i = 0; i < notes.length; i++) { @@ -66,7 +61,6 @@ function draw() { textSize(64); text(closestNote.note, width / 2, height - 50); - let diff = recordDiff; // let amt = map(diff, -100, 100, 0, 1); // let r = color(255, 0, 0); @@ -93,8 +87,6 @@ function draw() { fill(0, 255, 0); } rect(200 + diff / 2, 100, 10, 75); - - } function modelLoaded() { @@ -112,4 +104,4 @@ function gotPitch(error, frequency) { } pitch.getPitch(gotPitch); } -} \ No newline at end of file +} diff --git a/CodingChallenges/CC_152_RDP_Algorithm/P5/sketch.js b/CodingChallenges/CC_152_RDP_Algorithm/P5/sketch.js index 82e5e277c0..2b7fd27cb8 100644 --- a/CodingChallenges/CC_152_RDP_Algorithm/P5/sketch.js +++ b/CodingChallenges/CC_152_RDP_Algorithm/P5/sketch.js @@ -29,7 +29,6 @@ function rdp(startIndex, endIndex, allPoints, rdpPoints) { } } - function findFurthest(points, a, b) { let recordDistance = -1; const start = points[a]; @@ -50,7 +49,6 @@ function findFurthest(points, a, b) { } } - function lineDist(c, a, b) { const norm = scalarProjection(c, a, b); return p5.Vector.dist(c, norm); @@ -65,7 +63,6 @@ function scalarProjection(p, a, b) { return normalPoint; } - function draw() { background(0); @@ -105,6 +102,6 @@ function draw() { fill(255); noStroke(); textSize(24); - text("epsilon: " + nf(epsilon, 2, 2), 20, 25); - text("n: " + rdpPoints.length, 20, 50); -} \ No newline at end of file + text('epsilon: ' + nf(epsilon, 2, 2), 20, 25); + text('n: ' + rdpPoints.length, 20, 50); +} diff --git a/CodingChallenges/CC_153_Interactive_SketchRRN/P5/sketch.js b/CodingChallenges/CC_153_Interactive_SketchRRN/P5/sketch.js index 2422c8abde..b7637f1be9 100644 --- a/CodingChallenges/CC_153_Interactive_SketchRRN/P5/sketch.js +++ b/CodingChallenges/CC_153_Interactive_SketchRRN/P5/sketch.js @@ -6,13 +6,13 @@ let sketchRNN; let currentStroke; let x, y; -let nextPen = "down"; +let nextPen = 'down'; let seedPath = []; let seedPoints = []; let personDrawing = false; function preload() { - sketchRNN = ml5.sketchRNN("catpig"); + sketchRNN = ml5.sketchRNN('catpig'); } function startDrawing() { @@ -53,7 +53,7 @@ function sketchRNNStart() { let strokePath = { dx: rdpPoints[i].x - rdpPoints[i - 1].x, dy: rdpPoints[i].y - rdpPoints[i - 1].y, - pen: "down" + pen: 'down' }; seedPath.push(strokePath); } @@ -67,7 +67,7 @@ function setup() { canvas.mouseReleased(sketchRNNStart); background(255); //sketchRNN.generate(gotStrokePath); - console.log("model loaded"); + console.log('model loaded'); } function gotStrokePath(error, strokePath) { @@ -86,15 +86,15 @@ function draw() { } if (currentStroke) { - if (nextPen == "end") { + if (nextPen == 'end') { sketchRNN.reset(); sketchRNNStart(); currentStroke = null; - nextPen = "down"; + nextPen = 'down'; return; } - if (nextPen == "down") { + if (nextPen == 'down') { line(x, y, x + currentStroke.dx, y + currentStroke.dy); } x += currentStroke.dx; diff --git a/CodingChallenges/CC_154_Tic_Tac_Toe_Minimax/P5/minimax.js b/CodingChallenges/CC_154_Tic_Tac_Toe_Minimax/P5/minimax.js index 34a9500c95..0594eaf377 100644 --- a/CodingChallenges/CC_154_Tic_Tac_Toe_Minimax/P5/minimax.js +++ b/CodingChallenges/CC_154_Tic_Tac_Toe_Minimax/P5/minimax.js @@ -11,10 +11,10 @@ function bestMove() { for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { // Is the spot available? - if (board[i][j] == "") { + if (board[i][j] == '') { board[i][j] = ai; let score = minimax(board, 0, false); - board[i][j] = ""; + board[i][j] = ''; if (score > bestScore) { bestScore = score; move = { i, j }; @@ -43,10 +43,10 @@ function minimax(board, depth, isMaximizing) { for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { // Is the spot available? - if (board[i][j] == "") { + if (board[i][j] == '') { board[i][j] = ai; let score = minimax(board, depth + 1, false); - board[i][j] = ""; + board[i][j] = ''; bestScore = max(score, bestScore); } } @@ -57,10 +57,10 @@ function minimax(board, depth, isMaximizing) { for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { // Is the spot available? - if (board[i][j] == "") { + if (board[i][j] == '') { board[i][j] = human; let score = minimax(board, depth + 1, true); - board[i][j] = ""; + board[i][j] = ''; bestScore = min(score, bestScore); } } diff --git a/CodingChallenges/CC_154_Tic_Tac_Toe_Minimax/P5/sketch.js b/CodingChallenges/CC_154_Tic_Tac_Toe_Minimax/P5/sketch.js index ce27393cb2..42afc7291c 100644 --- a/CodingChallenges/CC_154_Tic_Tac_Toe_Minimax/P5/sketch.js +++ b/CodingChallenges/CC_154_Tic_Tac_Toe_Minimax/P5/sketch.js @@ -5,16 +5,16 @@ // https://editor.p5js.org/codingtrain/sketches/0zyUhZdJD let board = [ - ["", "", ""], - ["", "", ""], - ["", "", ""] + ['', '', ''], + ['', '', ''], + ['', '', ''] ]; let w; // = width / 3; let h; // = height / 3; -let ai = "X"; -let human = "O"; +let ai = 'X'; +let human = 'O'; let currentPlayer = human; function setup() { @@ -25,7 +25,7 @@ function setup() { } function equals3(a, b, c) { - return a == b && b == c && a != ""; + return a == b && b == c && a != ''; } function checkWinner() { @@ -56,14 +56,14 @@ function checkWinner() { let openSpots = 0; for (let i = 0; i < 3; i++) { for (let j = 0; j < 3; j++) { - if (board[i][j] == "") { + if (board[i][j] == '') { openSpots++; } } } if (winner == null && openSpots == 0) { - return "tie"; + return 'tie'; } else { return winner; } @@ -75,7 +75,7 @@ function mousePressed() { let i = floor(mouseX / w); let j = floor(mouseY / h); // If valid turn - if (board[i][j] == "") { + if (board[i][j] == '') { board[i][j] = human; currentPlayer = ai; bestMove(); @@ -112,10 +112,10 @@ function draw() { let result = checkWinner(); if (result != null) { noLoop(); - let resultP = createP(""); - resultP.style("font-size", "32pt"); - if (result == "tie") { - resultP.html("Tie!"); + let resultP = createP(''); + resultP.style('font-size', '32pt'); + if (result == 'tie') { + resultP.html('Tie!'); } else { resultP.html(`${result} wins!`); } diff --git a/CodingInTheCabana/Cabana_001_Maurer_Rose/P5/sketch.js b/CodingInTheCabana/Cabana_001_Maurer_Rose/P5/sketch.js index eaae1c0de0..1299f3dc28 100644 --- a/CodingInTheCabana/Cabana_001_Maurer_Rose/P5/sketch.js +++ b/CodingInTheCabana/Cabana_001_Maurer_Rose/P5/sketch.js @@ -46,7 +46,4 @@ function draw() { n += 0.001; d += 0.003; - - - -} \ No newline at end of file +} diff --git a/CodingInTheCabana/Cabana_002_Collatz_Conjecture/P5/sketch.js b/CodingInTheCabana/Cabana_002_Collatz_Conjecture/P5/sketch.js index 98e15c8cbb..5767cb5ed0 100644 --- a/CodingInTheCabana/Cabana_002_Collatz_Conjecture/P5/sketch.js +++ b/CodingInTheCabana/Cabana_002_Collatz_Conjecture/P5/sketch.js @@ -4,7 +4,6 @@ // https://youtu.be/EYLWxwo1Ed8 // https://editor.p5js.org/codingtrain/sketches/XjLDE7gu6 - function setup() { createCanvas(800, 600); background(0); @@ -37,7 +36,6 @@ function setup() { } } - function collatz(n) { // even if (n % 2 == 0) { diff --git a/Courses/beginner_ml5/04_feature_extractor_classification/P5/sketch.js b/Courses/beginner_ml5/04_feature_extractor_classification/P5/sketch.js index 8a973836fc..c63f0dd52e 100755 --- a/Courses/beginner_ml5/04_feature_extractor_classification/P5/sketch.js +++ b/Courses/beginner_ml5/04_feature_extractor_classification/P5/sketch.js @@ -30,7 +30,6 @@ function whileTraining(loss) { } } - function gotResults(error, result) { if (error) { console.error(error); @@ -62,8 +61,6 @@ function setup() { trainButton.mousePressed(function() { classifier.train(whileTraining); }); - - } function draw() { diff --git a/Courses/beginner_ml5/05_feature_extractor_regression/P5/sketch.js b/Courses/beginner_ml5/05_feature_extractor_regression/P5/sketch.js index ac17fdd146..bf6d632620 100755 --- a/Courses/beginner_ml5/05_feature_extractor_regression/P5/sketch.js +++ b/Courses/beginner_ml5/05_feature_extractor_regression/P5/sketch.js @@ -30,7 +30,6 @@ function whileTraining(loss) { } } - function gotResults(error, result) { if (error) { console.error(error); @@ -55,13 +54,10 @@ function setup() { predictor.addImage(slider.value()); }); - trainButton = createButton('train'); trainButton.mousePressed(function() { predictor.train(whileTraining); }); - - } function draw() { diff --git a/Courses/beginner_ml5/06_feature_extractor_load_save/P5/sketch.js b/Courses/beginner_ml5/06_feature_extractor_load_save/P5/sketch.js index 27ac2523e5..4a32633a0d 100755 --- a/Courses/beginner_ml5/06_feature_extractor_load_save/P5/sketch.js +++ b/Courses/beginner_ml5/06_feature_extractor_load_save/P5/sketch.js @@ -13,7 +13,6 @@ let happyButton; let sadButton; let trainButton; - function modelReady() { console.log('Model is ready!!!'); // classifier.load('model.json', customModelReady); @@ -38,22 +37,22 @@ function setup() { classifier = mobilenet.classification(video, videoReady); happyButton = createButton('happy'); - happyButton.mousePressed(function () { + happyButton.mousePressed(function() { classifier.addImage('happy'); }); sadButton = createButton('sad'); - sadButton.mousePressed(function () { + sadButton.mousePressed(function() { classifier.addImage('sad'); }); trainButton = createButton('train'); - trainButton.mousePressed(function () { + trainButton.mousePressed(function() { classifier.train(whileTraining); }); saveButton = createButton('save'); - saveButton.mousePressed(function () { + saveButton.mousePressed(function() { classifier.save(); }); } @@ -66,7 +65,6 @@ function draw() { text(label, 10, height - 10); } - function whileTraining(loss) { if (loss == null) { console.log('Training Complete'); @@ -76,7 +74,6 @@ function whileTraining(loss) { } } - function gotResults(error, result) { if (error) { console.error(error); diff --git a/Courses/beginner_ml5/07_knn_classifier/P5/sketch.js b/Courses/beginner_ml5/07_knn_classifier/P5/sketch.js index f8f95f64dd..372ab696c4 100644 --- a/Courses/beginner_ml5/07_knn_classifier/P5/sketch.js +++ b/Courses/beginner_ml5/07_knn_classifier/P5/sketch.js @@ -3,10 +3,9 @@ // http://codingtra.in // KNN Classification with Feature Extractor -// 1: https://youtu.be/KTNqXwkLuM4 -// 2: https://youtu.be/Mwo5_bUVhlA -// 3: https://youtu.be/JWsKay58Z2g - +// 1: https://youtu.be/KTNqXwkLuM4 +// 2: https://youtu.be/Mwo5_bUVhlA +// 3: https://youtu.be/JWsKay58Z2g let video; let features; diff --git a/Courses/beginner_ml5/6.1_train_your_own/P5/sketch.js b/Courses/beginner_ml5/6.1_train_your_own/P5/sketch.js index e1a5c89be6..07f67794d7 100644 --- a/Courses/beginner_ml5/6.1_train_your_own/P5/sketch.js +++ b/Courses/beginner_ml5/6.1_train_your_own/P5/sketch.js @@ -5,10 +5,10 @@ // https://editor.p5js.org/codingtrain/sketches/zwGahux8a let model; -let targetLabel = "C"; +let targetLabel = 'C'; // let trainingData = []; -let state = "collection"; +let state = 'collection'; let notes = { C: 261.6256, @@ -27,25 +27,25 @@ function setup() { wave = new p5.Oscillator(); - wave.setType("sine"); + wave.setType('sine'); wave.start(); wave.freq(440); wave.amp(env); let options = { - inputs: ["x", "y"], - outputs: ["label"], - task: "classification", - debug: "true" + inputs: ['x', 'y'], + outputs: ['label'], + task: 'classification', + debug: 'true' }; model = ml5.neuralNetwork(options); background(255); } function keyPressed() { - if (key == "t") { - state = "training"; - console.log("starting training"); + if (key == 't') { + state = 'training'; + console.log('starting training'); model.normalizeData(); let options = { epochs: 200 @@ -61,8 +61,8 @@ function whileTraining(epoch, loss) { } function finishedTraining() { - console.log("finished training."); - state = "prediction"; + console.log('finished training.'); + state = 'prediction'; } function mousePressed() { @@ -71,7 +71,7 @@ function mousePressed() { y: mouseY }; - if (state == "collection") { + if (state == 'collection') { let target = { label: targetLabel }; @@ -86,7 +86,7 @@ function mousePressed() { wave.freq(notes[targetLabel]); env.play(); - } else if (state == "prediction") { + } else if (state == 'prediction') { model.classify(inputs, gotResults); } } diff --git a/Courses/beginner_ml5/6.2_save_data/P5/sketch.js b/Courses/beginner_ml5/6.2_save_data/P5/sketch.js index 3058a0c36d..a3e90b36fe 100644 --- a/Courses/beginner_ml5/6.2_save_data/P5/sketch.js +++ b/Courses/beginner_ml5/6.2_save_data/P5/sketch.js @@ -5,9 +5,9 @@ // https://editor.p5js.org/codingtrain/sketches/4fxtImOMz let model; -let targetLabel = "C"; +let targetLabel = 'C'; -let state = "collection"; +let state = 'collection'; let notes = { C: 261.6256, @@ -30,20 +30,20 @@ function setup() { wave = new p5.Oscillator(); - wave.setType("sine"); + wave.setType('sine'); wave.start(); wave.freq(440); wave.amp(env); let options = { - inputs: ["x", "y"], - outputs: ["label"], - task: "classification", - debug: "true", + inputs: ['x', 'y'], + outputs: ['label'], + task: 'classification', + debug: 'true', learningRate: 0.5 }; model = ml5.neuralNetwork(options); - model.loadData("mouse-notes.json", dataLoaded); + model.loadData('mouse-notes.json', dataLoaded); background(255); } @@ -63,8 +63,8 @@ function dataLoaded() { textAlign(CENTER, CENTER); text(target.label, inputs.x, inputs.y); } - state = "training"; - console.log("starting training"); + state = 'training'; + console.log('starting training'); model.normalizeData(); let options = { epochs: 200 @@ -73,16 +73,16 @@ function dataLoaded() { } function keyPressed() { - if (key == "t") { - state = "training"; - console.log("starting training"); + if (key == 't') { + state = 'training'; + console.log('starting training'); model.normalizeData(); let options = { epochs: 200 }; model.train(options, whileTraining, finishedTraining); - } else if (key == "s") { - model.saveData("mouse-notes"); + } else if (key == 's') { + model.saveData('mouse-notes'); } else { targetLabel = key.toUpperCase(); } @@ -93,8 +93,8 @@ function whileTraining(epoch, loss) { } function finishedTraining() { - console.log("finished training."); - state = "prediction"; + console.log('finished training.'); + state = 'prediction'; } function mousePressed() { @@ -103,7 +103,7 @@ function mousePressed() { y: mouseY }; - if (state == "collection") { + if (state == 'collection') { let target = { label: targetLabel }; @@ -118,7 +118,7 @@ function mousePressed() { wave.freq(notes[targetLabel]); env.play(); - } else if (state == "prediction") { + } else if (state == 'prediction') { model.classify(inputs, gotResults); } } diff --git a/Courses/beginner_ml5/6.3_save_model/P5/sketch.js b/Courses/beginner_ml5/6.3_save_model/P5/sketch.js index e37e6ca573..36a137aed6 100644 --- a/Courses/beginner_ml5/6.3_save_model/P5/sketch.js +++ b/Courses/beginner_ml5/6.3_save_model/P5/sketch.js @@ -5,9 +5,9 @@ // https://editor.p5js.org/codingtrain/sketches/RxDbDKGiG let model; -let targetLabel = "C"; +let targetLabel = 'C'; -let state = "collection"; +let state = 'collection'; let notes = { C: 261.6256, @@ -30,24 +30,24 @@ function setup() { wave = new p5.Oscillator(); - wave.setType("sine"); + wave.setType('sine'); wave.start(); wave.freq(440); wave.amp(env); let options = { - inputs: ["x", "y"], - outputs: ["label"], - task: "classification", - debug: "true", + inputs: ['x', 'y'], + outputs: ['label'], + task: 'classification', + debug: 'true', learningRate: 0.5 }; model = ml5.neuralNetwork(options); - model.loadData("mouse-notes.json", dataLoaded); + model.loadData('mouse-notes.json', dataLoaded); const modelInfo = { - model: "model/model.json", - metadata: "model/model_meta.json", - weights: "model/model.weights.bin" + model: 'model/model.json', + metadata: 'model/model_meta.json', + weights: 'model/model.weights.bin' }; model.load(modelInfo, modelLoaded); @@ -56,8 +56,8 @@ function setup() { } function modelLoaded() { - console.log("model loaded"); - state = "prediction"; + console.log('model loaded'); + state = 'prediction'; } function dataLoaded() { @@ -85,17 +85,17 @@ function dataLoaded() { } function keyPressed() { - if (key == "t") { - state = "training"; - console.log("starting training"); + if (key == 't') { + state = 'training'; + console.log('starting training'); model.normalizeData(); let options = { epochs: 200 }; model.train(options, whileTraining, finishedTraining); - } else if (key == "s") { - model.saveData("mouse-notes"); - } else if (key == "m") { + } else if (key == 's') { + model.saveData('mouse-notes'); + } else if (key == 'm') { model.save(); } else { targetLabel = key.toUpperCase(); @@ -107,8 +107,8 @@ function whileTraining(epoch, loss) { } function finishedTraining() { - console.log("finished training."); - state = "prediction"; + console.log('finished training.'); + state = 'prediction'; } function mousePressed() { @@ -117,7 +117,7 @@ function mousePressed() { y: mouseY }; - if (state == "collection") { + if (state == 'collection') { let target = { label: targetLabel }; @@ -132,7 +132,7 @@ function mousePressed() { wave.freq(notes[targetLabel]); env.play(); - } else if (state == "prediction") { + } else if (state == 'prediction') { model.classify(inputs, gotResults); } } diff --git a/Courses/beginner_ml5/6.4_regression/P5/sketch.js b/Courses/beginner_ml5/6.4_regression/P5/sketch.js index cb35b1232d..a8a9fd4e59 100644 --- a/Courses/beginner_ml5/6.4_regression/P5/sketch.js +++ b/Courses/beginner_ml5/6.4_regression/P5/sketch.js @@ -5,9 +5,9 @@ // https://editor.p5js.org/codingtrain/sketches/aw7R9aSkh let model; -let targetLabel = "C"; +let targetLabel = 'C'; -let state = "collection"; +let state = 'collection'; let notes = { C: 261.6256, @@ -30,16 +30,16 @@ function setup() { wave = new p5.Oscillator(); - wave.setType("sine"); + wave.setType('sine'); wave.start(); wave.freq(440); wave.amp(env); let options = { - inputs: ["x", "y"], - outputs: ["frequency"], - task: "regression", - debug: "true" + inputs: ['x', 'y'], + outputs: ['frequency'], + task: 'regression', + debug: 'true' }; model = ml5.neuralNetwork(options); @@ -56,8 +56,8 @@ function setup() { } function modelLoaded() { - console.log("model loaded"); - state = "prediction"; + console.log('model loaded'); + state = 'prediction'; } function dataLoaded() { @@ -86,17 +86,17 @@ function dataLoaded() { } function keyPressed() { - if (key == "t") { - state = "training"; - console.log("starting training"); + if (key == 't') { + state = 'training'; + console.log('starting training'); model.normalizeData(); let options = { epochs: 50 }; model.train(options, whileTraining, finishedTraining); - } else if (key == "s") { - model.saveData("mouse-notes"); - } else if (key == "m") { + } else if (key == 's') { + model.saveData('mouse-notes'); + } else if (key == 'm') { model.save(); } else { targetLabel = key.toUpperCase(); @@ -108,8 +108,8 @@ function whileTraining(epoch, loss) { } function finishedTraining() { - console.log("finished training."); - state = "prediction"; + console.log('finished training.'); + state = 'prediction'; } function mousePressed() { @@ -118,7 +118,7 @@ function mousePressed() { y: mouseY }; - if (state == "collection") { + if (state == 'collection') { let targetFrequency = notes[targetLabel]; let target = { frequency: targetFrequency @@ -134,7 +134,7 @@ function mousePressed() { wave.freq(targetFrequency); env.play(); - } else if (state == "prediction") { + } else if (state == 'prediction') { model.predict(inputs, gotResults); } } diff --git a/Courses/intelligence_learning/session3/linear_regression_gradient_descent/sketch.js b/Courses/intelligence_learning/session3/linear_regression_gradient_descent/sketch.js index 1622db9e36..3b2fe19143 100644 --- a/Courses/intelligence_learning/session3/linear_regression_gradient_descent/sketch.js +++ b/Courses/intelligence_learning/session3/linear_regression_gradient_descent/sketch.js @@ -17,9 +17,6 @@ function gradientDescent() { m = m + error * x * learning_rate; b = b + error * learning_rate; } - - - } function drawLine() { @@ -36,11 +33,8 @@ function drawLine() { stroke(255); strokeWeight(2); line(x1, y1, x2, y2); - - } - function mousePressed() { var x = map(mouseX, 0, width, 0, 1); var y = map(mouseY, 0, height, 1, 0); @@ -62,5 +56,4 @@ function draw() { gradientDescent(); drawLine(); } - } diff --git a/Courses/intelligence_learning/session3/linear_regression_ordinary_least_squares/sketch.js b/Courses/intelligence_learning/session3/linear_regression_ordinary_least_squares/sketch.js index bf20fdc9ac..04585fa1da 100644 --- a/Courses/intelligence_learning/session3/linear_regression_ordinary_least_squares/sketch.js +++ b/Courses/intelligence_learning/session3/linear_regression_ordinary_least_squares/sketch.js @@ -43,11 +43,8 @@ function drawLine() { stroke(255); strokeWeight(2); line(x1, y1, x2, y2); - - } - function mousePressed() { var x = map(mouseX, 0, width, 0, 1); var y = map(mouseY, 0, height, 1, 0); @@ -69,5 +66,4 @@ function draw() { linearRegression(); drawLine(); } - } diff --git a/Courses/intelligence_learning/session4/toy-neural-network-js/examples/xor/sketch.js b/Courses/intelligence_learning/session4/toy-neural-network-js/examples/xor/sketch.js index 944e048ce8..5d962f007c 100644 --- a/Courses/intelligence_learning/session4/toy-neural-network-js/examples/xor/sketch.js +++ b/Courses/intelligence_learning/session4/toy-neural-network-js/examples/xor/sketch.js @@ -1,17 +1,22 @@ let nn; -let training_data = [{ - inputs: [0, 0], - targets: [0] -}, { - inputs: [1, 0], - targets: [1] -}, { - inputs: [0, 1], - targets: [1] -}, { - inputs: [1, 1], - targets: [0] -}]; +let training_data = [ + { + inputs: [0, 0], + targets: [0] + }, + { + inputs: [1, 0], + targets: [1] + }, + { + inputs: [0, 1], + targets: [1] + }, + { + inputs: [1, 1], + targets: [0] + } +]; let lr_slider; @@ -48,7 +53,4 @@ function draw() { rect(x, y, resolution, resolution); } } - - - } diff --git a/Courses/intelligence_learning/session6/6_5_6_tf_layers/sketch.js b/Courses/intelligence_learning/session6/6_5_6_tf_layers/sketch.js index 219ffcc6eb..d2b502bf1f 100755 --- a/Courses/intelligence_learning/session6/6_5_6_tf_layers/sketch.js +++ b/Courses/intelligence_learning/session6/6_5_6_tf_layers/sketch.js @@ -35,19 +35,13 @@ model.compile({ loss: tf.losses.meanSquaredError }); - const xs = tf.tensor2d([ [0, 0], [0.5, 0.5], [1, 1] ]); -const ys = tf.tensor2d([ - [1], - [0.5], - [0] -]); - +const ys = tf.tensor2d([[1], [0.5], [0]]); train().then(() => { let outputs = model.predict(xs); @@ -60,13 +54,12 @@ async function train() { const config = { shuffle: true, epochs: 10 - } + }; const response = await model.fit(xs, ys, config); console.log(response.history.loss[0]); } } - // const xs = tf.tensor2d([ // [0.25, 0.92], // [0.12, 0.3], diff --git a/Courses/intelligence_learning/session7/07_01_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_01_color_classifier/sketch.js index c8e861497d..18f6287590 100644 --- a/Courses/intelligence_learning/session7/07_01_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_01_color_classifier/sketch.js @@ -26,9 +26,6 @@ function setup() { let submit = createButton('submit'); submit.mousePressed(sendData); - - - } function sendData() { diff --git a/Courses/intelligence_learning/session7/07_02_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_02_color_classifier/sketch.js index 1a7a73d7e2..0c68fd36e8 100644 --- a/Courses/intelligence_learning/session7/07_02_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_02_color_classifier/sketch.js @@ -25,12 +25,12 @@ function pickColor() { function setup() { // Initialize Firebase var config = { - apiKey: "AIzaSyDPekCKX4ee6h9NVR2lEITGAM0XIHn-c7c", - authDomain: "color-classification.firebaseapp.com", - databaseURL: "https://color-classification.firebaseio.com", - projectId: "color-classification", - storageBucket: "", - messagingSenderId: "590040209608" + apiKey: 'AIzaSyDPekCKX4ee6h9NVR2lEITGAM0XIHn-c7c', + authDomain: 'color-classification.firebaseapp.com', + databaseURL: 'https://color-classification.firebaseio.com', + projectId: 'color-classification', + storageBucket: '', + messagingSenderId: '590040209608' }; firebase.initializeApp(config); database = firebase.database(); @@ -38,7 +38,6 @@ function setup() { createCanvas(100, 100); pickColor(); - let buttons = []; buttons.push(createButton('red-ish')); buttons.push(createButton('green-ish')); @@ -53,10 +52,6 @@ function setup() { for (let i = 0; i < buttons.length; i++) { buttons[i].mousePressed(sendData); } - - - - } function sendData() { @@ -70,17 +65,17 @@ function sendData() { g: g, b: b, label: this.html() - } + }; console.log('saving data'); console.log(data); let color = colorDatabase.push(data, finished); - console.log("Firebase generated key: " + color.key); + console.log('Firebase generated key: ' + color.key); // Reload the data for the page function finished(err) { if (err) { - console.error("ooops, something went wrong."); + console.error('ooops, something went wrong.'); console.error(err); } else { console.log('Data saved successfully'); diff --git a/Courses/intelligence_learning/session7/07_03_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_03_color_classifier/sketch.js index c99f991231..a35b3e9385 100644 --- a/Courses/intelligence_learning/session7/07_03_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_03_color_classifier/sketch.js @@ -15,12 +15,12 @@ function setup() { // Initialize Firebase var config = { - apiKey: "AIzaSyDPekCKX4ee6h9NVR2lEITGAM0XIHn-c7c", - authDomain: "color-classification.firebaseapp.com", - databaseURL: "https://color-classification.firebaseio.com", - projectId: "color-classification", - storageBucket: "", - messagingSenderId: "590040209608" + apiKey: 'AIzaSyDPekCKX4ee6h9NVR2lEITGAM0XIHn-c7c', + authDomain: 'color-classification.firebaseapp.com', + databaseURL: 'https://color-classification.firebaseio.com', + projectId: 'color-classification', + storageBucket: '', + messagingSenderId: '590040209608' }; firebase.initializeApp(config); database = firebase.database(); @@ -50,14 +50,13 @@ function gotData(results) { } } - users.sort((a,b) => { + users.sort((a, b) => { return uid_bycount[a] - uid_bycount[b]; - }) + }); for (let id of users) { console.log(`${id} ${uid_bycount[id]}`); } //console.log(uid_bycount) - } diff --git a/Courses/intelligence_learning/session7/07_04_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_04_color_classifier/sketch.js index 0cbbf1c2a8..d978803ab1 100644 --- a/Courses/intelligence_learning/session7/07_04_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_04_color_classifier/sketch.js @@ -26,24 +26,22 @@ let colorByLabel = { 'purple-ish': [], 'brown-ish': [], 'orange-ish': [], - 'yellow-ish': [], -} + 'yellow-ish': [] +}; let label = 'grey-ish'; - function setup() { createCanvas(400, 400); - // Initialize Firebase var config = { - apiKey: "AIzaSyDPekCKX4ee6h9NVR2lEITGAM0XIHn-c7c", - authDomain: "color-classification.firebaseapp.com", - databaseURL: "https://color-classification.firebaseio.com", - projectId: "color-classification", - storageBucket: "", - messagingSenderId: "590040209608" + apiKey: 'AIzaSyDPekCKX4ee6h9NVR2lEITGAM0XIHn-c7c', + authDomain: 'color-classification.firebaseapp.com', + databaseURL: 'https://color-classification.firebaseio.com', + projectId: 'color-classification', + storageBucket: '', + messagingSenderId: '590040209608' }; firebase.initializeApp(config); database = firebase.database(); @@ -51,8 +49,6 @@ function setup() { ref.once('value', gotData); //, errorData); } - - function gotData(results) { let data = results.val(); @@ -67,14 +63,14 @@ function gotData(results) { //let col = color(record.r, record.g, record.b); colorByLabel[record.label].push(record); - - if(record.uid == 'YGdqOTDDmrbGm80gM5UHicxMBgS2') { + if (record.uid == 'YGdqOTDDmrbGm80gM5UHicxMBgS2') { userData.push(record); } } // Visualizing Data by User - userData.sort((a,b) => {a.label > b.label + userData.sort((a, b) => { + a.label > b.label; if (a.label > b.label) { return 1; } else { @@ -83,17 +79,15 @@ function gotData(results) { }); let title = createDiv(`Data Entered by ${userData[0].uid}`); - title.style('padding-top','50px'); + title.style('padding-top', '50px'); for (let entry of userData) { let div = createDiv(entry.label); let colorBox = createDiv(''); colorBox.parent(div); - colorBox.size(10,10); - colorBox.style('background-color',`rgb(${entry.r},${entry.g},${entry.b})`) + colorBox.size(10, 10); + colorBox.style('background-color', `rgb(${entry.r},${entry.g},${entry.b})`); } - - // Visualizing Data by Color Label let blues = colorByLabel[label]; let x = 0; @@ -101,7 +95,7 @@ function gotData(results) { for (let i = 0; i < blues.length; i++) { noStroke(); fill(blues[i].r, blues[i].g, blues[i].b); - rect(x,y,10,10); + rect(x, y, 10, 10); x += 10; if (x >= width) { x = 0; @@ -145,5 +139,4 @@ function gotData(results) { // } //console.log(uid_bycount) - } diff --git a/Courses/intelligence_learning/session7/07_05_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_05_color_classifier/sketch.js index 48e07e2a4e..ee23b92e5c 100755 --- a/Courses/intelligence_learning/session7/07_05_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_05_color_classifier/sketch.js @@ -13,21 +13,21 @@ // https://github.com/CodingTrain/ColorClassifer-TensorFlow.js let filter = { - 'YGdqOTDDmrbGm80gM5UHicxMBgS2': true, - 'HUXmyv1dSSUnIvYk976MPWUSaTG2': true, - 'hPdk0Qpo0Gb5NsWSgxsqPM7M2EA2': true + YGdqOTDDmrbGm80gM5UHicxMBgS2: true, + HUXmyv1dSSUnIvYk976MPWUSaTG2: true, + hPdk0Qpo0Gb5NsWSgxsqPM7M2EA2: true }; function setup() { noCanvas(); // Initialize Firebase var config = { - apiKey: "AIzaSyDPekCKX4ee6h9NVR2lEITGAM0XIHn-c7c", - authDomain: "color-classification.firebaseapp.com", - databaseURL: "https://color-classification.firebaseio.com", - projectId: "color-classification", - storageBucket: "", - messagingSenderId: "590040209608" + apiKey: 'AIzaSyDPekCKX4ee6h9NVR2lEITGAM0XIHn-c7c', + authDomain: 'color-classification.firebaseapp.com', + databaseURL: 'https://color-classification.firebaseio.com', + projectId: 'color-classification', + storageBucket: '', + messagingSenderId: '590040209608' }; firebase.initializeApp(config); database = firebase.database(); @@ -35,7 +35,6 @@ function setup() { ref.once('value', gotData); //, errorData); } - function gotData(results) { let data = results.val(); diff --git a/Courses/intelligence_learning/session7/07_06_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_06_color_classifier/sketch.js index 69bd878a1c..1bab2356ad 100755 --- a/Courses/intelligence_learning/session7/07_06_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_06_color_classifier/sketch.js @@ -18,7 +18,6 @@ function preload() { data = loadJSON('colorData.json'); } - function setup() { //console.log(data.entries.length); @@ -32,5 +31,4 @@ function setup() { let xs = tf.tensor2d(colors); console.log(xs.shape); xs.print(); - } diff --git a/Courses/intelligence_learning/session7/07_07_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_07_color_classifier/sketch.js index 467847def4..10bae616e2 100755 --- a/Courses/intelligence_learning/session7/07_07_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_07_color_classifier/sketch.js @@ -24,13 +24,12 @@ let labelList = [ 'purple-ish', 'brown-ish', 'grey-ish' -] +]; function preload() { data = loadJSON('colorData.json'); } - function setup() { //console.log(data.entries.length); @@ -59,5 +58,4 @@ function setup() { ys.print(); //console.log(labels); - } diff --git a/Courses/intelligence_learning/session7/07_08_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_08_color_classifier/sketch.js index 0f3fd6a07c..2133c417d5 100755 --- a/Courses/intelligence_learning/session7/07_08_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_08_color_classifier/sketch.js @@ -26,13 +26,12 @@ let labelList = [ 'purple-ish', 'brown-ish', 'grey-ish' -] +]; function preload() { data = loadJSON('colorData.json'); } - function setup() { //console.log(data.entries.length); @@ -60,7 +59,6 @@ function setup() { xs.print(); ys.print(); - // Building Model model = tf.sequential(); @@ -77,7 +75,6 @@ function setup() { model.add(hidden); model.add(output); - // The Next Steps: // Create an optimizer @@ -86,6 +83,4 @@ function setup() { // Compile the model // Train the model - - } diff --git a/Courses/intelligence_learning/session7/07_09_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_09_color_classifier/sketch.js index cfb3a0a8a4..fa874ee688 100755 --- a/Courses/intelligence_learning/session7/07_09_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_09_color_classifier/sketch.js @@ -26,13 +26,12 @@ let labelList = [ 'purple-ish', 'brown-ish', 'grey-ish' -] +]; function preload() { data = loadJSON('colorData.json'); } - function setup() { //console.log(data.entries.length); @@ -60,7 +59,6 @@ function setup() { xs.print(); ys.print(); - // Building Model model = tf.sequential(); @@ -89,5 +87,4 @@ function setup() { // Next Step: // Train the model // model.fit - } diff --git a/Courses/intelligence_learning/session7/07_10_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_10_color_classifier/sketch.js index e0877f7ff3..aa9c4b9e34 100755 --- a/Courses/intelligence_learning/session7/07_10_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_10_color_classifier/sketch.js @@ -26,13 +26,12 @@ let labelList = [ 'purple-ish', 'brown-ish', 'grey-ish' -] +]; function preload() { data = loadJSON('colorData.json'); } - function setup() { //console.log(data.entries.length); @@ -60,7 +59,6 @@ function setup() { // xs.print(); // ys.print(); - // Building Model model = tf.sequential(); @@ -91,12 +89,11 @@ function setup() { epochs: 50, validationSplit: 0.1, shuffle: true - } + }; model.fit(xs, ys, options).then(results => { - console.log(results.history.loss) + console.log(results.history.loss); }); - } function draw() { diff --git a/Courses/intelligence_learning/session7/07_11_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_11_color_classifier/sketch.js index bde5b6cca8..16e2e45672 100755 --- a/Courses/intelligence_learning/session7/07_11_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_11_color_classifier/sketch.js @@ -29,13 +29,12 @@ let labelList = [ 'purple-ish', 'brown-ish', 'grey-ish' -] +]; function preload() { data = loadJSON('colorData.json'); } - function setup() { lossP = createP('Loss'); //console.log(data.entries.length); @@ -64,7 +63,6 @@ function setup() { // xs.print(); // ys.print(); - // Building Model model = tf.sequential(); @@ -93,7 +91,6 @@ function setup() { train().then(results => { console.log(results.history.loss); }); - } // Training Function @@ -105,8 +102,8 @@ async function train() { callbacks: { onTrainBegin: () => console.log('training start'), onTrainEnd: () => console.log('training complete'), - onBatchEnd: async(num, logs) => { - await tf.nextFrame(); + onBatchEnd: async (num, logs) => { + await tf.nextFrame(); }, onEpochEnd: (num, logs) => { console.log('Epoch: ' + num); @@ -114,7 +111,7 @@ async function train() { // console.log('Loss: ' + logs.loss); } } - } + }; return await model.fit(xs, ys, options); } @@ -123,5 +120,5 @@ function draw() { background(0); stroke(255); strokeWeight(4); - line(frameCount % width, 0, frameCount % width, height) + line(frameCount % width, 0, frameCount % width, height); } diff --git a/Courses/intelligence_learning/session7/07_12_color_classifier/sketch.js b/Courses/intelligence_learning/session7/07_12_color_classifier/sketch.js index 248feb2478..25c78b8655 100755 --- a/Courses/intelligence_learning/session7/07_12_color_classifier/sketch.js +++ b/Courses/intelligence_learning/session7/07_12_color_classifier/sketch.js @@ -29,7 +29,7 @@ let labelList = [ 'purple-ish', 'brown-ish', 'grey-ish' -] +]; function preload() { data = loadJSON('colorData.json'); @@ -76,7 +76,7 @@ function setup() { model.compile({ optimizer: optimizer, loss: 'categoricalCrossentropy', - metrics: ['accuracy'], + metrics: ['accuracy'] }); train(); @@ -97,9 +97,9 @@ async function train() { await tf.nextFrame(); }, onTrainEnd: () => { - console.log('finished') - }, - }, + console.log('finished'); + } + } }); } @@ -112,9 +112,7 @@ function draw() { stroke(255); line(frameCount % width, 0, frameCount % width, height); tf.tidy(() => { - const input = tf.tensor2d([ - [r, g, b] - ]); + const input = tf.tensor2d([[r, g, b]]); let results = model.predict(input); let argMax = results.argMax(1); let index = argMax.dataSync()[0]; diff --git a/Courses/natureofcode/10.18-toy_neural_network/examples/xor/sketch.js b/Courses/natureofcode/10.18-toy_neural_network/examples/xor/sketch.js index 944e048ce8..5d962f007c 100644 --- a/Courses/natureofcode/10.18-toy_neural_network/examples/xor/sketch.js +++ b/Courses/natureofcode/10.18-toy_neural_network/examples/xor/sketch.js @@ -1,17 +1,22 @@ let nn; -let training_data = [{ - inputs: [0, 0], - targets: [0] -}, { - inputs: [1, 0], - targets: [1] -}, { - inputs: [0, 1], - targets: [1] -}, { - inputs: [1, 1], - targets: [0] -}]; +let training_data = [ + { + inputs: [0, 0], + targets: [0] + }, + { + inputs: [1, 0], + targets: [1] + }, + { + inputs: [0, 1], + targets: [1] + }, + { + inputs: [1, 1], + targets: [0] + } +]; let lr_slider; @@ -48,7 +53,4 @@ function draw() { rect(x, y, resolution, resolution); } } - - - } diff --git a/Courses/natureofcode/11.3_neuroevolution_tfjs.js/nn.js b/Courses/natureofcode/11.3_neuroevolution_tfjs.js/nn.js index 189b116083..9298469a0c 100644 --- a/Courses/natureofcode/11.3_neuroevolution_tfjs.js/nn.js +++ b/Courses/natureofcode/11.3_neuroevolution_tfjs.js/nn.js @@ -27,7 +27,12 @@ class NeuralNetwork { weightCopies[i] = weights[i].clone(); } modelCopy.setWeights(weightCopies); - return new NeuralNetwork(modelCopy, this.input_nodes, this.hidden_nodes, this.output_nodes); + return new NeuralNetwork( + modelCopy, + this.input_nodes, + this.hidden_nodes, + this.output_nodes + ); }); } diff --git a/Courses/natureofcode/5.17_matter_intro/box.js b/Courses/natureofcode/5.17_matter_intro/box.js index b367e3bf05..f912432fdf 100644 --- a/Courses/natureofcode/5.17_matter_intro/box.js +++ b/Courses/natureofcode/5.17_matter_intro/box.js @@ -7,7 +7,7 @@ function Box(x, y, w, h) { var options = { friction: 0.3, restitution: 0.6 - } + }; this.body = Bodies.rectangle(x, y, w, h, options); this.w = w; this.h = h; @@ -25,6 +25,5 @@ function Box(x, y, w, h) { fill(127); rect(0, 0, this.w, this.h); pop(); - } - + }; } diff --git a/Courses/natureofcode/5.17_matter_intro/sketch.js b/Courses/natureofcode/5.17_matter_intro/sketch.js index 361aedb96e..91caa69422 100644 --- a/Courses/natureofcode/5.17_matter_intro/sketch.js +++ b/Courses/natureofcode/5.17_matter_intro/sketch.js @@ -22,7 +22,7 @@ function setup() { //Engine.run(engine); var options = { isStatic: true - } + }; ground = Bodies.rectangle(200, height, width, 100, options); World.add(world, ground); @@ -47,5 +47,4 @@ function draw() { fill(170); rectMode(CENTER); rect(ground.position.x, ground.position.y, width, 100); - } diff --git a/Courses/natureofcode/5.18_matter_intro/boundary.js b/Courses/natureofcode/5.18_matter_intro/boundary.js index e2cc4e3155..033c0a4846 100644 --- a/Courses/natureofcode/5.18_matter_intro/boundary.js +++ b/Courses/natureofcode/5.18_matter_intro/boundary.js @@ -9,7 +9,7 @@ function Boundary(x, y, w, h, a) { restitution: 0.95, angle: a, isStatic: true - } + }; this.body = Bodies.rectangle(x, y, w, h, options); this.w = w; this.h = h; @@ -28,6 +28,5 @@ function Boundary(x, y, w, h, a) { fill(0); rect(0, 0, this.w, this.h); pop(); - } - + }; } diff --git a/Courses/natureofcode/5.18_matter_intro/box.js b/Courses/natureofcode/5.18_matter_intro/box.js index b31117111a..600a6f42c5 100644 --- a/Courses/natureofcode/5.18_matter_intro/box.js +++ b/Courses/natureofcode/5.18_matter_intro/box.js @@ -7,7 +7,7 @@ function Circle(x, y, r) { var options = { friction: 0, restitution: 0.95 - } + }; this.body = Bodies.circle(x, y, r, options); this.r = r; World.add(world, this.body); @@ -24,6 +24,5 @@ function Circle(x, y, r) { fill(127); ellipse(0, 0, this.r * 2); pop(); - } - + }; } diff --git a/Courses/natureofcode/5.18_matter_intro/sketch.js b/Courses/natureofcode/5.18_matter_intro/sketch.js index 0cbd4c3d45..5a053c9984 100644 --- a/Courses/natureofcode/5.18_matter_intro/sketch.js +++ b/Courses/natureofcode/5.18_matter_intro/sketch.js @@ -44,5 +44,4 @@ function draw() { for (var i = 0; i < boundaries.length; i++) { boundaries[i].show(); } - } diff --git a/Courses/natureofcode/5.19_matter_delete_bodies/boundary.js b/Courses/natureofcode/5.19_matter_delete_bodies/boundary.js index b9e78ddd36..74aad64d16 100644 --- a/Courses/natureofcode/5.19_matter_delete_bodies/boundary.js +++ b/Courses/natureofcode/5.19_matter_delete_bodies/boundary.js @@ -9,7 +9,7 @@ function Boundary(x, y, w, h, a) { restitution: 0.95, angle: a, isStatic: true - } + }; this.body = Bodies.rectangle(x, y, w, h, options); this.w = w; this.h = h; @@ -27,6 +27,5 @@ function Boundary(x, y, w, h, a) { fill(0); rect(0, 0, this.w, this.h); pop(); - } - + }; } diff --git a/Courses/natureofcode/5.19_matter_delete_bodies/box.js b/Courses/natureofcode/5.19_matter_delete_bodies/box.js index 14d9b2f9dd..8041b249be 100644 --- a/Courses/natureofcode/5.19_matter_delete_bodies/box.js +++ b/Courses/natureofcode/5.19_matter_delete_bodies/box.js @@ -7,19 +7,19 @@ function Circle(x, y, r) { var options = { friction: 0, restitution: 0.95 - } + }; this.body = Bodies.circle(x, y, r, options); this.r = r; World.add(world, this.body); this.isOffScreen = function() { var pos = this.body.position; - return (pos.y > height + 100); - } + return pos.y > height + 100; + }; this.removeFromWorld = function() { World.remove(world, this.body); - } + }; this.show = function() { var pos = this.body.position; @@ -33,6 +33,5 @@ function Circle(x, y, r) { fill(127); ellipse(0, 0, this.r * 2); pop(); - } - + }; } diff --git a/Courses/natureofcode/5.19_matter_delete_bodies/sketch.js b/Courses/natureofcode/5.19_matter_delete_bodies/sketch.js index 618c2e989c..246652d99f 100644 --- a/Courses/natureofcode/5.19_matter_delete_bodies/sketch.js +++ b/Courses/natureofcode/5.19_matter_delete_bodies/sketch.js @@ -52,5 +52,4 @@ function draw() { } // console.log(circles.length, world.bodies.length); - } diff --git a/Courses/natureofcode/5.20_matter_constraints/boundary.js b/Courses/natureofcode/5.20_matter_constraints/boundary.js index 5516ae394b..14b56beeed 100644 --- a/Courses/natureofcode/5.20_matter_constraints/boundary.js +++ b/Courses/natureofcode/5.20_matter_constraints/boundary.js @@ -9,7 +9,7 @@ function Boundary(x, y, w, h, a) { restitution: 0.95, angle: a, isStatic: true - } + }; this.body = Bodies.rectangle(x, y, w, h, options); this.w = w; this.h = h; @@ -27,6 +27,5 @@ function Boundary(x, y, w, h, a) { fill(0); rect(0, 0, this.w, this.h); pop(); - } - + }; } diff --git a/Courses/natureofcode/5.20_matter_constraints/particle.js b/Courses/natureofcode/5.20_matter_constraints/particle.js index c57d9533ea..29665a457b 100644 --- a/Courses/natureofcode/5.20_matter_constraints/particle.js +++ b/Courses/natureofcode/5.20_matter_constraints/particle.js @@ -8,19 +8,19 @@ function Particle(x, y, r, fixed) { friction: 0, restitution: 0.95, isStatic: fixed - } + }; this.body = Bodies.circle(x, y, r, options); this.r = r; World.add(world, this.body); this.isOffScreen = function() { var pos = this.body.position; - return (pos.y > height + 100); - } + return pos.y > height + 100; + }; this.removeFromWorld = function() { World.remove(world, this.body); - } + }; this.show = function() { var pos = this.body.position; @@ -34,6 +34,5 @@ function Particle(x, y, r, fixed) { fill(127); ellipse(0, 0, this.r * 2); pop(); - } - + }; } diff --git a/Courses/natureofcode/5.20_matter_constraints/sketch.js b/Courses/natureofcode/5.20_matter_constraints/sketch.js index c6a03af5ca..d6196719be 100644 --- a/Courses/natureofcode/5.20_matter_constraints/sketch.js +++ b/Courses/natureofcode/5.20_matter_constraints/sketch.js @@ -25,7 +25,6 @@ function setup() { var prev = null; for (var x = 200; x < 400; x += 20) { - var fixed = false; if (!prev) { fixed = true; @@ -40,7 +39,7 @@ function setup() { bodyB: prev.body, length: 20, stiffness: 0.4 - } + }; var constraint = Constraint.create(options); World.add(world, constraint); } @@ -48,7 +47,6 @@ function setup() { prev = p; } - boundaries.push(new Boundary(200, height, width, 50, 0)); } @@ -73,5 +71,4 @@ function draw() { } //line(particles[0].body.position.x, particles[0].body.position.y, particles[1].body.position.x, particles[1].body.position.y); - } diff --git a/Courses/natureofcode/5.21_matter_mouse_constraint/boundary.js b/Courses/natureofcode/5.21_matter_mouse_constraint/boundary.js index 0cc21b2563..3ebcd3e633 100644 --- a/Courses/natureofcode/5.21_matter_mouse_constraint/boundary.js +++ b/Courses/natureofcode/5.21_matter_mouse_constraint/boundary.js @@ -9,7 +9,7 @@ function Boundary(x, y, w, h, a) { restitution: 0.95, angle: a, isStatic: true - } + }; this.body = Bodies.rectangle(x, y, w, h, options); this.w = w; this.h = h; @@ -27,6 +27,5 @@ function Boundary(x, y, w, h, a) { fill(0); rect(0, 0, this.w, this.h); pop(); - } - + }; } diff --git a/Courses/natureofcode/5.21_matter_mouse_constraint/particle.js b/Courses/natureofcode/5.21_matter_mouse_constraint/particle.js index 3223b66311..744a3c4919 100644 --- a/Courses/natureofcode/5.21_matter_mouse_constraint/particle.js +++ b/Courses/natureofcode/5.21_matter_mouse_constraint/particle.js @@ -8,19 +8,19 @@ function Particle(x, y, r, fixed) { friction: 0, restitution: 0.95, isStatic: fixed - } + }; this.body = Bodies.circle(x, y, r, options); this.r = r; World.add(world, this.body); this.isOffScreen = function() { var pos = this.body.position; - return (pos.y > height + 100); - } + return pos.y > height + 100; + }; this.removeFromWorld = function() { World.remove(world, this.body); - } + }; this.show = function() { var pos = this.body.position; @@ -35,6 +35,5 @@ function Particle(x, y, r, fixed) { ellipse(0, 0, this.r * 2); line(0, 0, this.r, 0); pop(); - } - + }; } diff --git a/Courses/natureofcode/5.21_matter_mouse_constraint/sketch.js b/Courses/natureofcode/5.21_matter_mouse_constraint/sketch.js index 53334cc3d6..ee0d38a3c8 100644 --- a/Courses/natureofcode/5.21_matter_mouse_constraint/sketch.js +++ b/Courses/natureofcode/5.21_matter_mouse_constraint/sketch.js @@ -21,7 +21,6 @@ var ground; var mConstraint; - function setup() { var canvas = createCanvas(400, 400); engine = Engine.create(); @@ -30,7 +29,6 @@ function setup() { var prev = null; for (var x = 200; x < 400; x += 20) { - var fixed = false; if (!prev) { fixed = true; @@ -45,7 +43,7 @@ function setup() { bodyB: prev.body, length: 20, stiffness: 0.4 - } + }; var constraint = Constraint.create(options); World.add(world, constraint); } @@ -53,7 +51,6 @@ function setup() { prev = p; } - boundaries.push(new Boundary(200, height, width, 50, 0)); var canvasmouse = Mouse.create(canvas.elt); @@ -61,7 +58,7 @@ function setup() { //console.log(canvasmouse); var options = { mouse: canvasmouse - } + }; mConstraint = MouseConstraint.create(engine, options); World.add(world, mConstraint); console.log(mConstraint); diff --git a/Courses/natureofcode/9.10_PoolSelection/sketch.js b/Courses/natureofcode/9.10_PoolSelection/sketch.js index 58d0c33b8f..e0ba93f958 100644 --- a/Courses/natureofcode/9.10_PoolSelection/sketch.js +++ b/Courses/natureofcode/9.10_PoolSelection/sketch.js @@ -1,9 +1,9 @@ var fruits = [ - { name: "mango",score: 5}, - { name: "blueberry", score: 3 }, - { name: "cherry", score: 1 }, - { name: "melon", score: 7}, - { name: "apple", score: 1} + { name: 'mango', score: 5 }, + { name: 'blueberry', score: 3 }, + { name: 'cherry', score: 1 }, + { name: 'melon', score: 7 }, + { name: 'apple', score: 1 } ]; function setup() { @@ -23,12 +23,8 @@ function setup() { var fruit = pickOne(fruits); fruit.count++; } - - - } - function pickOne(list) { var index = 0; var r = random(1); @@ -39,5 +35,4 @@ function pickOne(list) { } index--; return list[index]; - } diff --git a/Courses/programming_with_text/session01/1-03_textInput/sketch.js b/Courses/programming_with_text/session01/1-03_textInput/sketch.js index d55d4824db..b3ecd4f6aa 100644 --- a/Courses/programming_with_text/session01/1-03_textInput/sketch.js +++ b/Courses/programming_with_text/session01/1-03_textInput/sketch.js @@ -10,13 +10,12 @@ var submit; function setup() { noCanvas(); // textfield = createInput("your favorite food"); - textfield = select("#blueberry"); + textfield = select('#blueberry'); //textfield.changed(newText); textfield.input(newTyping); output = select('#output'); - submit = select("#submit"); + submit = select('#submit'); submit.mousePressed(newText); - } function newTyping() { @@ -24,7 +23,6 @@ function newTyping() { //createP(textfield.value()); } - function newText() { createP(textfield.value()); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session01/1-04_loadingTextFile/sketch.js b/Courses/programming_with_text/session01/1-04_loadingTextFile/sketch.js index 5f9a2c1478..41c012c180 100644 --- a/Courses/programming_with_text/session01/1-04_loadingTextFile/sketch.js +++ b/Courses/programming_with_text/session01/1-04_loadingTextFile/sketch.js @@ -6,21 +6,21 @@ // var txt; function loadFile() { - loadStrings("rainbow.txt", fileLoaded); + loadStrings('rainbow.txt', fileLoaded); } function fileLoaded(data) { // txt = data; - createP(join(data, "
")); + createP(join(data, '
')); } function fileSelected(file) { - createP(file.name + " " + file.size + " " + file.type); + createP(file.name + ' ' + file.size + ' ' + file.type); - if (file.type == "text") { + if (file.type == 'text') { createP(file.data); } else { - createP("I need a text file."); + createP('I need a text file.'); } // console.log(file); } @@ -30,7 +30,7 @@ function setup() { createFileInput(fileSelected); - var button = select("#loadfile"); + var button = select('#loadfile'); button.mousePressed(loadFile); // console.log(txt); diff --git a/Courses/programming_with_text/session01/1-05_StringObject/sketch.js b/Courses/programming_with_text/session01/1-05_StringObject/sketch.js index 53772a03ed..1b19b8135d 100644 --- a/Courses/programming_with_text/session01/1-05_StringObject/sketch.js +++ b/Courses/programming_with_text/session01/1-05_StringObject/sketch.js @@ -10,11 +10,10 @@ var submit; function setup() { noCanvas(); // textfield = createInput("your favorite food"); - textfield = select("#txt"); + textfield = select('#txt'); output = select('#output'); - submit = select("#submit"); + submit = select('#submit'); submit.mousePressed(newText); - } function newText() { @@ -29,7 +28,6 @@ function newText() { s = join(words, ' '); createP(s); - //var index = s.indexOf("rainbow"); //var newtext = s.substring(s.length / 2, s.length); diff --git a/Courses/programming_with_text/session02/2-0607_regexTestMatchExec/sketch.js b/Courses/programming_with_text/session02/2-0607_regexTestMatchExec/sketch.js index 4b783aa1e6..125bac5fa8 100644 --- a/Courses/programming_with_text/session02/2-0607_regexTestMatchExec/sketch.js +++ b/Courses/programming_with_text/session02/2-0607_regexTestMatchExec/sketch.js @@ -10,10 +10,10 @@ var submit; function setup() { noCanvas(); - textfield = select("#input"); + textfield = select('#input'); //textfield.changed(newText); output = select('#output'); - submit = select("#submit"); + submit = select('#submit'); submit.mousePressed(newText); } @@ -25,12 +25,8 @@ function newText() { // var result = r.exec(s); var results; - while (results = r.exec(s)) { + while ((results = r.exec(s))) { createP(results[1]); // do something with the matched results } - - - - -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session02/2-08_regexSplit/sketch.js b/Courses/programming_with_text/session02/2-08_regexSplit/sketch.js index f7821c8a7a..19b848c3c4 100644 --- a/Courses/programming_with_text/session02/2-08_regexSplit/sketch.js +++ b/Courses/programming_with_text/session02/2-08_regexSplit/sketch.js @@ -3,17 +3,16 @@ // http://patreon.com/codingtrain // Code for: https://youtu.be/fdyqutmcI2Q - var textfield; var output; var submit; function setup() { noCanvas(); - textfield = select("#input"); + textfield = select('#input'); //textfield.changed(newText); output = select('#output'); - submit = select("#submit"); + submit = select('#submit'); submit.mousePressed(newText); } @@ -25,4 +24,4 @@ function newText() { for (var i = 0; i < words.length; i++) { createP(words[i]); } -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session02/2-09_regexReplace/sketch.js b/Courses/programming_with_text/session02/2-09_regexReplace/sketch.js index dc21bdf744..c19ce8b0f9 100644 --- a/Courses/programming_with_text/session02/2-09_regexReplace/sketch.js +++ b/Courses/programming_with_text/session02/2-09_regexReplace/sketch.js @@ -9,10 +9,10 @@ var submit; function setup() { noCanvas(); - textfield = select("#input"); + textfield = select('#input'); //textfield.changed(newText); output = select('#output'); - submit = select("#submit"); + submit = select('#submit'); submit.mousePressed(newText); } @@ -26,18 +26,11 @@ function newText() { function replacer(match, group1, group2) { console.log(arguments); - console.log(arguments[0].length + arguments[1].length + arguments[2].length) - // console.log(match); - // console.log(group1); - // console.log(group2); + console.log(arguments[0].length + arguments[1].length + arguments[2].length); + // console.log(match); + // console.log(group1); + // console.log(group2); return match; } - - - - - - - -/**/ \ No newline at end of file +/**/ diff --git a/Courses/programming_with_text/session03/3-01_rita_js/sketch.js b/Courses/programming_with_text/session03/3-01_rita_js/sketch.js index b235866ff4..06d97f2b97 100644 --- a/Courses/programming_with_text/session03/3-01_rita_js/sketch.js +++ b/Courses/programming_with_text/session03/3-01_rita_js/sketch.js @@ -35,7 +35,7 @@ function processRita() { output += words[i]; } - output += " "; + output += ' '; } createP(output); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session03/3-02_nlp_compromise/sketch.js b/Courses/programming_with_text/session03/3-02_nlp_compromise/sketch.js index b3285e3b7e..bc7775155c 100644 --- a/Courses/programming_with_text/session03/3-02_nlp_compromise/sketch.js +++ b/Courses/programming_with_text/session03/3-02_nlp_compromise/sketch.js @@ -32,4 +32,4 @@ function process() { output += sentence.terms[i].whitespace.trailing; } createP(output); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session04/4_04_mastodon_bot/bot.js b/Courses/programming_with_text/session04/4_04_mastodon_bot/bot.js index bc9140925f..db90d02c89 100644 --- a/Courses/programming_with_text/session04/4_04_mastodon_bot/bot.js +++ b/Courses/programming_with_text/session04/4_04_mastodon_bot/bot.js @@ -2,26 +2,25 @@ require('dotenv').config(); const Mastodon = require('mastodon-api'); const fs = require('fs'); -console.log("Mastodon Bot starting..."); +console.log('Mastodon Bot starting...'); const M = new Mastodon({ client_key: process.env.CLIENT_KEY, client_secret: process.env.CLIENT_SECRET, access_token: process.env.ACCESS_TOKEN, timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests. - api_url: 'https://botsin.space/api/v1/', // optional, defaults to https://mastodon.social/api/v1/ -}) + api_url: 'https://botsin.space/api/v1/' // optional, defaults to https://mastodon.social/api/v1/ +}); toot(); setInterval(toot, 24 * 60 * 60 * 1000); - function toot() { const num = Math.floor(Math.random() * 100); const params = { - spoiler_text: "The meaning of life is: ", + spoiler_text: 'The meaning of life is: ', status: num - } + }; M.post('statuses', params, (error, data) => { if (error) { @@ -33,4 +32,4 @@ function toot() { console.log(data.content); } }); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session04/4_07_mastodon_bot/bot.js b/Courses/programming_with_text/session04/4_07_mastodon_bot/bot.js index 0f67eaab94..af23d35913 100644 --- a/Courses/programming_with_text/session04/4_07_mastodon_bot/bot.js +++ b/Courses/programming_with_text/session04/4_07_mastodon_bot/bot.js @@ -2,22 +2,21 @@ require('dotenv').config(); const Mastodon = require('mastodon-api'); const fs = require('fs'); -console.log("Mastodon Bot starting..."); +console.log('Mastodon Bot starting...'); const M = new Mastodon({ client_key: process.env.CLIENT_KEY, client_secret: process.env.CLIENT_SECRET, access_token: process.env.ACCESS_TOKEN, timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests. - api_url: 'https://botsin.space/api/v1/', // optional, defaults to https://mastodon.social/api/v1/ -}) + api_url: 'https://botsin.space/api/v1/' // optional, defaults to https://mastodon.social/api/v1/ +}); //toot(); //setInterval(toot, 24 * 60 * 60 * 1000); -const listener = M.stream('streaming/user') -listener.on('error', err => console.log(err)) - +const listener = M.stream('streaming/user'); +listener.on('error', err => console.log(err)); listener.on('message', msg => { // fs.writeFileSync(`data${new Date().getTime()}.json`, JSON.stringify(msg, null, 2)); @@ -28,7 +27,6 @@ listener.on('message', msg => { if (msg.data.type === 'follow') { toot(`@${acct} Welcome aboard!`); } else if (msg.data.type === 'mention') { - const regex1 = /(like|favou?rite|❤)/i; const content = msg.data.status.content; const id = msg.data.status.id; @@ -61,7 +59,7 @@ listener.on('message', msg => { function toot(content, id) { const params = { status: content - } + }; if (id) { params.in_reply_to_id = id; } @@ -75,4 +73,4 @@ function toot(content, id) { console.log(data.content); } }); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session04/4_xx_image_mastodon_bot/bot.js b/Courses/programming_with_text/session04/4_xx_image_mastodon_bot/bot.js index 169aa37b8d..bc636deec0 100644 --- a/Courses/programming_with_text/session04/4_xx_image_mastodon_bot/bot.js +++ b/Courses/programming_with_text/session04/4_xx_image_mastodon_bot/bot.js @@ -4,19 +4,18 @@ const util = require('util'); const fs = require('fs'); const exec = util.promisify(require('child_process').exec); -console.log("Mastodon Bot starting..."); +console.log('Mastodon Bot starting...'); const M = new Mastodon({ client_key: process.env.CLIENT_KEY, client_secret: process.env.CLIENT_SECRET, access_token: process.env.ACCESS_TOKEN, timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests. - api_url: 'https://botsin.space/api/v1/', // optional, defaults to https://mastodon.social/api/v1/ -}) + api_url: 'https://botsin.space/api/v1/' // optional, defaults to https://mastodon.social/api/v1/ +}); const cmd = 'processing-java --sketch=`pwd`/treegen --run'; - function tooter() { toot() .then(response => console.log(response)) @@ -37,7 +36,7 @@ async function toot() { const params1 = { file: stream, description: `A randomly generated fractal tree with ${angle}` - } + }; const response2 = await M.post('media', params1); const id = response2.data.id; @@ -46,10 +45,10 @@ async function toot() { status: `Behold my beautiful tree with angle ${angle} degrees`, in_reply_to_id: reply_id, media_ids: [id] - } - const response3 = await M.post('statuses', params2) + }; + const response3 = await M.post('statuses', params2); return { success: true, angle: angle }; -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session04/4_xx_reply_image_mastodon_bot/bot.js b/Courses/programming_with_text/session04/4_xx_reply_image_mastodon_bot/bot.js index 47b93bc920..ed14aa1bc1 100644 --- a/Courses/programming_with_text/session04/4_xx_reply_image_mastodon_bot/bot.js +++ b/Courses/programming_with_text/session04/4_xx_reply_image_mastodon_bot/bot.js @@ -4,15 +4,15 @@ const util = require('util'); const fs = require('fs'); const exec = util.promisify(require('child_process').exec); -console.log("Mastodon Bot starting..."); +console.log('Mastodon Bot starting...'); const M = new Mastodon({ client_key: process.env.CLIENT_KEY, client_secret: process.env.CLIENT_SECRET, access_token: process.env.ACCESS_TOKEN, timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests. - api_url: 'https://botsin.space/api/v1/', // optional, defaults to https://mastodon.social/api/v1/ -}) + api_url: 'https://botsin.space/api/v1/' // optional, defaults to https://mastodon.social/api/v1/ +}); const cmd = 'processing-java --sketch=`pwd`/treegen --run'; @@ -28,17 +28,15 @@ stream.on('message', response => { const results = content.match(regex); let angle = -1; if (results) { - angle = results[0] + angle = results[0]; } toot(acct, id, angle) .then(response => console.log(response)) .catch(error => console.error(error)); } - }); - //tooter(); //setInterval(tooter, 24 * 60 * 60 * 1000); @@ -47,8 +45,8 @@ async function toot(acct, reply_id, angle) { const params = { status: `@${acct} Please specify an angle in degrees using digits`, in_reply_to_id: reply_id - } - const response = await M.post('statuses', params) + }; + const response = await M.post('statuses', params); return { success: true, angle: -1 @@ -63,7 +61,7 @@ async function toot(acct, reply_id, angle) { const params1 = { file: stream, description: `A randomly generated fractal tree with ${angle}` - } + }; const response2 = await M.post('media', params1); const id = response2.data.id; @@ -72,11 +70,11 @@ async function toot(acct, reply_id, angle) { status: `@${acct} Behold my beautiful tree with angle ${angle} degrees`, in_reply_to_id: reply_id, media_ids: [id] - } - const response3 = await M.post('statuses', params2) + }; + const response3 = await M.post('statuses', params2); return { success: true, angle: angle }; } -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node1/hello.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node1/hello.js index 51d99288f1..0e40084eb1 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node1/hello.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node1/hello.js @@ -1,2 +1 @@ - -console.log("Hello aribitrary video website"); +console.log('Hello aribitrary video website'); diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node2/bot.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node2/bot.js index 700fb4a347..97bf5e7906 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node2/bot.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node2/bot.js @@ -5,16 +5,16 @@ var Twit = require('twit'); var config = require('./config'); var T = new Twit(config); -var params = { - q: 'rainbow', - count: 2 -} +var params = { + q: 'rainbow', + count: 2 +}; -T.get('search/tweets', params, gotData); +T.get('search/tweets', params, gotData); function gotData(err, data, response) { var tweets = data.statuses; for (var i = 0; i < tweets.length; i++) { - console.log(tweets[i].text); + console.log(tweets[i].text); } -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node2/config-empty.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node2/config-empty.js index 9d53fd9a36..d1a68ee28e 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node2/config-empty.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node2/config-empty.js @@ -1,12 +1,12 @@ // Change this file to config.js // Add your keys // Add file .gitignore: config.js -// Load with +// Load with // var config = require('./config.js'); module.exports = { - consumer_key: '', - consumer_secret: '', - access_token: '', - access_token_secret: '' -} \ No newline at end of file + consumer_key: '', + consumer_secret: '', + access_token: '', + access_token_secret: '' +}; diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node3/bot.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node3/bot.js index a65bc3fd96..6501c637ae 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node3/bot.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node3/bot.js @@ -5,17 +5,16 @@ var Twit = require('twit'); var config = require('./config'); var T = new Twit(config); - var tweet = { status: '#codingrainbow from node.js' -} +}; T.post('statuses/update', tweet, tweeted); function tweeted(err, data, response) { if (err) { - console.log("Something went wwrong!"); + console.log('Something went wwrong!'); } else { - console.log("It worked!"); + console.log('It worked!'); } } diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node3/config-empty.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node3/config-empty.js index 9d53fd9a36..d1a68ee28e 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node3/config-empty.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node3/config-empty.js @@ -1,12 +1,12 @@ // Change this file to config.js // Add your keys // Add file .gitignore: config.js -// Load with +// Load with // var config = require('./config.js'); module.exports = { - consumer_key: '', - consumer_secret: '', - access_token: '', - access_token_secret: '' -} \ No newline at end of file + consumer_key: '', + consumer_secret: '', + access_token: '', + access_token_secret: '' +}; diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_a_setInterval/bot.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_a_setInterval/bot.js index 225d1060cd..e40cb2c17b 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_a_setInterval/bot.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_a_setInterval/bot.js @@ -6,23 +6,22 @@ var config = require('./config'); var T = new Twit(config); tweetIt(); -setInterval(tweetIt, 1000*20); +setInterval(tweetIt, 1000 * 20); function tweetIt() { - - var r = Math.floor(Math.random()*100); + var r = Math.floor(Math.random() * 100); var tweet = { status: 'random number ' + r + ' #codingrainbow' - } + }; T.post('statuses/update', tweet, tweeted); function tweeted(err, data, response) { if (err) { - console.log("Something went wwrong!"); + console.log('Something went wwrong!'); } else { - console.log("It worked!"); + console.log('It worked!'); } } -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_a_setInterval/config-empty.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_a_setInterval/config-empty.js index 9d53fd9a36..d1a68ee28e 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_a_setInterval/config-empty.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_a_setInterval/config-empty.js @@ -1,12 +1,12 @@ // Change this file to config.js // Add your keys // Add file .gitignore: config.js -// Load with +// Load with // var config = require('./config.js'); module.exports = { - consumer_key: '', - consumer_secret: '', - access_token: '', - access_token_secret: '' -} \ No newline at end of file + consumer_key: '', + consumer_secret: '', + access_token: '', + access_token_secret: '' +}; diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_b_followbot/bot.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_b_followbot/bot.js index 652b335663..6c7a40a0cd 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_b_followbot/bot.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_b_followbot/bot.js @@ -11,7 +11,11 @@ var stream = T.stream('user'); // To ensure we don't tweet ourselves, we must get our user data. var my_screen_name = null; -T.get('account/verify_credentials', { skip_status: true }, function(err, data, response) { +T.get('account/verify_credentials', { skip_status: true }, function( + err, + data, + response +) { my_screen_name = data.screen_name; console.log('Using account ' + my_screen_name); }); @@ -20,7 +24,7 @@ T.get('account/verify_credentials', { skip_status: true }, function(err, data, r stream.on('follow', followed); function followed(eventMsg) { - console.log("Follow event!"); + console.log('Follow event!'); var name = eventMsg.source.name; var screenName = eventMsg.source.screen_name; /* If you follow someone, follow bot works again. @@ -33,20 +37,18 @@ function followed(eventMsg) { } } - function tweetIt(txt) { - var tweet = { status: txt - } + }; T.post('statuses/update', tweet, tweeted); function tweeted(err, data, response) { if (err) { - console.log("Something went wwrong!"); + console.log('Something went wwrong!'); } else { - console.log("It worked!"); + console.log('It worked!'); } } } diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_b_followbot/config-empty.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_b_followbot/config-empty.js index 9d53fd9a36..d1a68ee28e 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_b_followbot/config-empty.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node4_b_followbot/config-empty.js @@ -1,12 +1,12 @@ // Change this file to config.js // Add your keys // Add file .gitignore: config.js -// Load with +// Load with // var config = require('./config.js'); module.exports = { - consumer_key: '', - consumer_secret: '', - access_token: '', - access_token_secret: '' -} \ No newline at end of file + consumer_key: '', + consumer_secret: '', + access_token: '', + access_token_secret: '' +}; diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node5/bot.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node5/bot.js index 16d824b1a1..6c30c7c29b 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node5/bot.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node5/bot.js @@ -15,32 +15,31 @@ tweetIt(); function tweetIt() { var cmd = 'processing-java --sketch=`pwd`/rainbow --run'; exec(cmd, processing); - + function processing() { var filename = 'rainbow/output.png'; var params = { encoding: 'base64' - } + }; var b64 = fs.readFileSync(filename, params); T.post('media/upload', { media_data: b64 }, uploaded); function uploaded(err, data, response) { var id = data.media_id_string; - var tweet = { - status: '#codingrainbow live from node.js', - media_ids: [id] - } + var tweet = { + status: '#codingrainbow live from node.js', + media_ids: [id] + }; T.post('statuses/update', tweet, tweeted); - } - function tweeted(err, data, response) { - if (err) { - console.log("Something went wwrong!"); - } else { - console.log("It worked!"); + function tweeted(err, data, response) { + if (err) { + console.log('Something went wwrong!'); + } else { + console.log('It worked!'); + } } } - } -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session04/deprecated_twitter_bots/node5/config-empty.js b/Courses/programming_with_text/session04/deprecated_twitter_bots/node5/config-empty.js index 9d53fd9a36..d1a68ee28e 100644 --- a/Courses/programming_with_text/session04/deprecated_twitter_bots/node5/config-empty.js +++ b/Courses/programming_with_text/session04/deprecated_twitter_bots/node5/config-empty.js @@ -1,12 +1,12 @@ // Change this file to config.js // Add your keys // Add file .gitignore: config.js -// Load with +// Load with // var config = require('./config.js'); module.exports = { - consumer_key: '', - consumer_secret: '', - access_token: '', - access_token_secret: '' -} \ No newline at end of file + consumer_key: '', + consumer_secret: '', + access_token: '', + access_token_secret: '' +}; diff --git a/Courses/programming_with_text/session07/7-02_CFGwithTracery/sketch.js b/Courses/programming_with_text/session07/7-02_CFGwithTracery/sketch.js index bef360b548..5265264bbd 100644 --- a/Courses/programming_with_text/session07/7-02_CFGwithTracery/sketch.js +++ b/Courses/programming_with_text/session07/7-02_CFGwithTracery/sketch.js @@ -4,11 +4,11 @@ // Code for: https://youtu.be/C3EwsSNJeOE var story = { - "start": "#[hero:#character#]story#", - "character": ["dragon", "unicorn", "rainbow"], - "story": "A #adj# #hero.capitalize# fights the #adj# monster. Go #hero# go!", - "adj": ["dark", "sleepy", "quiet"] -} + start: '#[hero:#character#]story#', + character: ['dragon', 'unicorn', 'rainbow'], + story: 'A #adj# #hero.capitalize# fights the #adj# monster. Go #hero# go!', + adj: ['dark', 'sleepy', 'quiet'] +}; var grammar; @@ -16,6 +16,6 @@ function setup() { noCanvas(); grammar = tracery.createGrammar(story); - var result = grammar.flatten("#start#"); + var result = grammar.flatten('#start#'); console.log(result); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session07/7-03_CFGwithRiTaJS/sketch.js b/Courses/programming_with_text/session07/7-03_CFGwithRiTaJS/sketch.js index 2ac2c2d5c4..faf7d2d885 100644 --- a/Courses/programming_with_text/session07/7-03_CFGwithRiTaJS/sketch.js +++ b/Courses/programming_with_text/session07/7-03_CFGwithRiTaJS/sketch.js @@ -31,4 +31,4 @@ function setup() { function newHaiku() { var result = rg.expand(); createP(result); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session08/8-04_RESTfulRoutesParams/server.js b/Courses/programming_with_text/session08/8-04_RESTfulRoutesParams/server.js index c83d47e239..ad9df4519f 100644 --- a/Courses/programming_with_text/session08/8-04_RESTfulRoutesParams/server.js +++ b/Courses/programming_with_text/session08/8-04_RESTfulRoutesParams/server.js @@ -4,12 +4,11 @@ // Code for: https://youtu.be/oMhAd864bBc var words = { - "rainbow": 5, - "unicorn": 3, - "doom": -3, - "gloom": -2 -} - + rainbow: 5, + unicorn: 3, + doom: -3, + gloom: -2 +}; console.log('server is starting'); @@ -20,7 +19,7 @@ var app = express(); var server = app.listen(3000, listening); function listening() { - console.log("listening. . . "); + console.log('listening. . . '); } app.use(express.static('website')); @@ -34,13 +33,13 @@ function addWord(request, response) { var reply; if (!score) { reply = { - msg: "Score is required." - } + msg: 'Score is required.' + }; } else { words[word] = score; reply = { - msg: "Thank you for your word." - } + msg: 'Thank you for your word.' + }; } response.send(reply); @@ -59,15 +58,15 @@ function searchWord(request, response) { var reply; if (words[word]) { reply = { - status: "found", + status: 'found', word: word, score: words[word] - } + }; } else { reply = { - status: "not found", + status: 'not found', word: word - } + }; } response.send(reply); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session08/8-0506_SavingDataJSONnodeJS/server.js b/Courses/programming_with_text/session08/8-0506_SavingDataJSONnodeJS/server.js index d7d60b1a4a..4af1c231dd 100644 --- a/Courses/programming_with_text/session08/8-0506_SavingDataJSONnodeJS/server.js +++ b/Courses/programming_with_text/session08/8-0506_SavingDataJSONnodeJS/server.js @@ -17,7 +17,7 @@ var app = express(); var server = app.listen(3000, listening); function listening() { - console.log("listening. . . "); + console.log('listening. . . '); } app.use(express.static('website')); @@ -31,15 +31,14 @@ function addWord(request, response) { var reply; if (!score) { var reply = { - msg: "Score is required." - } + msg: 'Score is required.' + }; response.send(reply); } else { words[word] = score; var data = JSON.stringify(words, null, 2); fs.writeFile('words.json', data, finished); } - } function finished(err) { @@ -47,8 +46,8 @@ function finished(err) { reply = { word: word, score: score, - status: "success" - } + status: 'success' + }; response.send(reply); } @@ -65,15 +64,15 @@ function searchWord(request, response) { var reply; if (words[word]) { reply = { - status: "found", + status: 'found', word: word, score: words[word] - } + }; } else { reply = { - status: "not found", + status: 'not found', word: word - } + }; } response.send(reply); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session08/8-0506_SavingDataJSONnodeJS/website/sketch.js b/Courses/programming_with_text/session08/8-0506_SavingDataJSONnodeJS/website/sketch.js index 9d2c330429..1b2b666d0b 100644 --- a/Courses/programming_with_text/session08/8-0506_SavingDataJSONnodeJS/website/sketch.js +++ b/Courses/programming_with_text/session08/8-0506_SavingDataJSONnodeJS/website/sketch.js @@ -27,10 +27,8 @@ function submitWord() { console.log(data); drawData(); } - } - function gotData(data) { background(51); console.log(data); @@ -44,4 +42,4 @@ function gotData(data) { textSize(16); text(word, x, y); } -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session08/8-07_ConclusionHTTPPOST/server.js b/Courses/programming_with_text/session08/8-07_ConclusionHTTPPOST/server.js index ab75856a0a..560066b162 100644 --- a/Courses/programming_with_text/session08/8-07_ConclusionHTTPPOST/server.js +++ b/Courses/programming_with_text/session08/8-07_ConclusionHTTPPOST/server.js @@ -22,16 +22,18 @@ var app = express(); var server = app.listen(3000, listening); function listening() { - console.log("listening. . . "); + console.log('listening. . . '); } app.use(express.static('website')); var bodyParser = require('body-parser'); app.use(bodyParser.json()); // support json encoded bodies -app.use(bodyParser.urlencoded({ - extended: true -})); // support encoded bodies +app.use( + bodyParser.urlencoded({ + extended: true + }) +); // support encoded bodies app.use(cors()); @@ -68,7 +70,7 @@ function analyzeThis(request, response) { score: totalScore, comparative: comp, words: wordlist - } + }; response.send(reply); } @@ -81,15 +83,14 @@ function addWord(request, response) { var reply; if (!score && score !== 0) { var reply = { - msg: "Score is required." - } + msg: 'Score is required.' + }; response.send(reply); } else { additional[word] = score; var data = JSON.stringify(additional, null, 2); fs.writeFile('additional.json', data, finished); } - } function finished(err) { @@ -97,8 +98,8 @@ function finished(err) { reply = { word: word, score: score, - status: "success" - } + status: 'success' + }; response.send(reply); } @@ -108,7 +109,7 @@ function sendAll(request, response) { var data = { additional: additional, afinn: afinn - } + }; response.send(data); } @@ -119,15 +120,15 @@ function searchWord(request, response) { var reply; if (words[word]) { reply = { - status: "found", + status: 'found', word: word, score: words[word] - } + }; } else { reply = { - status: "not found", + status: 'not found', word: word - } + }; } response.send(reply); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session08/8-07_ConclusionHTTPPOST/website/sketch.js b/Courses/programming_with_text/session08/8-07_ConclusionHTTPPOST/website/sketch.js index f703faa1eb..6a1c8ae03f 100644 --- a/Courses/programming_with_text/session08/8-07_ConclusionHTTPPOST/website/sketch.js +++ b/Courses/programming_with_text/session08/8-07_ConclusionHTTPPOST/website/sketch.js @@ -12,7 +12,6 @@ function setup() { var buttonA = select('#analyze'); buttonA.mousePressed(analyzeThis); - } function analyzeThis() { @@ -20,7 +19,7 @@ function analyzeThis() { var data = { text: txt - } + }; httpPost('analyze/', data, 'json', dataPosted, postErr); } @@ -32,8 +31,6 @@ function postErr(err) { console.log(err); } - - function submitWord() { var word = select('#word').value(); var score = select('#scoreinput').value(); @@ -44,4 +41,4 @@ function submitWord() { function finished(data) { console.log(data); } -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session09/9-02_FirebaseSavingData/sketch.js b/Courses/programming_with_text/session09/9-02_FirebaseSavingData/sketch.js index 25b0345a28..37affc4af0 100644 --- a/Courses/programming_with_text/session09/9-02_FirebaseSavingData/sketch.js +++ b/Courses/programming_with_text/session09/9-02_FirebaseSavingData/sketch.js @@ -13,7 +13,7 @@ var database; function setup() { canvas = createCanvas(100, 100); score = 0; - createP('Click the button to get points.') + createP('Click the button to get points.'); button = createButton('click'); button.mousePressed(increaseScore); initialInput = createInput('initials'); @@ -21,11 +21,11 @@ function setup() { submitButton.mousePressed(submitScore); var config = { - apiKey: "AIzaSyDsJ73sg9CjbMj08ibW8KuTYQ4WfV3faSM", - authDomain: "my-not-awesome-project.firebaseapp.com", - databaseURL: "https://my-not-awesome-project.firebaseio.com", - storageBucket: "my-not-awesome-project.appspot.com", - messagingSenderId: "583703514528" + apiKey: 'AIzaSyDsJ73sg9CjbMj08ibW8KuTYQ4WfV3faSM', + authDomain: 'my-not-awesome-project.firebaseapp.com', + databaseURL: 'https://my-not-awesome-project.firebaseio.com', + storageBucket: 'my-not-awesome-project.appspot.com', + messagingSenderId: '583703514528' }; firebase.initializeApp(config); database = firebase.database(); @@ -35,7 +35,7 @@ function submitScore() { var data = { initials: initialInput.value(), score: score - } + }; console.log(data); var ref = database.ref('scores'); ref.push(data); @@ -51,4 +51,4 @@ function draw() { textSize(32); fill(255); text(score, width / 2, height / 2); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session09/9-03_FirebaseRetrievingData/sketch.js b/Courses/programming_with_text/session09/9-03_FirebaseRetrievingData/sketch.js index 677b22c8b5..e030168556 100644 --- a/Courses/programming_with_text/session09/9-03_FirebaseRetrievingData/sketch.js +++ b/Courses/programming_with_text/session09/9-03_FirebaseRetrievingData/sketch.js @@ -25,11 +25,11 @@ function setup() { submitButton.mousePressed(submitScore); var config = { - apiKey: "AIzaSyDsJ73sg9CjbMj08ibW8KuTYQ4WfV3faSM", - authDomain: "my-not-awesome-project.firebaseapp.com", - databaseURL: "https://my-not-awesome-project.firebaseio.com", - storageBucket: "my-not-awesome-project.appspot.com", - messagingSenderId: "583703514528" + apiKey: 'AIzaSyDsJ73sg9CjbMj08ibW8KuTYQ4WfV3faSM', + authDomain: 'my-not-awesome-project.firebaseapp.com', + databaseURL: 'https://my-not-awesome-project.firebaseio.com', + storageBucket: 'my-not-awesome-project.appspot.com', + messagingSenderId: '583703514528' }; firebase.initializeApp(config); database = firebase.database(); @@ -39,7 +39,6 @@ function setup() { } function gotData(data) { - var scorelistings = selectAll('.scorelisting'); for (var i = 0; i < scorelistings.length; i++) { scorelistings[i].remove(); @@ -65,12 +64,11 @@ function errData(err) { console.log(err); } - function submitScore() { var data = { initials: initialInput.value(), score: score - } + }; console.log(data); var ref = database.ref('scores'); var result = ref.push(data); @@ -87,4 +85,4 @@ function draw() { textSize(32); fill(255); text(score, width / 2, height / 2); -} \ No newline at end of file +} diff --git a/Courses/programming_with_text/session10/10-04_Speech_Recognition_with_p5.Speech/sketch.js b/Courses/programming_with_text/session10/10-04_Speech_Recognition_with_p5.Speech/sketch.js index 27f78ef102..65222c9e9d 100644 --- a/Courses/programming_with_text/session10/10-04_Speech_Recognition_with_p5.Speech/sketch.js +++ b/Courses/programming_with_text/session10/10-04_Speech_Recognition_with_p5.Speech/sketch.js @@ -17,5 +17,4 @@ function setup() { createP(speechRec.resultString); } } - } diff --git a/Courses/programming_with_text/session11/11-02_Bookmarklets/bookmarklet.js b/Courses/programming_with_text/session11/11-02_Bookmarklets/bookmarklet.js index 72b46657e0..5a621fdbc3 100644 --- a/Courses/programming_with_text/session11/11-02_Bookmarklets/bookmarklet.js +++ b/Courses/programming_with_text/session11/11-02_Bookmarklets/bookmarklet.js @@ -3,7 +3,7 @@ // http://patreon.com/codingtrain (function() { - console.log("bookmarklet starting"); + console.log('bookmarklet starting'); let paragraphs = document.getElementsByTagName('p'); for (let i = 0; i < paragraphs.length; i++) { paragraphs[i].innerHTML = 'puppy'; diff --git a/Courses/programming_with_text/session11/11-03_Chrome_Extensions_Content_Scripts/content.js b/Courses/programming_with_text/session11/11-03_Chrome_Extensions_Content_Scripts/content.js index 3aecb2b4e2..cf3acac912 100644 --- a/Courses/programming_with_text/session11/11-03_Chrome_Extensions_Content_Scripts/content.js +++ b/Courses/programming_with_text/session11/11-03_Chrome_Extensions_Content_Scripts/content.js @@ -2,7 +2,7 @@ // http://codingtra.in // http://patreon.com/codingtrain -console.log("Chrome extension go?"); +console.log('Chrome extension go?'); let paragraphs = document.getElementsByTagName('p'); for (elt of paragraphs) { diff --git a/Courses/programming_with_text/session11/11-04_Chrome_Extensions_Background_Scripts/background.js b/Courses/programming_with_text/session11/11-04_Chrome_Extensions_Background_Scripts/background.js index c32b9bb16b..673df2483c 100644 --- a/Courses/programming_with_text/session11/11-04_Chrome_Extensions_Background_Scripts/background.js +++ b/Courses/programming_with_text/session11/11-04_Chrome_Extensions_Background_Scripts/background.js @@ -8,7 +8,7 @@ chrome.browserAction.onClicked.addListener(buttonClicked); function buttonClicked(tab) { let msg = { - txt: "hello" - } + txt: 'hello' + }; chrome.tabs.sendMessage(tab.id, msg); } diff --git a/Courses/programming_with_text/session11/11-04_Chrome_Extensions_Background_Scripts/content.js b/Courses/programming_with_text/session11/11-04_Chrome_Extensions_Background_Scripts/content.js index e246c99b18..682b29210b 100644 --- a/Courses/programming_with_text/session11/11-04_Chrome_Extensions_Background_Scripts/content.js +++ b/Courses/programming_with_text/session11/11-04_Chrome_Extensions_Background_Scripts/content.js @@ -2,15 +2,13 @@ // http://codingtra.in // http://patreon.com/codingtrain -console.log("Chrome extension go?"); - - +console.log('Chrome extension go?'); chrome.runtime.onMessage.addListener(gotMessage); function gotMessage(message, sender, sendResponse) { console.log(message.txt); - if (message.txt === "hello") { + if (message.txt === 'hello') { let paragraphs = document.getElementsByTagName('p'); for (elt of paragraphs) { elt.style['background-color'] = '#FF00FF'; diff --git a/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/background.js b/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/background.js index c32b9bb16b..673df2483c 100644 --- a/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/background.js +++ b/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/background.js @@ -8,7 +8,7 @@ chrome.browserAction.onClicked.addListener(buttonClicked); function buttonClicked(tab) { let msg = { - txt: "hello" - } + txt: 'hello' + }; chrome.tabs.sendMessage(tab.id, msg); } diff --git a/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/content.js b/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/content.js index 6d38445cc8..caceba7d29 100644 --- a/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/content.js +++ b/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/content.js @@ -2,9 +2,7 @@ // http://codingtra.in // http://patreon.com/codingtrain -console.log("Chrome extension go?"); - - +console.log('Chrome extension go?'); chrome.runtime.onMessage.addListener(gotMessage); diff --git a/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/sketch/sketch.js b/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/sketch/sketch.js index 78bbfdb78f..cb683a2d03 100644 --- a/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/sketch/sketch.js +++ b/Courses/programming_with_text/session11/11-06_Pop-ups_Messaging/sketch/sketch.js @@ -4,16 +4,16 @@ function setup() { userinput.input(changeText); function changeText() { - console.log("text changed"); + console.log('text changed'); let params = { active: true, currentWindow: true - } + }; chrome.tabs.query(params, gotTabs); function gotTabs(tabs) { - console.log("got tabs"); + console.log('got tabs'); console.log(tabs); // send a message to the content script let message = userinput.value(); @@ -22,10 +22,5 @@ function setup() { }; chrome.tabs.sendMessage(tabs[0].id, msg); } - - - - } - } diff --git a/Courses/programming_with_text/session11/11-08_Cross-Browser_Extensions/kitten.js b/Courses/programming_with_text/session11/11-08_Cross-Browser_Extensions/kitten.js index 100c97a27d..6974df353d 100644 --- a/Courses/programming_with_text/session11/11-08_Cross-Browser_Extensions/kitten.js +++ b/Courses/programming_with_text/session11/11-08_Cross-Browser_Extensions/kitten.js @@ -5,11 +5,11 @@ console.log('Kittens of the world, unite as one!'); let filenames = [ - "freddie-marriage-40645.jpg", - "koen-eijkelenboom-353684.jpg", - "mikhail-vasilyev-130018.jpg", - "mikhail-vasilyev-253977.jpg", - "roxanne-desgagnes-277568.jpg" + 'freddie-marriage-40645.jpg', + 'koen-eijkelenboom-353684.jpg', + 'mikhail-vasilyev-130018.jpg', + 'mikhail-vasilyev-253977.jpg', + 'roxanne-desgagnes-277568.jpg' ]; let imgs = document.getElementsByTagName('img'); diff --git a/Tutorials/P5JS/16_promises/11_promises/sketch.js b/Tutorials/P5JS/16_promises/11_promises/sketch.js index f4315248fc..eaf866d6b9 100755 --- a/Tutorials/P5JS/16_promises/11_promises/sketch.js +++ b/Tutorials/P5JS/16_promises/11_promises/sketch.js @@ -5,9 +5,10 @@ // Promises Part 1 // Video: https://youtu.be/QO4NXhWo_NM -const wordnikAPI = "https://api.wordnik.com/v4/words.json/randomWord?&minLength=5&maxLength=-1&api_key=48dd829661f515d5abc0d03197a00582e888cc7da2484d5c7"; -const giphyAPI = "https://api.giphy.com/v1/gifs/search?rating=PG&api_key=dc6zaTOxFJmzC&q="; - +const wordnikAPI = + 'https://api.wordnik.com/v4/words.json/randomWord?&minLength=5&maxLength=-1&api_key=48dd829661f515d5abc0d03197a00582e888cc7da2484d5c7'; +const giphyAPI = + 'https://api.giphy.com/v1/gifs/search?rating=PG&api_key=dc6zaTOxFJmzC&q='; function setup() { noCanvas(); diff --git a/Tutorials/P5JS/16_promises/12_promises_make_your_own/sketch.js b/Tutorials/P5JS/16_promises/12_promises_make_your_own/sketch.js index 0ce7343815..afdf1cb832 100755 --- a/Tutorials/P5JS/16_promises/12_promises_make_your_own/sketch.js +++ b/Tutorials/P5JS/16_promises/12_promises_make_your_own/sketch.js @@ -9,7 +9,7 @@ function setup() { noCanvas(); delayES8(1000) .then(() => createP('hello')) - .catch((err) => console.error(err)); + .catch(err => console.error(err)); } async function delayES8(time) { @@ -20,7 +20,6 @@ async function delayES8(time) { return val; } - function delay(time) { return new Promise((resolve, reject) => { if (isNaN(time)) { diff --git a/Tutorials/P5JS/16_promises/13_16_async_await/sketch.js b/Tutorials/P5JS/16_promises/13_16_async_await/sketch.js index 26cc19d499..22174dcf00 100755 --- a/Tutorials/P5JS/16_promises/13_16_async_await/sketch.js +++ b/Tutorials/P5JS/16_promises/13_16_async_await/sketch.js @@ -10,10 +10,12 @@ // https://youtu.be/01RTj1MWec0 // https://youtu.be/BztW_u6HDbs -// Note: In this file, "let" was changed to "const" where it was appropriate to be consistent with ES6. +// Note: In this file, "let" was changed to "const" where it was appropriate to be consistent with ES6. -const wordnikAPI = "https://api.wordnik.com/v4/words.json/randomWord?&api_key=48dd829661f515d5abc0d03197a00582e888cc7da2484d5c7"; -const giphyAPI = "https://api.giphy.com/v1/gifs/search?rating=G&api_key=dc6zaTOxFJmzC&q="; +const wordnikAPI = + 'https://api.wordnik.com/v4/words.json/randomWord?&api_key=48dd829661f515d5abc0d03197a00582e888cc7da2484d5c7'; +const giphyAPI = + 'https://api.giphy.com/v1/gifs/search?rating=G&api_key=dc6zaTOxFJmzC&q='; function setup() { noCanvas(); @@ -23,7 +25,7 @@ function setup() { promises.push(wordGIF(i)); } Promise.all(promises) - .then((results) => { + .then(results => { for (let i = 0; i < results.length; i++) { createP(results[i].word); if (results[i].img !== null) { @@ -31,11 +33,13 @@ function setup() { } } }) - .catch((err) => console.log(err)); + .catch(err => console.log(err)); } async function wordGIF(num) { - const response1 = await fetch(`${wordnikAPI}&minLength=${num}&maxLength=${num}`); + const response1 = await fetch( + `${wordnikAPI}&minLength=${num}&maxLength=${num}` + ); const json1 = await response1.json(); const response2 = await fetch(giphyAPI + json1.word); const json2 = await response2.json(); @@ -49,5 +53,5 @@ async function wordGIF(num) { return { word: json1.word, img: img_url - } + }; } diff --git a/Tutorials/P5JS/18_p5.js_webgl/18.01_p5.js_Intro_to_webGL/sketch.js b/Tutorials/P5JS/18_p5.js_webgl/18.01_p5.js_Intro_to_webGL/sketch.js index 275a371bf7..ad4135b8bf 100644 --- a/Tutorials/P5JS/18_p5.js_webgl/18.01_p5.js_Intro_to_webGL/sketch.js +++ b/Tutorials/P5JS/18_p5.js_webgl/18.01_p5.js_Intro_to_webGL/sketch.js @@ -13,5 +13,4 @@ function draw() { fill(255, 0, 150); rect(0, 0, 50, 50); - } diff --git a/Tutorials/P5JS/18_p5.js_webgl/18.02_p5.js_Geometry/sketch.js b/Tutorials/P5JS/18_p5.js_webgl/18.02_p5.js_Geometry/sketch.js index 42980045f5..42c9ad881c 100644 --- a/Tutorials/P5JS/18_p5.js_webgl/18.02_p5.js_Geometry/sketch.js +++ b/Tutorials/P5JS/18_p5.js_webgl/18.02_p5.js_Geometry/sketch.js @@ -14,7 +14,7 @@ function draw() { background(175); rectMode(CENTER); - noStroke() + noStroke(); fill(0, 0, 255); //translate(0, 0, mouseX); rotateX(angle); diff --git a/Tutorials/P5JS/18_p5.js_webgl/18.04_p5.js_Texture/sketch.js b/Tutorials/P5JS/18_p5.js_webgl/18.04_p5.js_Texture/sketch.js index 35acc56a62..4905364f81 100644 --- a/Tutorials/P5JS/18_p5.js_webgl/18.04_p5.js_Texture/sketch.js +++ b/Tutorials/P5JS/18_p5.js_webgl/18.04_p5.js_Texture/sketch.js @@ -9,7 +9,7 @@ let kitten; let cam; function preload() { - kitten = loadImage('kittens/kitten0.jpg') + kitten = loadImage('kittens/kitten0.jpg'); } function setup() { diff --git a/Tutorials/P5JS/18_p5.js_webgl/18.06_p5.js_graphics_texture/sketch.js b/Tutorials/P5JS/18_p5.js_webgl/18.06_p5.js_graphics_texture/sketch.js index af37595bec..7e8dbe8b0e 100644 --- a/Tutorials/P5JS/18_p5.js_webgl/18.06_p5.js_graphics_texture/sketch.js +++ b/Tutorials/P5JS/18_p5.js_webgl/18.06_p5.js_graphics_texture/sketch.js @@ -16,7 +16,6 @@ function preload() { kitten = loadImage('kittens/kitten2.jpg'); } - function setup() { createCanvas(400, 300, WEBGL); // graphics = createGraphics(300, 300); @@ -49,7 +48,4 @@ function draw() { plane(300, 300); angle += 0.03; - - - } diff --git a/Tutorials/P5JS/p5.js/01/1.3_p5.js_basics_of_drawing/sketch.js b/Tutorials/P5JS/p5.js/01/1.3_p5.js_basics_of_drawing/sketch.js index 344509896f..1da9b21a3b 100644 --- a/Tutorials/P5JS/p5.js/01/1.3_p5.js_basics_of_drawing/sketch.js +++ b/Tutorials/P5JS/p5.js/01/1.3_p5.js_basics_of_drawing/sketch.js @@ -3,7 +3,6 @@ 2. Code is at 7:57 seconds on drawing rectangle */ - function setup() { createCanvas(640, 360); } @@ -11,4 +10,4 @@ function setup() { function draw() { // try to change the numbers below to see differences rect(100, 200, 75, 150); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/01/1.4_p5.js_Color/sketch.js b/Tutorials/P5JS/p5.js/01/1.4_p5.js_Color/sketch.js index d8ff40306d..36cf7cb295 100644 --- a/Tutorials/P5JS/p5.js/01/1.4_p5.js_Color/sketch.js +++ b/Tutorials/P5JS/p5.js/01/1.4_p5.js_Color/sketch.js @@ -3,32 +3,30 @@ code from video: https://youtu.be/9mucjcrhFcM?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cue code can be seen from 9:47 second onward */ - function setup() { - createCanvas(600, 400); + createCanvas(600, 400); } - function draw() { //background(255); background(150, 150, 200); ellipseMode(CENTER); rectMode(CENTER); - + // Body fill(255, 0, 0); rect(240, 145, 20, 100); - - // Head + + // Head fill(0, 0, 255); ellipse(240, 115, 60, 60); - + // Eyes fill(0, 255, 0); ellipse(221, 115, 16, 32); ellipse(259, 115, 16, 32); - + // Legs line(230, 195, 220, 205); line(250, 195, 260, 205); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/02/2.1_Variables_in_p5.js_mouseX_mouseY/sketch.js b/Tutorials/P5JS/p5.js/02/2.1_Variables_in_p5.js_mouseX_mouseY/sketch.js index 69c50373ab..367b5d7f8d 100644 --- a/Tutorials/P5JS/p5.js/02/2.1_Variables_in_p5.js_mouseX_mouseY/sketch.js +++ b/Tutorials/P5JS/p5.js/02/2.1_Variables_in_p5.js_mouseX_mouseY/sketch.js @@ -2,7 +2,6 @@ https://vimeo.com/channels/learningp5js/138327548 */ - function setup() { createCanvas(600, 400); background(250, 250, 100); @@ -14,13 +13,13 @@ function draw() { // ellipse fill(250, 200, 200); ellipse(mouseX, mouseY, 100, 100); - + // rectangle // fill(200, 250, 200); // rect(400, 100, 50, 50); } -// try mousePressed function +// try mousePressed function function mousePressed() { background(250, 250, 100); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/02/2.2_Variables_in_p5.js_(Make_Your_Own)/sketch.js b/Tutorials/P5JS/p5.js/02/2.2_Variables_in_p5.js_(Make_Your_Own)/sketch.js index e57a5fa5ca..7dcfd1dbc0 100644 --- a/Tutorials/P5JS/p5.js/02/2.2_Variables_in_p5.js_(Make_Your_Own)/sketch.js +++ b/Tutorials/P5JS/p5.js/02/2.2_Variables_in_p5.js_(Make_Your_Own)/sketch.js @@ -14,6 +14,6 @@ function draw() { // ellipse fill(250, 200, 200); ellipse(circleX, 200, 80, 80); - + circleX = circleX + 1; -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/02/2.3_0_p5.js_JavaScript_without_objects/sketch.js b/Tutorials/P5JS/p5.js/02/2.3_0_p5.js_JavaScript_without_objects/sketch.js index fbd45e2906..fe61fc7bc2 100644 --- a/Tutorials/P5JS/p5.js/02/2.3_0_p5.js_JavaScript_without_objects/sketch.js +++ b/Tutorials/P5JS/p5.js/02/2.3_0_p5.js_JavaScript_without_objects/sketch.js @@ -4,13 +4,13 @@ https://vimeo.com/channels/learningp5js/138327558 var x = 0; var y = 200; -var diameter = 50; +var diameter = 50; var r = 218; var g = 160; var b = 221; function setup() { - createCanvas(600, 400); + createCanvas(600, 400); } function draw() { @@ -19,6 +19,6 @@ function draw() { // ellipse fill(250, 200, 200); ellipse(x, y, diameter, diameter); - + x = x + 1; -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/02/2.3_1_p5.js_JavaScript_with_objects/sketch.js b/Tutorials/P5JS/p5.js/02/2.3_1_p5.js_JavaScript_with_objects/sketch.js index e8be368c5d..97a7a9c26e 100644 --- a/Tutorials/P5JS/p5.js/02/2.3_1_p5.js_JavaScript_with_objects/sketch.js +++ b/Tutorials/P5JS/p5.js/02/2.3_1_p5.js_JavaScript_with_objects/sketch.js @@ -3,17 +3,16 @@ https://vimeo.com/channels/learningp5js/138327558 */ var circle = { x: 0, - y: 200, + y: 200, diameter: 50 }; - var r = 218; var g = 160; var b = 221; function setup() { - createCanvas(600, 400); + createCanvas(600, 400); } function draw() { @@ -22,6 +21,6 @@ function draw() { // ellipse fill(250, 200, 200); ellipse(circle.x, circle.y, circle.diameter, circle.diameter); - + circle.x = circle.x + 1; -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/02/2.4_p5.js_map/sketch.js b/Tutorials/P5JS/p5.js/02/2.4_p5.js_map/sketch.js index 5b83060e0d..7846b99406 100644 --- a/Tutorials/P5JS/p5.js/02/2.4_p5.js_map/sketch.js +++ b/Tutorials/P5JS/p5.js/02/2.4_p5.js_map/sketch.js @@ -6,7 +6,7 @@ var r = 0; var b = 225; function setup() { - createCanvas(600, 400); + createCanvas(600, 400); } function draw() { @@ -17,8 +17,8 @@ function draw() { b = map(mouseX, 0, 600, 255, 0); // background(col); background(r, 0, b); - + // ellipse fill(250, 118, 222); ellipse(mouseX, 200, 64, 64); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/02/2.5_p5.js_random/sketch.js b/Tutorials/P5JS/p5.js/02/2.5_p5.js_random/sketch.js index 13e0b47f26..48f3043c88 100644 --- a/Tutorials/P5JS/p5.js/02/2.5_p5.js_random/sketch.js +++ b/Tutorials/P5JS/p5.js/02/2.5_p5.js_random/sketch.js @@ -4,13 +4,13 @@ https://vimeo.com/channels/learningp5js/138327559 var spot = { x: 100, y: 50 -} +}; var col = { r: 255, g: 0, b: 0 -} +}; function setup() { createCanvas(600, 400); background(0); @@ -20,10 +20,10 @@ function draw() { col.r = random(100, 255); col.g = 0; col.b = random(100, 190); - + spot.x = random(0, width); spot.y = random(0, height); noStroke(); fill(col.r, col.g, col.b, 100); ellipse(spot.x, spot.y, 24, 24); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/03/3.1_p5.js_Introduction_to_Conditional_Statements/sketch.js b/Tutorials/P5JS/p5.js/03/3.1_p5.js_Introduction_to_Conditional_Statements/sketch.js index bd706b0c9c..bc54bd0a82 100644 --- a/Tutorials/P5JS/p5.js/03/3.1_p5.js_Introduction_to_Conditional_Statements/sketch.js +++ b/Tutorials/P5JS/p5.js/03/3.1_p5.js_Introduction_to_Conditional_Statements/sketch.js @@ -8,14 +8,14 @@ function setup() { function draw() { background(0); - + stroke(255); strokeWeight(4); noFill(); - + if (mouseX > 300) { fill(255, 0, 200); } - + ellipse(300, 200, 100, 100); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/03/3.2_p5.js_The_Bouncing_Ball/sketch.js b/Tutorials/P5JS/p5.js/03/3.2_p5.js_The_Bouncing_Ball/sketch.js index 14c5b2c6a0..45d16d0b06 100644 --- a/Tutorials/P5JS/p5.js/03/3.2_p5.js_The_Bouncing_Ball/sketch.js +++ b/Tutorials/P5JS/p5.js/03/3.2_p5.js_The_Bouncing_Ball/sketch.js @@ -3,7 +3,7 @@ https://vimeo.com/channels/learningp5js/138935675 */ var x = 0; -var speed = 3; +var speed = 3; function setup() { createCanvas(600, 400); @@ -15,10 +15,10 @@ function draw() { strokeWeight(4); noFill(); ellipse(x, 200, 100, 100); - + if (x > width) { speed = -3; } - - x = x + speed; -} \ No newline at end of file + + x = x + speed; +} diff --git a/Tutorials/P5JS/p5.js/03/3.3_p5.js_Else_and_ElseIf_and_and_or/sketch.js b/Tutorials/P5JS/p5.js/03/3.3_p5.js_Else_and_ElseIf_and_and_or/sketch.js index 2c9701bd05..aee7def833 100644 --- a/Tutorials/P5JS/p5.js/03/3.3_p5.js_Else_and_ElseIf_and_and_or/sketch.js +++ b/Tutorials/P5JS/p5.js/03/3.3_p5.js_Else_and_ElseIf_and_and_or/sketch.js @@ -8,13 +8,13 @@ function setup() { function draw() { background(0); - + stroke(255); strokeWeight(4); noFill(); - + if (mouseX > 300 && mouseX < 400) { fill(255, 0, 200); } - rect(300, 200, 100, 100); -} \ No newline at end of file + rect(300, 200, 100, 100); +} diff --git a/Tutorials/P5JS/p5.js/03/3.4_0_p5.js_Boolean_variables/sketch.js b/Tutorials/P5JS/p5.js/03/3.4_0_p5.js_Boolean_variables/sketch.js index ae5572e799..e5b728aa76 100644 --- a/Tutorials/P5JS/p5.js/03/3.4_0_p5.js_Boolean_variables/sketch.js +++ b/Tutorials/P5JS/p5.js/03/3.4_0_p5.js_Boolean_variables/sketch.js @@ -8,17 +8,16 @@ function setup() { function draw() { background(0); - - + stroke(255); strokeWeight(4); noFill(); - + if (mouseX > 300 && mouseX < 400 && mouseY > 200 && mouseY < 300) { if (mouseIsPressed) { background(0, 255, 0); } fill(255, 0, 200); } - rect(300, 200, 100, 100); -} \ No newline at end of file + rect(300, 200, 100, 100); +} diff --git a/Tutorials/P5JS/p5.js/03/3.4_1_p5.js_Boolean_variables/sketch.js b/Tutorials/P5JS/p5.js/03/3.4_1_p5.js_Boolean_variables/sketch.js index 9facfeb69c..0c7cd9885d 100644 --- a/Tutorials/P5JS/p5.js/03/3.4_1_p5.js_Boolean_variables/sketch.js +++ b/Tutorials/P5JS/p5.js/03/3.4_1_p5.js_Boolean_variables/sketch.js @@ -14,11 +14,11 @@ function draw() { } else { background(0); } - + stroke(255); strokeWeight(4); noFill(); - + if (mouseX > 250 && mouseX < 350 && mouseY > 150 && mouseY < 250) { fill(255, 0, 200); } @@ -34,6 +34,5 @@ function mousePressed() { // on = true; // } on = !on; - } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/04/4.1_0_p5.js_while/sketch.js b/Tutorials/P5JS/p5.js/04/4.1_0_p5.js_while/sketch.js index 21d478fd34..7a4644565b 100644 --- a/Tutorials/P5JS/p5.js/04/4.1_0_p5.js_while/sketch.js +++ b/Tutorials/P5JS/p5.js/04/4.1_0_p5.js_while/sketch.js @@ -2,7 +2,6 @@ https://vimeo.com/channels/learningp5js/139013336 */ - function setup() { createCanvas(600, 400); } @@ -11,16 +10,16 @@ function draw() { background(0); strokeWeight(4); stroke(255); - + var x = 0; while (x <= width) { fill(0, 200, 255); ellipse(x, 200, 25, 25); x = x + 50; } - + for (x = 0; x <= width; x += 50) { fill(255, 0, 200); ellipse(x, 300, 25, 25); } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/04/4.1_1_p5.js_while_for/sketch.js b/Tutorials/P5JS/p5.js/04/4.1_1_p5.js_while_for/sketch.js index f3df7bb521..7f88431302 100644 --- a/Tutorials/P5JS/p5.js/04/4.1_1_p5.js_while_for/sketch.js +++ b/Tutorials/P5JS/p5.js/04/4.1_1_p5.js_while_for/sketch.js @@ -10,7 +10,7 @@ function draw() { background(0); strokeWeight(4); stroke(255); - + var x = 0; // ellipse(0, 200, 25, 25); ellipse(x, 200, 25, 25); @@ -30,4 +30,4 @@ function draw() { // ellipse(250, 200, 25, 25); ellipse(x, 200, 25, 25); x = x + 50; -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/04/4.2_0_Nested_loops/sketch.js b/Tutorials/P5JS/p5.js/04/4.2_0_Nested_loops/sketch.js index 60c5d3bbde..98d7ff485e 100644 --- a/Tutorials/P5JS/p5.js/04/4.2_0_Nested_loops/sketch.js +++ b/Tutorials/P5JS/p5.js/04/4.2_0_Nested_loops/sketch.js @@ -4,7 +4,7 @@ https://vimeo.com/channels/learningp5js/139013372 var offset = 0; function setup() { - createCanvas(600, 400); + createCanvas(600, 400); } function draw() { @@ -16,7 +16,6 @@ function draw() { fill(random(255), 0, random(255)); ellipse(x + offset, 200, 25, 25); } - + offset = offset + 1; - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/04/4.2_1_Nested_loops/sketch.js b/Tutorials/P5JS/p5.js/04/4.2_1_Nested_loops/sketch.js index f3d3731899..7324546739 100644 --- a/Tutorials/P5JS/p5.js/04/4.2_1_Nested_loops/sketch.js +++ b/Tutorials/P5JS/p5.js/04/4.2_1_Nested_loops/sketch.js @@ -2,9 +2,8 @@ https://vimeo.com/channels/learningp5js/139013372 */ - function setup() { - createCanvas(600, 400); + createCanvas(600, 400); } function draw() { @@ -14,11 +13,8 @@ function draw() { for (var x = 0; x <= mouseX; x += 50) { for (var y = 0; y <= height; y += 50) { - fill(random(255), 0, random(255)); - ellipse(x, y, 25, 25); + fill(random(255), 0, random(255)); + ellipse(x, y, 25, 25); } } - - - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/05/5.1_0_p5.js_functions/sketch.js b/Tutorials/P5JS/p5.js/05/5.1_0_p5.js_functions/sketch.js index 18eba7f566..1bdda4d979 100644 --- a/Tutorials/P5JS/p5.js/05/5.1_0_p5.js_functions/sketch.js +++ b/Tutorials/P5JS/p5.js/05/5.1_0_p5.js_functions/sketch.js @@ -3,11 +3,11 @@ https://vimeo.com/channels/learningp5js/139587733 */ var ball = { - x: 300, - y: 200, - xspeed: 4, + x: 300, + y: 200, + xspeed: 4, yspeed: -3 -} +}; function setup() { createCanvas(600, 400); @@ -18,16 +18,13 @@ function draw() { move(); bounce(); display(); - - } function bounce() { - if (ball.x > width || ball.x < 0) { ball.xspeed = ball.xspeed * -1; - } - + } + if (ball.y > height || ball.y < 0) { ball.yspeed = ball.yspeed * -1; } @@ -43,5 +40,4 @@ function display() { function move() { ball.x = ball.x + ball.xspeed; ball.y = ball.y + ball.yspeed; - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/05/5.1_1_p5.js_functions/sketch.js b/Tutorials/P5JS/p5.js/05/5.1_1_p5.js_functions/sketch.js index bd99b42221..93bfacb7bd 100644 --- a/Tutorials/P5JS/p5.js/05/5.1_1_p5.js_functions/sketch.js +++ b/Tutorials/P5JS/p5.js/05/5.1_1_p5.js_functions/sketch.js @@ -3,11 +3,11 @@ https://vimeo.com/channels/learningp5js/139587733 */ var ball = { - x: 300, - y: 200, - xspeed: 4, + x: 300, + y: 200, + xspeed: 4, yspeed: -3 -} +}; function setup() { createCanvas(600, 400); @@ -19,15 +19,15 @@ function draw() { strokeWeight(4); noFill(); ellipse(ball.x, ball.y, 24, 24); - + if (ball.x > width || ball.x < 0) { ball.xspeed = ball.xspeed * -1; - } - + } + if (ball.y > height || ball.y < 0) { ball.yspeed = ball.yspeed * -1; } - + ball.x = ball.x + ball.xspeed; ball.y = ball.y + ball.yspeed; -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/05/5.2_p5.js_function_parameters_and_arguments/sketch.js b/Tutorials/P5JS/p5.js/05/5.2_p5.js_function_parameters_and_arguments/sketch.js index e4b383cb3c..6bb7074d07 100644 --- a/Tutorials/P5JS/p5.js/05/5.2_p5.js_function_parameters_and_arguments/sketch.js +++ b/Tutorials/P5JS/p5.js/05/5.2_p5.js_function_parameters_and_arguments/sketch.js @@ -10,13 +10,12 @@ function draw() { background(50); lollipop(100, 100, 50); lollipop(300, 200, 150); - } function lollipop(x, y, diameter) { fill(0, 200, 255); - rect(x-10, y, 20, 150); - + rect(x - 10, y, 20, 150); + fill(255, 0, 200); ellipse(x, y, diameter, diameter); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/05/5.3_p5.js_functions_and_return/sketch.js b/Tutorials/P5JS/p5.js/05/5.3_p5.js_functions_and_return/sketch.js index 73f5a1b0e4..299bc123d2 100644 --- a/Tutorials/P5JS/p5.js/05/5.3_p5.js_functions_and_return/sketch.js +++ b/Tutorials/P5JS/p5.js/05/5.3_p5.js_functions_and_return/sketch.js @@ -5,17 +5,17 @@ https://vimeo.com/channels/learningp5js/139587730 function setup() { // var angle = degrees(PI/2); // println(angle); - + var km = milesToKm(26.3); println(km); - + var km2 = milesToKm(100); println(km2); - + // println(milesToKm(90)); } function milesToKm(miles) { var km = miles * 1.6; return km; -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/libraries/p5.serialport.js b/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/libraries/p5.serialport.js index 7b61c753e3..b43bed148c 100644 --- a/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/libraries/p5.serialport.js +++ b/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/libraries/p5.serialport.js @@ -10,26 +10,22 @@ * Shawn Van Every (Shawn.Van.Every@nyu.edu) * ITP/NYU * LGPL - * + * * https://github.com/vanevery/p5.serialport * */ (function(root, factory) { if (typeof define === 'function' && define.amd) define('p5.serialport', ['p5'], function(p5) { - (factory(p5)); + factory(p5); }); - else if (typeof exports === 'object') - factory(require('../p5')); - else - factory(root['p5']); -}(this, function(p5) { - + else if (typeof exports === 'object') factory(require('../p5')); + else factory(root['p5']); +})(this, function(p5) { // ============================================================================= // p5.SerialPort // ============================================================================= - /* var serialPort = new SerialPort(); serialPort.open("/dev/tty-usbserial1", { @@ -44,7 +40,6 @@ * @constructor */ p5.SerialPort = function(_hostname, _serverport) { - var self = this; this.bufferSize = 1; // How much to buffer before sending data event @@ -55,14 +50,14 @@ this.serialport = null; this.serialoptions = null; - + this.emitQueue = []; if (typeof _hostname === 'string') { this.hostname = _hostname; } else { //console.log("typeof _hostname " + typeof _hostname + " setting to locahost"); - this.hostname = "localhost"; + this.hostname = 'localhost'; } if (typeof _serverport === 'number') { @@ -73,10 +68,12 @@ } try { - this.socket = new WebSocket("ws://" + this.hostname + ":" + this.serverport); + this.socket = new WebSocket( + 'ws://' + this.hostname + ':' + this.serverport + ); } catch (err) { //console.log(err + "\n" + "Is the p5.serialserver running?"); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { self.errorCallback("Couldn't connect to the server, is it running?"); } } @@ -84,17 +81,17 @@ this.socket.onopen = function(event) { serialConnected = true; - if (typeof self.connectedCallback !== "undefined") { + if (typeof self.connectedCallback !== 'undefined') { self.connectedCallback(); } - + if (self.emitQueue.length > 0) { - for (var i = 0; i < self.emitQueue.length; i ++){ + for (var i = 0; i < self.emitQueue.length; i++) { self.emit(self.emitQueue[i]); } self.emitQueue = []; } - + /* Now handled by the queue if (self.serialport && self.serialoptions) { // If they have asked for a connect, these won't be null and we should try the connect now @@ -117,21 +114,21 @@ var messageObject = JSON.parse(event.data); // MESSAGE ROUTING - if (typeof messageObject.method !== "undefined") { + if (typeof messageObject.method !== 'undefined') { if (messageObject.method == 'echo') { //console.log("echo: " + messageObject.data); - } else if (messageObject.method === "openserial") { - if (typeof self.openCallback !== "undefined") { + } else if (messageObject.method === 'openserial') { + if (typeof self.openCallback !== 'undefined') { self.openCallback(); } - } else if (messageObject.method === "data") { + } else if (messageObject.method === 'data') { // Add to buffer, assuming this comes in byte by byte //console.log("data: " + JSON.stringify(messageObject.data)); self.serialBuffer.push(messageObject.data); - + //console.log(self.serialBuffer.length); - if (typeof self.dataCallback !== "undefined") { + if (typeof self.dataCallback !== 'undefined') { // Hand it to sketch if (self.serialBuffer.length >= self.bufferSize) { self.dataCallback(); @@ -139,28 +136,28 @@ //console.log(self.serialBuffer.length); } - if (typeof self.rawDataCallback !== "undefined") { + if (typeof self.rawDataCallback !== 'undefined') { self.rawDataCallback(messageObject.data); } } else if (messageObject.method === 'list') { - if (typeof self.listCallback !== "undefined") { + if (typeof self.listCallback !== 'undefined') { self.listCallback(messageObject.data); } - } else if (messageObject.method === "write") { + } else if (messageObject.method === 'write') { // Success Callback? - } else if (messageObject.method === "error") { + } else if (messageObject.method === 'error') { //console.log(messageObject.data); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { // Hand it to sketch self.errorCallback(messageObject.data); } } else { // Got message from server without known method - console.log("Unknown Method: " + messageObject); + console.log('Unknown Method: ' + messageObject); } } else { - console.log("Method Undefined: " + messageObject); + console.log('Method Undefined: ' + messageObject); } }; @@ -168,7 +165,7 @@ //console.log("socketOnClose"); //console.log(event); - if (typeof self.closeCallback !== "undefined") { + if (typeof self.closeCallback !== 'undefined') { self.closeCallback(); } }; @@ -177,11 +174,10 @@ //console.log("socketOnError"); //console.log(event); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { self.errorCallback(); } }; - }; p5.SerialPort.prototype.emit = function(data) { @@ -193,8 +189,11 @@ }; p5.SerialPort.prototype.isConnected = function() { - if (self.serialConnected) { return true; } - else { return false; } + if (self.serialConnected) { + return true; + } else { + return false; + } }; // list() - list serial ports available to the server @@ -209,7 +208,6 @@ }; p5.SerialPort.prototype.open = function(_serialport, _serialoptions, cb) { - if (typeof cb === 'function') { this.openCallback = cb; } @@ -223,7 +221,7 @@ this.serialoptions = {}; } - // If our socket is connected, we'll do this now, + // If our socket is connected, we'll do this now, // otherwise it will happen in the socket.onopen callback this.emit({ method: 'openserial', @@ -241,7 +239,7 @@ method: 'write', data: data }); - //this.socket.send({method:'writeByte',data:data}); ? + //this.socket.send({method:'writeByte',data:data}); ? //this.socket.send({method:'writeString',data:data}) ? }; @@ -289,7 +287,10 @@ // What to return var returnBuffer = this.serialBuffer.slice(0, index + 1); // Clear out what was returned - this.serialBuffer = this.serialBuffer.slice(index, this.serialBuffer.length + index); + this.serialBuffer = this.serialBuffer.slice( + index, + this.serialBuffer.length + index + ); return returnBuffer; } else { return -1; @@ -307,26 +308,27 @@ } // Clear the buffer this.serialBuffer.length = 0; - return stringBuffer.join(""); + return stringBuffer.join(''); }; p5.SerialPort.prototype.readStringUntil = function(stringToFind) { - var stringBuffer = []; //console.log("serialBuffer Length: " + this.serialBuffer.length); for (var i = 0; i < this.serialBuffer.length; i++) { //console.log("push: " + String.fromCharCode(this.serialBuffer[i])); stringBuffer.push(String.fromCharCode(this.serialBuffer[i])); } - stringBuffer = stringBuffer.join(""); + stringBuffer = stringBuffer.join(''); //console.log("stringBuffer: " + stringBuffer); - var returnString = ""; + var returnString = ''; var foundIndex = stringBuffer.indexOf(stringToFind); //console.log("found index: " + foundIndex); if (foundIndex > -1) { returnString = stringBuffer.substr(0, foundIndex); - this.serialBuffer = this.serialBuffer.slice(foundIndex + stringToFind.length); + this.serialBuffer = this.serialBuffer.slice( + foundIndex + stringToFind.length + ); } //console.log("Sending: " + returnString); return returnString; @@ -395,6 +397,6 @@ this.rawDataCallback = _callback; } }; -})); +}); // EOF diff --git a/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/sketch.js b/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/sketch.js index 835fa3c1bf..044f46a6c3 100644 --- a/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/sketch.js +++ b/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/sketch.js @@ -13,8 +13,7 @@ function setup() { } function draw() { -background(0); + background(0); ellipse(100, 200, num, num); ellipse(200, 200, nums[2], nums[2]); - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/sketch2.js b/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/sketch2.js index b8f53068c8..7388263c27 100644 --- a/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/sketch2.js +++ b/Tutorials/P5JS/p5.js/07/7.1_p5.js_what_is_an_array/sketch2.js @@ -1,4 +1,3 @@ - /* 1. Code below is for https://vimeo.com/channels/learningp5js/141211396 @@ -7,7 +6,7 @@ */ -var words = ["rainbow", "heart", "purple", "friendship", "love"]; +var words = ['rainbow', 'heart', 'purple', 'friendship', 'love']; var index = 0; @@ -16,7 +15,6 @@ function setup() { } function draw() { - background(0); fill(255); @@ -30,4 +28,4 @@ function mousePressed() { if (index == words.length) { index = 0; } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/07/7.2_p5.js_arrays_and_loops/libraries/p5.serialport.js b/Tutorials/P5JS/p5.js/07/7.2_p5.js_arrays_and_loops/libraries/p5.serialport.js index 7b61c753e3..b43bed148c 100644 --- a/Tutorials/P5JS/p5.js/07/7.2_p5.js_arrays_and_loops/libraries/p5.serialport.js +++ b/Tutorials/P5JS/p5.js/07/7.2_p5.js_arrays_and_loops/libraries/p5.serialport.js @@ -10,26 +10,22 @@ * Shawn Van Every (Shawn.Van.Every@nyu.edu) * ITP/NYU * LGPL - * + * * https://github.com/vanevery/p5.serialport * */ (function(root, factory) { if (typeof define === 'function' && define.amd) define('p5.serialport', ['p5'], function(p5) { - (factory(p5)); + factory(p5); }); - else if (typeof exports === 'object') - factory(require('../p5')); - else - factory(root['p5']); -}(this, function(p5) { - + else if (typeof exports === 'object') factory(require('../p5')); + else factory(root['p5']); +})(this, function(p5) { // ============================================================================= // p5.SerialPort // ============================================================================= - /* var serialPort = new SerialPort(); serialPort.open("/dev/tty-usbserial1", { @@ -44,7 +40,6 @@ * @constructor */ p5.SerialPort = function(_hostname, _serverport) { - var self = this; this.bufferSize = 1; // How much to buffer before sending data event @@ -55,14 +50,14 @@ this.serialport = null; this.serialoptions = null; - + this.emitQueue = []; if (typeof _hostname === 'string') { this.hostname = _hostname; } else { //console.log("typeof _hostname " + typeof _hostname + " setting to locahost"); - this.hostname = "localhost"; + this.hostname = 'localhost'; } if (typeof _serverport === 'number') { @@ -73,10 +68,12 @@ } try { - this.socket = new WebSocket("ws://" + this.hostname + ":" + this.serverport); + this.socket = new WebSocket( + 'ws://' + this.hostname + ':' + this.serverport + ); } catch (err) { //console.log(err + "\n" + "Is the p5.serialserver running?"); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { self.errorCallback("Couldn't connect to the server, is it running?"); } } @@ -84,17 +81,17 @@ this.socket.onopen = function(event) { serialConnected = true; - if (typeof self.connectedCallback !== "undefined") { + if (typeof self.connectedCallback !== 'undefined') { self.connectedCallback(); } - + if (self.emitQueue.length > 0) { - for (var i = 0; i < self.emitQueue.length; i ++){ + for (var i = 0; i < self.emitQueue.length; i++) { self.emit(self.emitQueue[i]); } self.emitQueue = []; } - + /* Now handled by the queue if (self.serialport && self.serialoptions) { // If they have asked for a connect, these won't be null and we should try the connect now @@ -117,21 +114,21 @@ var messageObject = JSON.parse(event.data); // MESSAGE ROUTING - if (typeof messageObject.method !== "undefined") { + if (typeof messageObject.method !== 'undefined') { if (messageObject.method == 'echo') { //console.log("echo: " + messageObject.data); - } else if (messageObject.method === "openserial") { - if (typeof self.openCallback !== "undefined") { + } else if (messageObject.method === 'openserial') { + if (typeof self.openCallback !== 'undefined') { self.openCallback(); } - } else if (messageObject.method === "data") { + } else if (messageObject.method === 'data') { // Add to buffer, assuming this comes in byte by byte //console.log("data: " + JSON.stringify(messageObject.data)); self.serialBuffer.push(messageObject.data); - + //console.log(self.serialBuffer.length); - if (typeof self.dataCallback !== "undefined") { + if (typeof self.dataCallback !== 'undefined') { // Hand it to sketch if (self.serialBuffer.length >= self.bufferSize) { self.dataCallback(); @@ -139,28 +136,28 @@ //console.log(self.serialBuffer.length); } - if (typeof self.rawDataCallback !== "undefined") { + if (typeof self.rawDataCallback !== 'undefined') { self.rawDataCallback(messageObject.data); } } else if (messageObject.method === 'list') { - if (typeof self.listCallback !== "undefined") { + if (typeof self.listCallback !== 'undefined') { self.listCallback(messageObject.data); } - } else if (messageObject.method === "write") { + } else if (messageObject.method === 'write') { // Success Callback? - } else if (messageObject.method === "error") { + } else if (messageObject.method === 'error') { //console.log(messageObject.data); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { // Hand it to sketch self.errorCallback(messageObject.data); } } else { // Got message from server without known method - console.log("Unknown Method: " + messageObject); + console.log('Unknown Method: ' + messageObject); } } else { - console.log("Method Undefined: " + messageObject); + console.log('Method Undefined: ' + messageObject); } }; @@ -168,7 +165,7 @@ //console.log("socketOnClose"); //console.log(event); - if (typeof self.closeCallback !== "undefined") { + if (typeof self.closeCallback !== 'undefined') { self.closeCallback(); } }; @@ -177,11 +174,10 @@ //console.log("socketOnError"); //console.log(event); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { self.errorCallback(); } }; - }; p5.SerialPort.prototype.emit = function(data) { @@ -193,8 +189,11 @@ }; p5.SerialPort.prototype.isConnected = function() { - if (self.serialConnected) { return true; } - else { return false; } + if (self.serialConnected) { + return true; + } else { + return false; + } }; // list() - list serial ports available to the server @@ -209,7 +208,6 @@ }; p5.SerialPort.prototype.open = function(_serialport, _serialoptions, cb) { - if (typeof cb === 'function') { this.openCallback = cb; } @@ -223,7 +221,7 @@ this.serialoptions = {}; } - // If our socket is connected, we'll do this now, + // If our socket is connected, we'll do this now, // otherwise it will happen in the socket.onopen callback this.emit({ method: 'openserial', @@ -241,7 +239,7 @@ method: 'write', data: data }); - //this.socket.send({method:'writeByte',data:data}); ? + //this.socket.send({method:'writeByte',data:data}); ? //this.socket.send({method:'writeString',data:data}) ? }; @@ -289,7 +287,10 @@ // What to return var returnBuffer = this.serialBuffer.slice(0, index + 1); // Clear out what was returned - this.serialBuffer = this.serialBuffer.slice(index, this.serialBuffer.length + index); + this.serialBuffer = this.serialBuffer.slice( + index, + this.serialBuffer.length + index + ); return returnBuffer; } else { return -1; @@ -307,26 +308,27 @@ } // Clear the buffer this.serialBuffer.length = 0; - return stringBuffer.join(""); + return stringBuffer.join(''); }; p5.SerialPort.prototype.readStringUntil = function(stringToFind) { - var stringBuffer = []; //console.log("serialBuffer Length: " + this.serialBuffer.length); for (var i = 0; i < this.serialBuffer.length; i++) { //console.log("push: " + String.fromCharCode(this.serialBuffer[i])); stringBuffer.push(String.fromCharCode(this.serialBuffer[i])); } - stringBuffer = stringBuffer.join(""); + stringBuffer = stringBuffer.join(''); //console.log("stringBuffer: " + stringBuffer); - var returnString = ""; + var returnString = ''; var foundIndex = stringBuffer.indexOf(stringToFind); //console.log("found index: " + foundIndex); if (foundIndex > -1) { returnString = stringBuffer.substr(0, foundIndex); - this.serialBuffer = this.serialBuffer.slice(foundIndex + stringToFind.length); + this.serialBuffer = this.serialBuffer.slice( + foundIndex + stringToFind.length + ); } //console.log("Sending: " + returnString); return returnString; @@ -395,6 +397,6 @@ this.rawDataCallback = _callback; } }; -})); +}); // EOF diff --git a/Tutorials/P5JS/p5.js/07/7.2_p5.js_arrays_and_loops/sketch.js b/Tutorials/P5JS/p5.js/07/7.2_p5.js_arrays_and_loops/sketch.js index 3264963a83..0a44a3fabb 100644 --- a/Tutorials/P5JS/p5.js/07/7.2_p5.js_arrays_and_loops/sketch.js +++ b/Tutorials/P5JS/p5.js/07/7.2_p5.js_arrays_and_loops/sketch.js @@ -4,8 +4,6 @@ 2. Video Referenced at 1:55 is For Loops, https://vimeo.com/channels/learningp5js/139013336 */ - - var nums = [100, 35, 46, 72]; function setup() { @@ -24,5 +22,4 @@ function draw() { // ellipse(200, 200, nums[1], nums[1]); // ellipse(300, 200, nums[2], nums[2]); // ellipse(400, 200, nums[3], nums[3]); - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/07/7.4_p5js_Mouse_Interaction_with_Objects/sketch.js b/Tutorials/P5JS/p5.js/07/7.4_p5js_Mouse_Interaction_with_Objects/sketch.js index aca15d5625..2ef61a193d 100644 --- a/Tutorials/P5JS/p5.js/07/7.4_p5js_Mouse_Interaction_with_Objects/sketch.js +++ b/Tutorials/P5JS/p5.js/07/7.4_p5js_Mouse_Interaction_with_Objects/sketch.js @@ -17,7 +17,6 @@ function mousePressed() { } } - function draw() { background(0); for (let i = 0; i < bubbles.length; i++) { diff --git a/Tutorials/P5JS/p5.js/07/7.5_0_p5js_Removing_Objects_from_Arrays/sketch.js b/Tutorials/P5JS/p5.js/07/7.5_0_p5js_Removing_Objects_from_Arrays/sketch.js index 21b136ae25..c223a74671 100644 --- a/Tutorials/P5JS/p5.js/07/7.5_0_p5js_Removing_Objects_from_Arrays/sketch.js +++ b/Tutorials/P5JS/p5.js/07/7.5_0_p5js_Removing_Objects_from_Arrays/sketch.js @@ -11,7 +11,6 @@ function setup() { } } - function draw() { background(0); for (let i = 0; i < bubbles.length; i++) { diff --git a/Tutorials/P5JS/p5.js/07/7.5_1_p5js_Removing_Objects_from_Arrays/sketch.js b/Tutorials/P5JS/p5.js/07/7.5_1_p5js_Removing_Objects_from_Arrays/sketch.js index be19634dd4..43728a46fd 100644 --- a/Tutorials/P5JS/p5.js/07/7.5_1_p5js_Removing_Objects_from_Arrays/sketch.js +++ b/Tutorials/P5JS/p5.js/07/7.5_1_p5js_Removing_Objects_from_Arrays/sketch.js @@ -9,8 +9,6 @@ function setup() { let b = new Bubble(x, y, r); bubbles.push(b); } - - } function mousePressed() { diff --git a/Tutorials/P5JS/p5.js/07/7.5_2_p5js_Removing_Objects_from_Arrays/sketch.js b/Tutorials/P5JS/p5.js/07/7.5_2_p5js_Removing_Objects_from_Arrays/sketch.js index 0dd3c8bd81..6bdd2cc8dc 100644 --- a/Tutorials/P5JS/p5.js/07/7.5_2_p5js_Removing_Objects_from_Arrays/sketch.js +++ b/Tutorials/P5JS/p5.js/07/7.5_2_p5js_Removing_Objects_from_Arrays/sketch.js @@ -2,14 +2,12 @@ let bubbles = []; function setup() { createCanvas(600, 400); - } function mouseDragged() { let r = 40; let b = new Bubble(mouseX, mouseY, r); bubbles.push(b); - } function draw() { @@ -27,7 +25,6 @@ function draw() { if (bubbles.length > 10) { bubbles.splice(0, 1); } - } class Bubble { diff --git a/Tutorials/P5JS/p5.js/07/7.6_p5.js_checking_objects_intersection_1/bubble.js b/Tutorials/P5JS/p5.js/07/7.6_p5.js_checking_objects_intersection_1/bubble.js index 12c7fb1cb0..e9e66e6b4c 100644 --- a/Tutorials/P5JS/p5.js/07/7.6_p5.js_checking_objects_intersection_1/bubble.js +++ b/Tutorials/P5JS/p5.js/07/7.6_p5.js_checking_objects_intersection_1/bubble.js @@ -8,7 +8,7 @@ class Bubble { intersects(other) { let d = dist(this.x, this.y, other.x, other.y); - return (d < this.r + other.r); + return d < this.r + other.r; // if (d < this.r + other.r) { // return true; // } else { diff --git a/Tutorials/P5JS/p5.js/07/7.6_p5.js_checking_objects_intersection_1/sketch.js b/Tutorials/P5JS/p5.js/07/7.6_p5.js_checking_objects_intersection_1/sketch.js index 0cf5bc596d..51a84298f3 100644 --- a/Tutorials/P5JS/p5.js/07/7.6_p5.js_checking_objects_intersection_1/sketch.js +++ b/Tutorials/P5JS/p5.js/07/7.6_p5.js_checking_objects_intersection_1/sketch.js @@ -10,8 +10,6 @@ function setup() { function draw() { background(0); - - if (bubble1.intersects(bubble2)) { background(200, 0, 100); } @@ -22,7 +20,6 @@ function draw() { //bubble2.move(); bubble2.x = mouseX; bubble2.y = mouseY; - } class Bubble { @@ -35,7 +32,7 @@ class Bubble { intersects(other) { let d = dist(this.x, this.y, other.x, other.y); - return (d < this.r + other.r); + return d < this.r + other.r; // if (d < this.r + other.r) { // return true; // } else { diff --git a/Tutorials/P5JS/p5.js/07/7.7_p5.js_checking_objects_intersection_2/sketch.js b/Tutorials/P5JS/p5.js/07/7.7_p5.js_checking_objects_intersection_2/sketch.js index 61d6bce873..f827a63d32 100644 --- a/Tutorials/P5JS/p5.js/07/7.7_p5.js_checking_objects_intersection_2/sketch.js +++ b/Tutorials/P5JS/p5.js/07/7.7_p5.js_checking_objects_intersection_2/sketch.js @@ -27,10 +27,7 @@ function draw() { } else { b.changeColor(0); } - - } - } class Bubble { @@ -43,7 +40,7 @@ class Bubble { intersects(other) { let d = dist(this.x, this.y, other.x, other.y); - return (d < this.r + other.r); + return d < this.r + other.r; // if (d < this.r + other.r) { // return true; // } else { diff --git a/Tutorials/P5JS/p5.js/07/7.8_p5.js_objects_images/sketch.js b/Tutorials/P5JS/p5.js/07/7.8_p5.js_objects_images/sketch.js index 022bff8819..3ce1bd99ba 100644 --- a/Tutorials/P5JS/p5.js/07/7.8_p5.js_objects_images/sketch.js +++ b/Tutorials/P5JS/p5.js/07/7.8_p5.js_objects_images/sketch.js @@ -28,7 +28,6 @@ function mousePressed() { } } - function draw() { background(0); for (let i = 0; i < bubbles.length; i++) { @@ -43,13 +42,17 @@ class Bubble { this.y = y; this.r = r; this.kitten = random(kittens); - } clicked(px, py) { //let d = dist(px, py, this.x, this.y); //if (d < this.r) { - if (px > this.x && px < this.x + this.r && py > this.y && py < this.y + this.r) { + if ( + px > this.x && + px < this.x + this.r && + py > this.y && + py < this.y + this.r + ) { this.kitten = flower; //random(kittens); } } diff --git a/Tutorials/P5JS/p5.js/08/8.01_p5.js_What_is_HTML/sketch.js b/Tutorials/P5JS/p5.js/08/8.01_p5.js_What_is_HTML/sketch.js index ab7bfb53ba..c4293db9e0 100644 --- a/Tutorials/P5JS/p5.js/08/8.01_p5.js_What_is_HTML/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.01_p5.js_What_is_HTML/sketch.js @@ -8,4 +8,4 @@ function draw() { background(0); fill(255, 0, 0); rect(100, 100, 50, 50); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/08/8.02_p5.js_Creating_HTML_elements_with_JavaScript/sketch.js b/Tutorials/P5JS/p5.js/08/8.02_p5.js_Creating_HTML_elements_with_JavaScript/sketch.js index e325d47b00..df4d8b465a 100644 --- a/Tutorials/P5JS/p5.js/08/8.02_p5.js_Creating_HTML_elements_with_JavaScript/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.02_p5.js_Creating_HTML_elements_with_JavaScript/sketch.js @@ -2,17 +2,16 @@ function setup() { createCanvas(200, 200); - createElement('h1', 'My favorite language is p5') - createP("My favorite color is purple") - + createElement('h1', 'My favorite language is p5'); + createP('My favorite color is purple'); } function mousePressed() { - createP("My favorite number is " + random(0, 10)) + createP('My favorite number is ' + random(0, 10)); } function draw() { background(0); fill(255, 0, 0); rect(100, 100, 50, 50); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/08/8.03_p5.js_Manipulating_DOM_elements_html_position/sketch.js b/Tutorials/P5JS/p5.js/08/8.03_p5.js_Manipulating_DOM_elements_html_position/sketch.js index dd385b13cd..3924df759e 100644 --- a/Tutorials/P5JS/p5.js/08/8.03_p5.js_Manipulating_DOM_elements_html_position/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.03_p5.js_Manipulating_DOM_elements_html_position/sketch.js @@ -11,16 +11,13 @@ function setup() { h1 = createElement('h1', 'Waiting.'); // h1.position(400, 400); // createP("My favorite color is purple") - } - function mousePressed() { - h1.html("Now I will show you my favorite number"); - createP("My favorite number is " + random(0, 10)); + h1.html('Now I will show you my favorite number'); + createP('My favorite number is ' + random(0, 10)); } - function draw() { //clear(); background(150, 100); @@ -28,4 +25,4 @@ function draw() { rect(x, y, 50, 50); h1.position(x, y); x = x + random(-5, 5); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/08/8.04_p5.js_Handling_DOM_events_with_callbacks/sketch.js b/Tutorials/P5JS/p5.js/08/8.04_p5.js_Handling_DOM_events_with_callbacks/sketch.js index bb3ccb18bd..2251e7f258 100644 --- a/Tutorials/P5JS/p5.js/08/8.04_p5.js_Handling_DOM_events_with_callbacks/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.04_p5.js_Handling_DOM_events_with_callbacks/sketch.js @@ -1,31 +1,25 @@ // https://vimeo.com/channels/learningp5js/142698163 - var bgcolor; var button; - function setup() { canvas = createCanvas(200, 200); bgcolor = color(200); - button = createButton("go go go go"); + button = createButton('go go go go'); button.mousePressed(changeColor); - } function changeColor() { - bgcolor = color(random(255)) - + bgcolor = color(random(255)); } // function mousePressed() { // changeColor(); // } - function draw() { background(bgcolor); fill(255, 0, 175); rect(100, 100, 50, 50); - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/08/8.05_p5.js_Interfacing_with_the_DOM/sketch.js b/Tutorials/P5JS/p5.js/08/8.05_p5.js_Interfacing_with_the_DOM/sketch.js index b2256b1e36..4e48b2abc7 100644 --- a/Tutorials/P5JS/p5.js/08/8.05_p5.js_Interfacing_with_the_DOM/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.05_p5.js_Interfacing_with_the_DOM/sketch.js @@ -10,16 +10,15 @@ function setup() { canvas = createCanvas(200, 200); bgcolor = color(200); nameP = createP('Your name!'); - button = createButton("go"); + button = createButton('go'); button.mousePressed(changeColor); slider = createSlider(10, 100, 86); input = createInput('type your name'); - } function changeColor() { - bgcolor = color(random(255)) + bgcolor = color(random(255)); } function draw() { diff --git a/Tutorials/P5JS/p5.js/08/8.06_p5.js_Other_Events_and_Inputs/sketch.js b/Tutorials/P5JS/p5.js/08/8.06_p5.js_Other_Events_and_Inputs/sketch.js index e284105221..89834fe274 100644 --- a/Tutorials/P5JS/p5.js/08/8.06_p5.js_Other_Events_and_Inputs/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.06_p5.js_Other_Events_and_Inputs/sketch.js @@ -11,18 +11,18 @@ function setup() { canvas.mouseOver(overpara); canvas.mouseOut(outpara); canvas.mousePressed(changeColor); - + bgcolor = color(200); nameP = createP('Your name!'); - - button = createButton("go go go go"); + + button = createButton('go go go go'); button.mousePressed(changeColor); slider = createSlider(10, 100, 86); nameInput = createInput('type your name'); - + nameP.mouseOver(overpara); nameP.mouseOut(outpara); - + nameInput.changed(updateText); } @@ -38,20 +38,17 @@ function outpara() { nameP.html('your mouse is out'); } function changeColor() { - bgcolor = color(random(255)) - + bgcolor = color(random(255)); } // function mousePressed() { // changeColor(); // } - function draw() { background(bgcolor); fill(255, 0, 175); ellipse(100, 100, slider.value(), slider.value()); //nameP.html(input.value()); text(nameInput.value(), 10, 20); - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/08/8.07_p5.js_The_basics_of_CSS/sketch.js b/Tutorials/P5JS/p5.js/08/8.07_p5.js_The_basics_of_CSS/sketch.js index c85ae12f33..33776c6fa6 100644 --- a/Tutorials/P5JS/p5.js/08/8.07_p5.js_The_basics_of_CSS/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.07_p5.js_The_basics_of_CSS/sketch.js @@ -14,23 +14,23 @@ function setup() { txt = createP('some text'); txt.mouseOver(changeStyle); txt.mouseOut(revertStyle); - - button = createButton("go"); + + button = createButton('go'); // button.mousePressed(changeStyle); } function changeStyle() { - txt.style("background-color", "pink"); - txt.style("padding", "24px"); + txt.style('background-color', 'pink'); + txt.style('padding', '24px'); } function revertStyle() { - txt.style("background-color", "purple"); - txt.style("padding", "8px"); + txt.style('background-color', 'purple'); + txt.style('padding', '8px'); } function draw() { background(bgcolor); fill(255, 0, 175); ellipse(100, 100, 50, 50); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/08/8.08_p5.js_events_changed_input/sketch.js b/Tutorials/P5JS/p5.js/08/8.08_p5.js_events_changed_input/sketch.js index 1a8b030300..e51e956f01 100644 --- a/Tutorials/P5JS/p5.js/08/8.08_p5.js_events_changed_input/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.08_p5.js_events_changed_input/sketch.js @@ -7,10 +7,10 @@ var paragraph; function setup() { noCanvas(); - textbox = createInput("enter text"); + textbox = createInput('enter text'); slider = createSlider(10, 64, 16); - paragraph = createP("starting text"); - + paragraph = createP('starting text'); + textbox.changed(updateText); slider.changed(updateSize); //slider.input(updateSize); @@ -19,10 +19,9 @@ function setup() { function updateSize() { // paragraph.style("font-size", "24pt"); - paragraph.style("font-size", slider.value() + "pt"); + paragraph.style('font-size', slider.value() + 'pt'); } - function updateText() { paragraph.html(textbox.value()); } diff --git a/Tutorials/P5JS/p5.js/08/8.09_p5.js_CSS_Selectors/sketch.js b/Tutorials/P5JS/p5.js/08/8.09_p5.js_CSS_Selectors/sketch.js index 9a8b5c6d60..e24b3e10a5 100644 --- a/Tutorials/P5JS/p5.js/08/8.09_p5.js_CSS_Selectors/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.09_p5.js_CSS_Selectors/sketch.js @@ -4,11 +4,6 @@ // All examples: github.com/shiffman/Video-Lesson-Materials +function setup() {} -function setup() { - -} - -function draw() { - -} \ No newline at end of file +function draw() {} diff --git a/Tutorials/P5JS/p5.js/08/8.10_p5.js_select_selectAll_with_CSS_selectors/sketch.js b/Tutorials/P5JS/p5.js/08/8.10_p5.js_select_selectAll_with_CSS_selectors/sketch.js index 90c2d664b2..b3d45f6c6b 100644 --- a/Tutorials/P5JS/p5.js/08/8.10_p5.js_select_selectAll_with_CSS_selectors/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.10_p5.js_select_selectAll_with_CSS_selectors/sketch.js @@ -14,13 +14,13 @@ function setup() { // paragraph = select('#unicorn'); // paragraphs = selectAll('p'); paragraphs = selectAll('.rainbow'); - + for (var i = 0; i < paragraphs.length; i++) { // paragraph.mouseOver(changeBackground); - paragraphs[i].style('font-size', "24pt"); + paragraphs[i].style('font-size', '24pt'); } //paragraph.style('background-color', '#F0F') - + var button = select('#button'); button.mousePressed(canvasBg); } @@ -30,5 +30,5 @@ function canvasBg() { } function changeBackground() { - paragraph.style('background-color', '#F0F') + paragraph.style('background-color', '#F0F'); } diff --git a/Tutorials/P5JS/p5.js/08/8.11_p5.js_callbacks_on_multiple_DOM_elements/sketch.js b/Tutorials/P5JS/p5.js/08/8.11_p5.js_callbacks_on_multiple_DOM_elements/sketch.js index b292fd3230..e094efe825 100644 --- a/Tutorials/P5JS/p5.js/08/8.11_p5.js_callbacks_on_multiple_DOM_elements/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.11_p5.js_callbacks_on_multiple_DOM_elements/sketch.js @@ -16,19 +16,19 @@ function setup() { // createP("This is a random number " + random(100)); paragraph = select('#unicorn'); - + for (var i = 0; i < 100; i++) { var par = createP('rainbow'); par.position(random(500), random(500)); } paragraphs = selectAll('p'); // paragraphs = selectAll('.rainbow'); - + for (var i = 0; i < paragraphs.length; i++) { paragraphs[i].mouseOver(highlight); paragraphs[i].mouseOut(unhighlight); } - + // paragraph = select('#unicorn'); // paragraph.mouseOver(highlight); // paragraph.mouseOut(unhighlight); @@ -42,4 +42,4 @@ function highlight() { function unhighlight() { this.style('padding', '0pt'); this.style('background-color', '#FFF'); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/08/8.12_p5.js_parent_child/sketch.js b/Tutorials/P5JS/p5.js/08/8.12_p5.js_parent_child/sketch.js index ae35e306a9..afc90ec839 100644 --- a/Tutorials/P5JS/p5.js/08/8.12_p5.js_parent_child/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.12_p5.js_parent_child/sketch.js @@ -15,5 +15,5 @@ function setup() { function addItem() { var r = floor(random(0, happy.length)); var li = createElement('li', happy[r]); - li.parent("happylist"); + li.parent('happylist'); } diff --git a/Tutorials/P5JS/p5.js/08/8.13_p5.js_Assign_a_CSS_class_dynamically/sketch.js b/Tutorials/P5JS/p5.js/08/8.13_p5.js_Assign_a_CSS_class_dynamically/sketch.js index a04838d50f..db4b919b8e 100644 --- a/Tutorials/P5JS/p5.js/08/8.13_p5.js_Assign_a_CSS_class_dynamically/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.13_p5.js_Assign_a_CSS_class_dynamically/sketch.js @@ -15,21 +15,20 @@ function setup() { var p = createA('#', 'apples'); var x = floor(random(windowWidth)); var y = floor(random(windowHeight)); - p.position(x,y); - p.class('apple') + p.position(x, y); + p.class('apple'); } for (i = 0; i < 10; i++) { // var p = createP('blueberries'); // var p = createA('http://google.com', 'blueberries') - p = createA('#', 'blueberries') + p = createA('#', 'blueberries'); x = floor(random(windowWidth)); y = floor(random(windowHeight)); - p.position(x,y); + p.position(x, y); p.class('blueberry'); - p.mousePressed(becomeApple) - } - + p.mousePressed(becomeApple); + } } function becomeApple() { @@ -37,16 +36,4 @@ function becomeApple() { this.class('apple'); } -function draw() { - -} - - - - - - - - - - +function draw() {} diff --git a/Tutorials/P5JS/p5.js/08/8.14_0_p5.js_parent()_and_child()_again_with_variables/sketch.js b/Tutorials/P5JS/p5.js/08/8.14_0_p5.js_parent()_and_child()_again_with_variables/sketch.js index b55927d986..da244c1d1e 100644 --- a/Tutorials/P5JS/p5.js/08/8.14_0_p5.js_parent()_and_child()_again_with_variables/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.14_0_p5.js_parent()_and_child()_again_with_variables/sketch.js @@ -1,38 +1,20 @@ var p; function setup() { - noCanvas() + noCanvas(); p = createP('This is a link: '); p.style('background-color', '#CCC'); p.style('padding', '24px'); - + var a = createA('#', 'apples'); a.mousePressed(addPhoto); a.parent(p); - - } function addPhoto() { var img = createImg('apples2.jpg'); - + img.size(100, 100); img.parent(p); // img.parent(this); - } - - - - - - - - - - - - - - - diff --git a/Tutorials/P5JS/p5.js/08/8.14_1_p5.js_parent()_and_child()_again_with_variables/sketch.js b/Tutorials/P5JS/p5.js/08/8.14_1_p5.js_parent()_and_child()_again_with_variables/sketch.js index 7b59a2be62..eec8b9cd49 100644 --- a/Tutorials/P5JS/p5.js/08/8.14_1_p5.js_parent()_and_child()_again_with_variables/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.14_1_p5.js_parent()_and_child()_again_with_variables/sketch.js @@ -1,40 +1,22 @@ // var p; function setup() { - noCanvas() + noCanvas(); for (var i = 0; i < 5; i++) { - var p = createP('This is a link: '); p.style('background-color', '#CCC'); p.style('padding', '24px'); - + var a = createA('#', 'apples'); a.mousePressed(addPhoto); a.parent(p); } - } function addPhoto() { var img = createImg('apples2.jpg'); img.size(100, 100); - + // img.parent(p); img.parent(this); - } - - - - - - - - - - - - - - - diff --git a/Tutorials/P5JS/p5.js/08/8.14_2_p5.js_parent()_and_child()_again_with_variables/sketch.js b/Tutorials/P5JS/p5.js/08/8.14_2_p5.js_parent()_and_child()_again_with_variables/sketch.js index 6e96192639..177821fd92 100644 --- a/Tutorials/P5JS/p5.js/08/8.14_2_p5.js_parent()_and_child()_again_with_variables/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.14_2_p5.js_parent()_and_child()_again_with_variables/sketch.js @@ -1,40 +1,22 @@ // var p; function setup() { - noCanvas() + noCanvas(); for (var i = 0; i < 5; i++) { - var p = createP('This is a link: '); p.style('background-color', '#CCC'); p.style('padding', '24px'); - + var a = createA('#', 'apples'); a.mousePressed(addPhoto); a.parent(p); } - } function addPhoto() { var img = createImg('appleImage.jpg'); img.size(100, 100); var paragraph = this.parent(); - + img.parent(paragraph); - } - - - - - - - - - - - - - - - diff --git a/Tutorials/P5JS/p5.js/08/8.14_3_p5.js_parent()_and_child()_again_with_variables/sketch.js b/Tutorials/P5JS/p5.js/08/8.14_3_p5.js_parent()_and_child()_again_with_variables/sketch.js index 370f9386e7..4d84ac8e8e 100644 --- a/Tutorials/P5JS/p5.js/08/8.14_3_p5.js_parent()_and_child()_again_with_variables/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.14_3_p5.js_parent()_and_child()_again_with_variables/sketch.js @@ -1,18 +1,17 @@ // var p; var images = []; function setup() { - noCanvas() + noCanvas(); for (var i = 0; i < 5; i++) { - var p = createP('This is a link: '); p.style('background-color', '#CCC'); p.style('padding', '24px'); - + var a = createA('#', 'apples'); a.mousePressed(addPhoto); a.parent(p); } - + var button = select('#clear'); button.mousePressed(clearStuff); } @@ -32,18 +31,3 @@ function addPhoto() { var paragraph = this.parent(); img.parent(paragraph); } - - - - - - - - - - - - - - - diff --git a/Tutorials/P5JS/p5.js/08/8.15_p5.js_drag_and_drop/sketch.js b/Tutorials/P5JS/p5.js/08/8.15_p5.js_drag_and_drop/sketch.js index 58e0cd8e40..9aa40a5503 100644 --- a/Tutorials/P5JS/p5.js/08/8.15_p5.js_drag_and_drop/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.15_p5.js_drag_and_drop/sketch.js @@ -2,7 +2,7 @@ var dropzone; function setup() { createCanvas(200, 200); background(0); - + dropzone = select('#dropzone'); dropzone.dragOver(highlight); dropzone.dragLeave(unhighlight); @@ -10,16 +10,15 @@ function setup() { } function gotFile(file) { - createP(file.name + " " + file.size); + createP(file.name + ' ' + file.size); var img = createImg(file.data); img.size(100, 100); - } function highlight() { - dropzone.style('background-color','#ccc'); + dropzone.style('background-color', '#ccc'); } function unhighlight() { - dropzone.style('background-color','#fff'); + dropzone.style('background-color', '#fff'); } diff --git a/Tutorials/P5JS/p5.js/08/8.16_p5js_The_Slider_Dance/sketch.js b/Tutorials/P5JS/p5.js/08/8.16_p5js_The_Slider_Dance/sketch.js index 7b98f425f1..5ea2b3d719 100644 --- a/Tutorials/P5JS/p5.js/08/8.16_p5js_The_Slider_Dance/sketch.js +++ b/Tutorials/P5JS/p5.js/08/8.16_p5js_The_Slider_Dance/sketch.js @@ -15,7 +15,7 @@ function draw() { // Set the position of each slider dynamically using map() for (var i = 0; i < sliders.length; i++) { // Map sine function to range from 0 to 100 for slider - var x = map(sin(angle+offset), -1, 1, 0, 255); + var x = map(sin(angle + offset), -1, 1, 0, 255); // Control the slider sliders[i].value(x); offset += 0.25; diff --git a/Tutorials/P5JS/p5.js/09/9.01_p5.js_Transformation_Pt.1/sketch.js b/Tutorials/P5JS/p5.js/09/9.01_p5.js_Transformation_Pt.1/sketch.js index 2b3d5c325a..012ac3b8af 100644 --- a/Tutorials/P5JS/p5.js/09/9.01_p5.js_Transformation_Pt.1/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.01_p5.js_Transformation_Pt.1/sketch.js @@ -7,20 +7,19 @@ function setup() { } function draw() { - background(0); - - push(); - translate(50, 50); - rotate(angle); - fill(255, 100, 50); - rect(0, 0, 100, 50); - pop(); + background(0); - translate(300, 300); - rotate(-angle * 3); - fill(50, 100, 250); - rect(0, 0, 100, 50); + push(); + translate(50, 50); + rotate(angle); + fill(255, 100, 50); + rect(0, 0, 100, 50); + pop(); + translate(300, 300); + rotate(-angle * 3); + fill(50, 100, 250); + rect(0, 0, 100, 50); - angle = angle + 5; -} \ No newline at end of file + angle = angle + 5; +} diff --git a/Tutorials/P5JS/p5.js/09/9.02_p5.js_Transformation_Pt.2/sketch.js b/Tutorials/P5JS/p5.js/09/9.02_p5.js_Transformation_Pt.2/sketch.js index c9399fc2a7..d8d8c01b22 100644 --- a/Tutorials/P5JS/p5.js/09/9.02_p5.js_Transformation_Pt.2/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.02_p5.js_Transformation_Pt.2/sketch.js @@ -7,17 +7,16 @@ function setup() { } function draw() { - background(0); - push(); - translate(200, 200); - // scale(mouseX / 100, mouseY / 100); - scale(1, -1); - rotate(angle); - stroke(255); - fill(100); - rect(0, 0, 100, 50); - pop(); + background(0); + push(); + translate(200, 200); + // scale(mouseX / 100, mouseY / 100); + scale(1, -1); + rotate(angle); + stroke(255); + fill(100); + rect(0, 0, 100, 50); + pop(); - - angle = angle + 2; -} \ No newline at end of file + angle = angle + 2; +} diff --git a/Tutorials/P5JS/p5.js/09/9.03_p5.js_Transformation_Pt.3/sketch.js b/Tutorials/P5JS/p5.js/09/9.03_p5.js_Transformation_Pt.3/sketch.js index 021b5aa65c..d8d8c01b22 100644 --- a/Tutorials/P5JS/p5.js/09/9.03_p5.js_Transformation_Pt.3/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.03_p5.js_Transformation_Pt.3/sketch.js @@ -7,16 +7,16 @@ function setup() { } function draw() { - background(0); - push(); - translate(200, 200); - // scale(mouseX / 100, mouseY / 100); - scale(1, -1); - rotate(angle); - stroke(255); - fill(100); - rect(0, 0, 100, 50); - pop(); + background(0); + push(); + translate(200, 200); + // scale(mouseX / 100, mouseY / 100); + scale(1, -1); + rotate(angle); + stroke(255); + fill(100); + rect(0, 0, 100, 50); + pop(); - angle = angle + 2; -} \ No newline at end of file + angle = angle + 2; +} diff --git a/Tutorials/P5JS/p5.js/09/9.04_p5.js_setTimeout/sketch.js b/Tutorials/P5JS/p5.js/09/9.04_p5.js_setTimeout/sketch.js index 197e10cd85..f258f8521f 100644 --- a/Tutorials/P5JS/p5.js/09/9.04_p5.js_setTimeout/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.04_p5.js_setTimeout/sketch.js @@ -24,4 +24,4 @@ function draw() { if (x > width) { x = 0; } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/09/9.05_0_p5.js_setInterval/sketch.js b/Tutorials/P5JS/p5.js/09/9.05_0_p5.js_setInterval/sketch.js index b108d2b021..9734e038bb 100644 --- a/Tutorials/P5JS/p5.js/09/9.05_0_p5.js_setInterval/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.05_0_p5.js_setInterval/sketch.js @@ -6,7 +6,7 @@ function setup() { createCanvas(200, 200); timer = createP('timer 1'); timer2 = createP('timer 2'); - + interval = setInterval(timeIt, 500); } @@ -24,4 +24,4 @@ function draw() { if (x > width) { x = 0; } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/09/9.05_1_p5.js_setInterval/sketch.js b/Tutorials/P5JS/p5.js/09/9.05_1_p5.js_setInterval/sketch.js index c64ff888ac..ba9ab7d125 100644 --- a/Tutorials/P5JS/p5.js/09/9.05_1_p5.js_setInterval/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.05_1_p5.js_setInterval/sketch.js @@ -37,4 +37,4 @@ function draw() { if (x > width) { x = 0; } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/09/9.06_p5.js_Closure/sketch.js b/Tutorials/P5JS/p5.js/09/9.06_p5.js_Closure/sketch.js index 9f41a1d836..b2d1b9dc8f 100644 --- a/Tutorials/P5JS/p5.js/09/9.06_p5.js_Closure/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.06_p5.js_Closure/sketch.js @@ -9,7 +9,6 @@ function setup() { makeTimer(timer1, 500); makeTimer(timer2, 312); - } function makeTimer(elt, wait) { @@ -21,10 +20,6 @@ function makeTimer(elt, wait) { } } - - - - function draw() { background(51); stroke(255); @@ -34,4 +29,4 @@ function draw() { if (x > width) { x = 0; } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/ES6_Version/sketch.js b/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/ES6_Version/sketch.js index a789bd7946..1832c60200 100644 --- a/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/ES6_Version/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/ES6_Version/sketch.js @@ -7,7 +7,6 @@ function setup() { for (let i = 0; i < 4; i++) { vibrations.push(new Particle(random(width), random(height))); } - } function draw() { @@ -33,7 +32,6 @@ function mousePressed() { } class Particle { - constructor(x, y) { this.x = x; this.y = y; @@ -68,7 +66,7 @@ class Particle { // beginShape(); for (let i = 0; i < this.history.length; i++) { let pos = this.history[i]; - let col = map(i, 0, this.history.length, 75, 200) + let col = map(i, 0, this.history.length, 75, 200); fill(col); let d = map(i, 0, this.history.length, 1, 24); ellipse(pos.x, pos.y, d, d); diff --git a/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/particle.js b/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/particle.js index 8c5f7d9440..61e6cbf158 100644 --- a/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/particle.js +++ b/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/particle.js @@ -4,30 +4,30 @@ function Particle(x, y) { this.x = x; this.y = y; - + this.history = []; - + this.update = function() { this.x += random(-10, 10); this.y += random(-10, 10); - + for (var i = 0; i < this.history.length; i++) { this.history[i].x += random(-2, 2); this.history[i].y += random(-2, 2); } var v = createVector(this.x, this.y); - this.history.push(v); + this.history.push(v); if (this.history.length > 100) { this.history.splice(0, 1); } - } - + }; + this.show = function() { stroke(0); fill(0, 150); ellipse(this.x, this.y, 24, 24); - + noFill(); beginShape(); for (var i = 0; i < this.history.length; i++) { @@ -37,8 +37,5 @@ function Particle(x, y) { vertex(pos.x, pos.y); } endShape(); - - - } - -} \ No newline at end of file + }; +} diff --git a/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/sketch.js b/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/sketch.js index 1a0ce4fd3a..4b9b7ae3c7 100644 --- a/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.07_p5.js_Drawing_Object_Trails/sketch.js @@ -17,6 +17,6 @@ function draw() { particles[i].update(); particles[i].show(); } - + //line(frameCount, 0, frameCount, height); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/09/9.08_p5.js_Random_Circles_with_No_Overlap/ES6_Version/sketch.js b/Tutorials/P5JS/p5.js/09/9.08_p5.js_Random_Circles_with_No_Overlap/ES6_Version/sketch.js index cf5230dc23..b83bd83924 100644 --- a/Tutorials/P5JS/p5.js/09/9.08_p5.js_Random_Circles_with_No_Overlap/ES6_Version/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.08_p5.js_Random_Circles_with_No_Overlap/ES6_Version/sketch.js @@ -14,7 +14,6 @@ let circles = []; let counter = 0; class Circle { - constructor() { this.x = random(width); this.y = random(height); @@ -22,16 +21,20 @@ class Circle { } } - function setup() { createCanvas(600, 600); while (circles.length < 1000) { let overlapping = false; - let proposalCircle = new Circle; + let proposalCircle = new Circle(); for (let j = 0; j < circles.length; j++) { let existingCircle = circles[j]; - let d = dist(proposalCircle.x, proposalCircle.y, existingCircle.x, existingCircle.y); + let d = dist( + proposalCircle.x, + proposalCircle.y, + existingCircle.x, + existingCircle.y + ); if (d < proposalCircle.r + existingCircle.r) { overlapping = true; break; @@ -42,7 +45,12 @@ function setup() { circles.push(proposalCircle); noStroke(); fill(0, 255, 250, 100); - ellipse(proposalCircle.x, proposalCircle.y, proposalCircle.r * 2, proposalCircle.r * 2); + ellipse( + proposalCircle.x, + proposalCircle.y, + proposalCircle.r * 2, + proposalCircle.r * 2 + ); } counter++; diff --git a/Tutorials/P5JS/p5.js/09/9.08_p5.js_Random_Circles_with_No_Overlap/sketch.js b/Tutorials/P5JS/p5.js/09/9.08_p5.js_Random_Circles_with_No_Overlap/sketch.js index 27ecfd1e18..dc909546a8 100644 --- a/Tutorials/P5JS/p5.js/09/9.08_p5.js_Random_Circles_with_No_Overlap/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.08_p5.js_Random_Circles_with_No_Overlap/sketch.js @@ -5,10 +5,10 @@ var circles = []; function setup() { createCanvas(640, 360); - + // Lets make sure we don't get stuck in infinite loop var protection = 0; - + // Try to get to 500 while (circles.length < 500) { // Pick a random circle @@ -16,7 +16,7 @@ function setup() { x: random(width), y: random(height), r: random(6, 36) - } + }; // Does it overlap any previous circles? var overlapping = false; @@ -27,12 +27,12 @@ function setup() { overlapping = true; } } - + // If not keep it! if (!overlapping) { circles.push(circle); } - + // Are we stuck? protection++; if (protection > 10000) { @@ -46,5 +46,4 @@ function setup() { noStroke(); ellipse(circles[i].x, circles[i].y, circles[i].r * 2, circles[i].r * 2); } - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/09/9.09_p5.js_Minimum_Spanning_Tree/sketch.js b/Tutorials/P5JS/p5.js/09/9.09_p5.js_Minimum_Spanning_Tree/sketch.js index f37455f2ea..2bf85026af 100644 --- a/Tutorials/P5JS/p5.js/09/9.09_p5.js_Minimum_Spanning_Tree/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.09_p5.js_Minimum_Spanning_Tree/sketch.js @@ -7,7 +7,6 @@ function setup() { var v = createVector(random(width), random(height)); vertices.push(v); } - } function mousePressed() { @@ -46,16 +45,19 @@ function draw() { } stroke(255); strokeWeight(2); - line(reached[rIndex].x, reached[rIndex].y, unreached[uIndex].x, unreached[uIndex].y); + line( + reached[rIndex].x, + reached[rIndex].y, + unreached[uIndex].x, + unreached[uIndex].y + ); reached.push(unreached[uIndex]); unreached.splice(uIndex, 1); } - for (var i = 0; i < vertices.length; i++) { fill(255); stroke(255); ellipse(vertices[i].x, vertices[i].y, 16, 16); } - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/09/9.10_p5.js_Reset_a_Sketch_with_Button_Click/flock.js b/Tutorials/P5JS/p5.js/09/9.10_p5.js_Reset_a_Sketch_with_Button_Click/flock.js index 5d7afe9951..34995767c7 100644 --- a/Tutorials/P5JS/p5.js/09/9.10_p5.js_Reset_a_Sketch_with_Button_Click/flock.js +++ b/Tutorials/P5JS/p5.js/09/9.10_p5.js_Reset_a_Sketch_with_Button_Click/flock.js @@ -1,7 +1,6 @@ - // Add a new boid into the System function mouseDragged() { - flock.addBoid(new Boid(mouseX,mouseY)); + flock.addBoid(new Boid(mouseX, mouseY)); } // The Nature of Code @@ -17,13 +16,13 @@ function Flock() { Flock.prototype.run = function() { for (var i = 0; i < this.boids.length; i++) { - this.boids[i].run(this.boids); // Passing the entire list of boids to each boid individually + this.boids[i].run(this.boids); // Passing the entire list of boids to each boid individually } -} +}; Flock.prototype.addBoid = function(b) { this.boids.push(b); -} +}; // The Nature of Code // Daniel Shiffman @@ -32,12 +31,12 @@ Flock.prototype.addBoid = function(b) { // Boid class // Methods for Separation, Cohesion, Alignment added -function Boid(x,y) { - this.acceleration = createVector(0,0); - this.velocity = createVector(random(-1,1),random(-1,1)); - this.position = createVector(x,y); +function Boid(x, y) { + this.acceleration = createVector(0, 0); + this.velocity = createVector(random(-1, 1), random(-1, 1)); + this.position = createVector(x, y); this.r = 3.0; - this.maxspeed = 3; // Maximum speed + this.maxspeed = 3; // Maximum speed this.maxforce = 0.05; // Maximum steering force } @@ -46,17 +45,17 @@ Boid.prototype.run = function(boids) { this.update(); this.borders(); this.render(); -} +}; Boid.prototype.applyForce = function(force) { // We could add mass here if we want A = F / M this.acceleration.add(force); -} +}; Boid.prototype.flock = function(boids) { - var sep = this.separate(boids); // Separation - var ali = this.align(boids); // Alignment - var coh = this.cohesion(boids); // Cohesion + var sep = this.separate(boids); // Separation + var ali = this.align(boids); // Alignment + var coh = this.cohesion(boids); // Cohesion // Arbitrarily weight these forces sep.mult(1.5); ali.mult(1.0); @@ -65,7 +64,7 @@ Boid.prototype.flock = function(boids) { this.applyForce(sep); this.applyForce(ali); this.applyForce(coh); -} +}; // Method to update location Boid.prototype.update = function() { @@ -76,19 +75,19 @@ Boid.prototype.update = function() { this.position.add(this.velocity); // Reset accelertion to 0 each cycle this.acceleration.mult(0); -} +}; // STEER = DESIRED MINUS VELOCITY Boid.prototype.seek = function(target) { - var desired = p5.Vector.sub(target,this.position); // A vector pointing from the location to the target + var desired = p5.Vector.sub(target, this.position); // A vector pointing from the location to the target // Normalize desired and scale to maximum speed desired.normalize(); desired.mult(this.maxspeed); // Steering = Desired minus Velocity - var steer = p5.Vector.sub(desired,this.velocity); - steer.limit(this.maxforce); // Limit to maximum steering force + var steer = p5.Vector.sub(desired, this.velocity); + steer.limit(this.maxforce); // Limit to maximum steering force return steer; -} +}; Boid.prototype.render = function() { // Draw a triangle rotated in the direction of velocity @@ -96,40 +95,40 @@ Boid.prototype.render = function() { fill(127); stroke(200); push(); - translate(this.position.x,this.position.y); + translate(this.position.x, this.position.y); rotate(theta); beginShape(); - vertex(0, -this.r*2); - vertex(-this.r, this.r*2); - vertex(this.r, this.r*2); + vertex(0, -this.r * 2); + vertex(-this.r, this.r * 2); + vertex(this.r, this.r * 2); endShape(CLOSE); pop(); -} +}; // Wraparound Boid.prototype.borders = function() { - if (this.position.x < -this.r) this.position.x = width +this.r; - if (this.position.y < -this.r) this.position.y = height+this.r; - if (this.position.x > width +this.r) this.position.x = -this.r; - if (this.position.y > height+this.r) this.position.y = -this.r; -} + if (this.position.x < -this.r) this.position.x = width + this.r; + if (this.position.y < -this.r) this.position.y = height + this.r; + if (this.position.x > width + this.r) this.position.x = -this.r; + if (this.position.y > height + this.r) this.position.y = -this.r; +}; // Separation // Method checks for nearby boids and steers away Boid.prototype.separate = function(boids) { var desiredseparation = 25.0; - var steer = createVector(0,0); + var steer = createVector(0, 0); var count = 0; // For every boid in the system, check if it's too close for (var i = 0; i < boids.length; i++) { - var d = p5.Vector.dist(this.position,boids[i].position); - if ((d > 0) && (d < desiredseparation)) { + var d = p5.Vector.dist(this.position, boids[i].position); + if (d > 0 && d < desiredseparation) { // Calculate vector pointing away from neighbor - var diff = p5.Vector.sub(this.position,boids[i].position); + var diff = p5.Vector.sub(this.position, boids[i].position); diff.normalize(); - diff.div(d); // Weight by distance + diff.div(d); // Weight by distance steer.add(diff); - count++; // Keep track of how many + count++; // Keep track of how many } } // Average -- divide by how many @@ -146,16 +145,16 @@ Boid.prototype.separate = function(boids) { steer.limit(this.maxforce); } return steer; -} +}; // Alignment Boid.prototype.align = function(boids) { var neighbordist = 50; - var sum = createVector(0,0); + var sum = createVector(0, 0); var count = 0; for (var i = 0; i < boids.length; i++) { - var d = p5.Vector.dist(this.position,boids[i].position); - if ((d > 0) && (d < neighbordist)) { + var d = p5.Vector.dist(this.position, boids[i].position); + if (d > 0 && d < neighbordist) { sum.add(boids[i].velocity); count++; } @@ -164,30 +163,30 @@ Boid.prototype.align = function(boids) { sum.div(count); sum.normalize(); sum.mult(this.maxspeed); - var steer = p5.Vector.sub(sum,this.velocity); + var steer = p5.Vector.sub(sum, this.velocity); steer.limit(this.maxforce); return steer; } else { - return createVector(0,0); + return createVector(0, 0); } -} +}; // Cohesion Boid.prototype.cohesion = function(boids) { var neighbordist = 50; - var sum = createVector(0,0); // Start with empty vector to accumulate all locations + var sum = createVector(0, 0); // Start with empty vector to accumulate all locations var count = 0; for (var i = 0; i < boids.length; i++) { - var d = p5.Vector.dist(this.position,boids[i].position); - if ((d > 0) && (d < neighbordist)) { + var d = p5.Vector.dist(this.position, boids[i].position); + if (d > 0 && d < neighbordist) { sum.add(boids[i].position); // Add location count++; } } if (count > 0) { sum.div(count); - return this.seek(sum); // Steer towards the location + return this.seek(sum); // Steer towards the location } else { - return createVector(0,0); + return createVector(0, 0); } -} \ No newline at end of file +}; diff --git a/Tutorials/P5JS/p5.js/09/9.10_p5.js_Reset_a_Sketch_with_Button_Click/sketch.js b/Tutorials/P5JS/p5.js/09/9.10_p5.js_Reset_a_Sketch_with_Button_Click/sketch.js index 50ab3becf8..754dfaf65d 100644 --- a/Tutorials/P5JS/p5.js/09/9.10_p5.js_Reset_a_Sketch_with_Button_Click/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.10_p5.js_Reset_a_Sketch_with_Button_Click/sketch.js @@ -5,10 +5,10 @@ var frameCounter = 0; function setup() { createCanvas(640, 360); resetSketch(); - var button = createButton("reset"); + var button = createButton('reset'); button.mousePressed(resetSketch); txt = createP('0'); - txt.style('font-size','32pt'); + txt.style('font-size', '32pt'); } function resetSketch() { @@ -23,6 +23,6 @@ function resetSketch() { function draw() { background(51); flock.run(); - txt.html(frameCounter ); + txt.html(frameCounter); frameCounter++; -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/09/9.11_p5.js_Instance_Mode/sketch.js b/Tutorials/P5JS/p5.js/09/9.11_p5.js_Instance_Mode/sketch.js index 81d260f2c8..a51b0b741e 100644 --- a/Tutorials/P5JS/p5.js/09/9.11_p5.js_Instance_Mode/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.11_p5.js_Instance_Mode/sketch.js @@ -4,7 +4,7 @@ var sketch1 = function(p) { p.setup = function() { p.createCanvas(200, 200); p.background(51); - } + }; p.draw = function() { p.fill(255, 0, 200, 25); p.noStroke(); @@ -12,8 +12,8 @@ var sketch1 = function(p) { p.x = p.x + p.random(-10, 10); p.y = p.y + p.random(-10, 10); - } -} + }; +}; var sketch2 = function(p) { p.x = 100; @@ -21,7 +21,7 @@ var sketch2 = function(p) { p.setup = function() { p.createCanvas(200, 200); p.background(51); - } + }; p.draw = function() { p.fill(255, 200, 0, 25); p.noStroke(); @@ -29,8 +29,8 @@ var sketch2 = function(p) { p.x = p.x + p.random(-10, 10); p.y = p.y + p.random(-10, 10); - } -} + }; +}; var myp5_3 = new p5(); @@ -38,10 +38,9 @@ var myp5_1 = new p5(sketch1); var myp5_2 = new p5(sketch2); function resetBackground() { - myp5_1.x = myp5_1.width/2; - myp5_1.y = myp5_1.height/2; + myp5_1.x = myp5_1.width / 2; + myp5_1.y = myp5_1.height / 2; myp5_1.background(51); } setInterval(resetBackground, 3000); - diff --git a/Tutorials/P5JS/p5.js/09/9.14_p5.js_Loading_Animation/sketch.js b/Tutorials/P5JS/p5.js/09/9.14_p5.js_Loading_Animation/sketch.js index 56f6cce55a..3216c1b9ff 100644 --- a/Tutorials/P5JS/p5.js/09/9.14_p5.js_Loading_Animation/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.14_p5.js_Loading_Animation/sketch.js @@ -29,17 +29,16 @@ function draw() { background(51); if (loading) { - stroke(255); noFill(); rect(10, 10, 200, 20); noStroke(); fill(255, 100); - var w = 200 * counter / totalSongs; + var w = (200 * counter) / totalSongs; rect(10, 10, w, 20); - translate(width/2, height/2); + translate(width / 2, height / 2); rotate(angle); strokeWeight(4); stroke(255); @@ -48,5 +47,4 @@ function draw() { } else { background(0, 255, 0); } - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/09/9.17_p5.js_Arguments/sketch.js b/Tutorials/P5JS/p5.js/09/9.17_p5.js_Arguments/sketch.js index 7351227d4c..41b7394b02 100644 --- a/Tutorials/P5JS/p5.js/09/9.17_p5.js_Arguments/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.17_p5.js_Arguments/sketch.js @@ -3,24 +3,24 @@ var particles = []; function setup() { createCanvas(200, 200); particles[0] = new Particle(); - particles[1] = new Particle(150,50); + particles[1] = new Particle(150, 50); var v = createVector(150, 100); particles[2] = new Particle(v); - particles[3] = new Particle("100,150") + particles[3] = new Particle('100,150'); } function draw() { - background(0); - for (var i = 0; i < particles.length; i++) { - particles[i].show(); - } + background(0); + for (var i = 0; i < particles.length; i++) { + particles[i].show(); + } } function Particle(a, b) { if (a instanceof p5.Vector) { this.x = a.x; this.y = a.y; - } else if (typeof(a) == "string") { + } else if (typeof a == 'string') { var nums = a.split(','); this.x = Number(nums[0]); this.y = Number(nums[1]); @@ -32,7 +32,7 @@ function Particle(a, b) { this.show = function() { fill(255); ellipse(this.x, this.y, 16, 16); - } + }; } // function sum() { @@ -48,4 +48,4 @@ function Particle(a, b) { // val += arguments[i]; // } // return val; -// } \ No newline at end of file +// } diff --git a/Tutorials/P5JS/p5.js/09/9.19_p5.js_Prototypes/sketch.js b/Tutorials/P5JS/p5.js/09/9.19_p5.js_Prototypes/sketch.js index 035df79866..ce8f89b018 100644 --- a/Tutorials/P5JS/p5.js/09/9.19_p5.js_Prototypes/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.19_p5.js_Prototypes/sketch.js @@ -8,7 +8,7 @@ function Particle() { Particle.prototype.show = function() { point(this.x, this.y); -} +}; var p; var v; @@ -16,8 +16,8 @@ var v; p5.Vector.prototype.double = function() { this.x *= 2; this.y *= 2; - this.z *- 2; -} + this.z * -2; +}; function setup() { createCanvas(600, 600); @@ -26,6 +26,4 @@ function setup() { v = createVector(3, 4); } -function draw() { - -} \ No newline at end of file +function draw() {} diff --git a/Tutorials/P5JS/p5.js/09/9.20_p5.js_Polar_Coordinates/sketch.js b/Tutorials/P5JS/p5.js/09/9.20_p5.js_Polar_Coordinates/sketch.js index 02035814d5..48e64bc5a6 100644 --- a/Tutorials/P5JS/p5.js/09/9.20_p5.js_Polar_Coordinates/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.20_p5.js_Polar_Coordinates/sketch.js @@ -17,6 +17,6 @@ function draw() { var dx = r * cos(angle); var dy = r * sin(angle); - point(x+dx, y+dy); - line(x, y, x+dx, y + dy); -} \ No newline at end of file + point(x + dx, y + dy); + line(x, y, x + dx, y + dy); +} diff --git a/Tutorials/P5JS/p5.js/09/9.23_p5.js_creategraphics/sketch.js b/Tutorials/P5JS/p5.js/09/9.23_p5.js_creategraphics/sketch.js index 6c73f23481..83a1b5c0fd 100644 --- a/Tutorials/P5JS/p5.js/09/9.23_p5.js_creategraphics/sketch.js +++ b/Tutorials/P5JS/p5.js/09/9.23_p5.js_creategraphics/sketch.js @@ -37,5 +37,4 @@ function draw() { pop(); angle += 0.1; - } diff --git a/Tutorials/P5JS/p5.js/10/10.02_p5.js_what_is_JSON_pt1/libraries/p5.serialport.js b/Tutorials/P5JS/p5.js/10/10.02_p5.js_what_is_JSON_pt1/libraries/p5.serialport.js index 5b4e695b16..af9f6b753d 100644 --- a/Tutorials/P5JS/p5.js/10/10.02_p5.js_what_is_JSON_pt1/libraries/p5.serialport.js +++ b/Tutorials/P5JS/p5.js/10/10.02_p5.js_what_is_JSON_pt1/libraries/p5.serialport.js @@ -10,26 +10,22 @@ * Shawn Van Every (Shawn.Van.Every@nyu.edu) * ITP/NYU * LGPL - * + * * https://github.com/vanevery/p5.serialport * */ (function(root, factory) { if (typeof define === 'function' && define.amd) define('p5.serialport', ['p5'], function(p5) { - (factory(p5)); + factory(p5); }); - else if (typeof exports === 'object') - factory(require('../p5')); - else - factory(root['p5']); -}(this, function(p5) { - + else if (typeof exports === 'object') factory(require('../p5')); + else factory(root['p5']); +})(this, function(p5) { // ============================================================================= // p5.SerialPort // ============================================================================= - /* var serialPort = new SerialPort(); serialPort.open("/dev/tty-usbserial1", { @@ -44,7 +40,6 @@ * @constructor */ p5.SerialPort = function(_hostname, _serverport) { - var self = this; this.bufferSize = 1; // How much to buffer before sending data event @@ -55,7 +50,7 @@ this.serialport = null; this.serialoptions = null; - + this.emitQueue = []; this.serialportList = []; @@ -64,7 +59,7 @@ this.hostname = _hostname; } else { //console.log("typeof _hostname " + typeof _hostname + " setting to locahost"); - this.hostname = "localhost"; + this.hostname = 'localhost'; } if (typeof _serverport === 'number') { @@ -75,11 +70,13 @@ } try { - this.socket = new WebSocket("ws://" + this.hostname + ":" + this.serverport); - console.log(("ws://" + this.hostname + ":" + this.serverport)); + this.socket = new WebSocket( + 'ws://' + this.hostname + ':' + this.serverport + ); + console.log('ws://' + this.hostname + ':' + this.serverport); } catch (err) { //console.log(err + "\n" + "Is the p5.serialserver running?"); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { self.errorCallback("Couldn't connect to the server, is it running?"); } } @@ -88,18 +85,18 @@ console.log('opened socket'); serialConnected = true; - if (typeof self.connectedCallback !== "undefined") { + if (typeof self.connectedCallback !== 'undefined') { self.connectedCallback(); } - + if (self.emitQueue.length > 0) { - for (var i = 0; i < self.emitQueue.length; i ++){ + for (var i = 0; i < self.emitQueue.length; i++) { //console.log("queue: " + self.emitQueue[i]); self.emit(self.emitQueue[i]); } self.emitQueue = []; } - + /* Now handled by the queue if (self.serialport && self.serialoptions) { // If they have asked for a connect, these won't be null and we should try the connect now @@ -122,21 +119,21 @@ var messageObject = JSON.parse(event.data); // MESSAGE ROUTING - if (typeof messageObject.method !== "undefined") { + if (typeof messageObject.method !== 'undefined') { if (messageObject.method == 'echo') { //console.log("echo: " + messageObject.data); - } else if (messageObject.method === "openserial") { - if (typeof self.openCallback !== "undefined") { + } else if (messageObject.method === 'openserial') { + if (typeof self.openCallback !== 'undefined') { self.openCallback(); } - } else if (messageObject.method === "data") { + } else if (messageObject.method === 'data') { // Add to buffer, assuming this comes in byte by byte //console.log("data: " + JSON.stringify(messageObject.data)); self.serialBuffer.push(messageObject.data); - + //console.log(self.serialBuffer.length); - if (typeof self.dataCallback !== "undefined") { + if (typeof self.dataCallback !== 'undefined') { // Hand it to sketch if (self.serialBuffer.length >= self.bufferSize) { self.dataCallback(); @@ -144,31 +141,30 @@ //console.log(self.serialBuffer.length); } - if (typeof self.rawDataCallback !== "undefined") { + if (typeof self.rawDataCallback !== 'undefined') { self.rawDataCallback(messageObject.data); } } else if (messageObject.method === 'list') { - self.serialportList = messageObject.data; - if (typeof self.listCallback !== "undefined") { + if (typeof self.listCallback !== 'undefined') { self.listCallback(messageObject.data); } - } else if (messageObject.method === "write") { + } else if (messageObject.method === 'write') { // Success Callback? - } else if (messageObject.method === "error") { + } else if (messageObject.method === 'error') { //console.log(messageObject.data); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { // Hand it to sketch self.errorCallback(messageObject.data); } } else { // Got message from server without known method - console.log("Unknown Method: " + messageObject); + console.log('Unknown Method: ' + messageObject); } } else { - console.log("Method Undefined: " + messageObject); + console.log('Method Undefined: ' + messageObject); } }; @@ -176,7 +172,7 @@ //console.log("socketOnClose"); //console.log(event); - if (typeof self.closeCallback !== "undefined") { + if (typeof self.closeCallback !== 'undefined') { self.closeCallback(); } }; @@ -185,11 +181,10 @@ //console.log("socketOnError"); //console.log(event); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { self.errorCallback(); } }; - }; p5.SerialPort.prototype.emit = function(data) { @@ -201,8 +196,11 @@ }; p5.SerialPort.prototype.isConnected = function() { - if (self.serialConnected) { return true; } - else { return false; } + if (self.serialConnected) { + return true; + } else { + return false; + } }; // list() - list serial ports available to the server @@ -220,7 +218,6 @@ }; p5.SerialPort.prototype.open = function(_serialport, _serialoptions, cb) { - if (typeof cb === 'function') { this.openCallback = cb; } @@ -234,7 +231,7 @@ this.serialoptions = {}; } - // If our socket is connected, we'll do this now, + // If our socket is connected, we'll do this now, // otherwise it will happen in the socket.onopen callback this.emit({ method: 'openserial', @@ -248,10 +245,10 @@ p5.SerialPort.prototype.write = function(data) { //Writes bytes, chars, ints, bytes[], Strings to the serial port var toWrite = null; - if (typeof data == "number") { + if (typeof data == 'number') { // This is the only one I am treating differently, the rest of the clauses are meaningless toWrite = [data]; - } else if (typeof data == "string") { + } else if (typeof data == 'string') { toWrite = data; } else if (Array.isArray(data)) { toWrite = data; @@ -263,7 +260,7 @@ method: 'write', data: toWrite }); - //this.socket.send({method:'writeByte',data:data}); ? + //this.socket.send({method:'writeByte',data:data}); ? //this.socket.send({method:'writeString',data:data}) ? }; @@ -314,14 +311,17 @@ }; p5.SerialPort.prototype.readBytesUntil = function(charToFind) { - console.log("Looking for: " + charToFind.charCodeAt(0)); + console.log('Looking for: ' + charToFind.charCodeAt(0)); //Reads from the port into a buffer of bytes up to and including a particular character. If the character isn't in the buffer, 'null' is returned. The version with without the byteBuffer parameter returns a byte array of all data up to and including the interesting byte. This is not efficient, but is easy to use. The version with the byteBuffer parameter is more memory and time efficient. It grabs the data in the buffer and puts it into the byte array passed in and returns an int value for the number of bytes read. If the byte buffer is not large enough, -1 is returned and an error is printed to the message area. If nothing is in the buffer, 0 is returned. var index = this.serialBuffer.indexOf(charToFind.charCodeAt(0)); if (index !== -1) { // What to return var returnBuffer = this.serialBuffer.slice(0, index + 1); // Clear out what was returned - this.serialBuffer = this.serialBuffer.slice(index, this.serialBuffer.length + index); + this.serialBuffer = this.serialBuffer.slice( + index, + this.serialBuffer.length + index + ); return returnBuffer; } else { return -1; @@ -339,26 +339,27 @@ } // Clear the buffer this.serialBuffer.length = 0; - return stringBuffer.join(""); + return stringBuffer.join(''); }; p5.SerialPort.prototype.readStringUntil = function(stringToFind) { - var stringBuffer = []; //console.log("serialBuffer Length: " + this.serialBuffer.length); for (var i = 0; i < this.serialBuffer.length; i++) { //console.log("push: " + String.fromCharCode(this.serialBuffer[i])); stringBuffer.push(String.fromCharCode(this.serialBuffer[i])); } - stringBuffer = stringBuffer.join(""); + stringBuffer = stringBuffer.join(''); //console.log("stringBuffer: " + stringBuffer); - var returnString = ""; + var returnString = ''; var foundIndex = stringBuffer.indexOf(stringToFind); //console.log("found index: " + foundIndex); if (foundIndex > -1) { returnString = stringBuffer.substr(0, foundIndex); - this.serialBuffer = this.serialBuffer.slice(foundIndex + stringToFind.length); + this.serialBuffer = this.serialBuffer.slice( + foundIndex + stringToFind.length + ); } //console.log("Sending: " + returnString); return returnString; @@ -366,8 +367,8 @@ // readStringUntil("\r\n"); p5.SerialPort.prototype.readLine = function() { - return this.readStringUntil("\r\n"); - }; + return this.readStringUntil('\r\n'); + }; // TODO //p5.SerialPort.prototype.bufferUntil @@ -417,31 +418,31 @@ // Register callback methods from sketch p5.SerialPort.prototype.onData = function(_callback) { - this.on('data',_callback); + this.on('data', _callback); }; p5.SerialPort.prototype.onOpen = function(_callback) { - this.on('open',_callback); + this.on('open', _callback); }; p5.SerialPort.prototype.onClose = function(_callback) { - this.on('close',_callback); + this.on('close', _callback); }; p5.SerialPort.prototype.onError = function(_callback) { - this.on('error',_callback); + this.on('error', _callback); }; p5.SerialPort.prototype.onList = function(_callback) { - this.on('list',_callback); + this.on('list', _callback); }; p5.SerialPort.prototype.onConnected = function(_callback) { - this.on('connected',_callback); + this.on('connected', _callback); }; p5.SerialPort.prototype.onRawData = function(_callback) { - this.on('rawdata',_callback); + this.on('rawdata', _callback); }; // Version 2 @@ -462,6 +463,6 @@ this.rawDataCallback = _callback; } }; -})); +}); -// EOF \ No newline at end of file +// EOF diff --git a/Tutorials/P5JS/p5.js/10/10.02_p5.js_what_is_JSON_pt1/sketch.js b/Tutorials/P5JS/p5.js/10/10.02_p5.js_what_is_JSON_pt1/sketch.js index 62ab488ee6..8478569d2c 100644 --- a/Tutorials/P5JS/p5.js/10/10.02_p5.js_what_is_JSON_pt1/sketch.js +++ b/Tutorials/P5JS/p5.js/10/10.02_p5.js_what_is_JSON_pt1/sketch.js @@ -7,12 +7,12 @@ JSON Formatter & Validator (referred at 08:11) https://jsonformatter.curiousconc var flower; function preload() { - flower = loadJSON("flower.json"); + flower = loadJSON('flower.json'); } function setup() { createCanvas(400, 400); - + // flower = { // name: "sunflower", // col: color(200, 220, 0) @@ -23,5 +23,4 @@ function draw() { background(0); fill(flower.r, flower.g, flower.b); text(flower.name, 10, 50); - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/10/10.03_p5.js_what_is_JSON_pt2/libraries/p5.serialport.js b/Tutorials/P5JS/p5.js/10/10.03_p5.js_what_is_JSON_pt2/libraries/p5.serialport.js index 5b4e695b16..af9f6b753d 100644 --- a/Tutorials/P5JS/p5.js/10/10.03_p5.js_what_is_JSON_pt2/libraries/p5.serialport.js +++ b/Tutorials/P5JS/p5.js/10/10.03_p5.js_what_is_JSON_pt2/libraries/p5.serialport.js @@ -10,26 +10,22 @@ * Shawn Van Every (Shawn.Van.Every@nyu.edu) * ITP/NYU * LGPL - * + * * https://github.com/vanevery/p5.serialport * */ (function(root, factory) { if (typeof define === 'function' && define.amd) define('p5.serialport', ['p5'], function(p5) { - (factory(p5)); + factory(p5); }); - else if (typeof exports === 'object') - factory(require('../p5')); - else - factory(root['p5']); -}(this, function(p5) { - + else if (typeof exports === 'object') factory(require('../p5')); + else factory(root['p5']); +})(this, function(p5) { // ============================================================================= // p5.SerialPort // ============================================================================= - /* var serialPort = new SerialPort(); serialPort.open("/dev/tty-usbserial1", { @@ -44,7 +40,6 @@ * @constructor */ p5.SerialPort = function(_hostname, _serverport) { - var self = this; this.bufferSize = 1; // How much to buffer before sending data event @@ -55,7 +50,7 @@ this.serialport = null; this.serialoptions = null; - + this.emitQueue = []; this.serialportList = []; @@ -64,7 +59,7 @@ this.hostname = _hostname; } else { //console.log("typeof _hostname " + typeof _hostname + " setting to locahost"); - this.hostname = "localhost"; + this.hostname = 'localhost'; } if (typeof _serverport === 'number') { @@ -75,11 +70,13 @@ } try { - this.socket = new WebSocket("ws://" + this.hostname + ":" + this.serverport); - console.log(("ws://" + this.hostname + ":" + this.serverport)); + this.socket = new WebSocket( + 'ws://' + this.hostname + ':' + this.serverport + ); + console.log('ws://' + this.hostname + ':' + this.serverport); } catch (err) { //console.log(err + "\n" + "Is the p5.serialserver running?"); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { self.errorCallback("Couldn't connect to the server, is it running?"); } } @@ -88,18 +85,18 @@ console.log('opened socket'); serialConnected = true; - if (typeof self.connectedCallback !== "undefined") { + if (typeof self.connectedCallback !== 'undefined') { self.connectedCallback(); } - + if (self.emitQueue.length > 0) { - for (var i = 0; i < self.emitQueue.length; i ++){ + for (var i = 0; i < self.emitQueue.length; i++) { //console.log("queue: " + self.emitQueue[i]); self.emit(self.emitQueue[i]); } self.emitQueue = []; } - + /* Now handled by the queue if (self.serialport && self.serialoptions) { // If they have asked for a connect, these won't be null and we should try the connect now @@ -122,21 +119,21 @@ var messageObject = JSON.parse(event.data); // MESSAGE ROUTING - if (typeof messageObject.method !== "undefined") { + if (typeof messageObject.method !== 'undefined') { if (messageObject.method == 'echo') { //console.log("echo: " + messageObject.data); - } else if (messageObject.method === "openserial") { - if (typeof self.openCallback !== "undefined") { + } else if (messageObject.method === 'openserial') { + if (typeof self.openCallback !== 'undefined') { self.openCallback(); } - } else if (messageObject.method === "data") { + } else if (messageObject.method === 'data') { // Add to buffer, assuming this comes in byte by byte //console.log("data: " + JSON.stringify(messageObject.data)); self.serialBuffer.push(messageObject.data); - + //console.log(self.serialBuffer.length); - if (typeof self.dataCallback !== "undefined") { + if (typeof self.dataCallback !== 'undefined') { // Hand it to sketch if (self.serialBuffer.length >= self.bufferSize) { self.dataCallback(); @@ -144,31 +141,30 @@ //console.log(self.serialBuffer.length); } - if (typeof self.rawDataCallback !== "undefined") { + if (typeof self.rawDataCallback !== 'undefined') { self.rawDataCallback(messageObject.data); } } else if (messageObject.method === 'list') { - self.serialportList = messageObject.data; - if (typeof self.listCallback !== "undefined") { + if (typeof self.listCallback !== 'undefined') { self.listCallback(messageObject.data); } - } else if (messageObject.method === "write") { + } else if (messageObject.method === 'write') { // Success Callback? - } else if (messageObject.method === "error") { + } else if (messageObject.method === 'error') { //console.log(messageObject.data); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { // Hand it to sketch self.errorCallback(messageObject.data); } } else { // Got message from server without known method - console.log("Unknown Method: " + messageObject); + console.log('Unknown Method: ' + messageObject); } } else { - console.log("Method Undefined: " + messageObject); + console.log('Method Undefined: ' + messageObject); } }; @@ -176,7 +172,7 @@ //console.log("socketOnClose"); //console.log(event); - if (typeof self.closeCallback !== "undefined") { + if (typeof self.closeCallback !== 'undefined') { self.closeCallback(); } }; @@ -185,11 +181,10 @@ //console.log("socketOnError"); //console.log(event); - if (typeof self.errorCallback !== "undefined") { + if (typeof self.errorCallback !== 'undefined') { self.errorCallback(); } }; - }; p5.SerialPort.prototype.emit = function(data) { @@ -201,8 +196,11 @@ }; p5.SerialPort.prototype.isConnected = function() { - if (self.serialConnected) { return true; } - else { return false; } + if (self.serialConnected) { + return true; + } else { + return false; + } }; // list() - list serial ports available to the server @@ -220,7 +218,6 @@ }; p5.SerialPort.prototype.open = function(_serialport, _serialoptions, cb) { - if (typeof cb === 'function') { this.openCallback = cb; } @@ -234,7 +231,7 @@ this.serialoptions = {}; } - // If our socket is connected, we'll do this now, + // If our socket is connected, we'll do this now, // otherwise it will happen in the socket.onopen callback this.emit({ method: 'openserial', @@ -248,10 +245,10 @@ p5.SerialPort.prototype.write = function(data) { //Writes bytes, chars, ints, bytes[], Strings to the serial port var toWrite = null; - if (typeof data == "number") { + if (typeof data == 'number') { // This is the only one I am treating differently, the rest of the clauses are meaningless toWrite = [data]; - } else if (typeof data == "string") { + } else if (typeof data == 'string') { toWrite = data; } else if (Array.isArray(data)) { toWrite = data; @@ -263,7 +260,7 @@ method: 'write', data: toWrite }); - //this.socket.send({method:'writeByte',data:data}); ? + //this.socket.send({method:'writeByte',data:data}); ? //this.socket.send({method:'writeString',data:data}) ? }; @@ -314,14 +311,17 @@ }; p5.SerialPort.prototype.readBytesUntil = function(charToFind) { - console.log("Looking for: " + charToFind.charCodeAt(0)); + console.log('Looking for: ' + charToFind.charCodeAt(0)); //Reads from the port into a buffer of bytes up to and including a particular character. If the character isn't in the buffer, 'null' is returned. The version with without the byteBuffer parameter returns a byte array of all data up to and including the interesting byte. This is not efficient, but is easy to use. The version with the byteBuffer parameter is more memory and time efficient. It grabs the data in the buffer and puts it into the byte array passed in and returns an int value for the number of bytes read. If the byte buffer is not large enough, -1 is returned and an error is printed to the message area. If nothing is in the buffer, 0 is returned. var index = this.serialBuffer.indexOf(charToFind.charCodeAt(0)); if (index !== -1) { // What to return var returnBuffer = this.serialBuffer.slice(0, index + 1); // Clear out what was returned - this.serialBuffer = this.serialBuffer.slice(index, this.serialBuffer.length + index); + this.serialBuffer = this.serialBuffer.slice( + index, + this.serialBuffer.length + index + ); return returnBuffer; } else { return -1; @@ -339,26 +339,27 @@ } // Clear the buffer this.serialBuffer.length = 0; - return stringBuffer.join(""); + return stringBuffer.join(''); }; p5.SerialPort.prototype.readStringUntil = function(stringToFind) { - var stringBuffer = []; //console.log("serialBuffer Length: " + this.serialBuffer.length); for (var i = 0; i < this.serialBuffer.length; i++) { //console.log("push: " + String.fromCharCode(this.serialBuffer[i])); stringBuffer.push(String.fromCharCode(this.serialBuffer[i])); } - stringBuffer = stringBuffer.join(""); + stringBuffer = stringBuffer.join(''); //console.log("stringBuffer: " + stringBuffer); - var returnString = ""; + var returnString = ''; var foundIndex = stringBuffer.indexOf(stringToFind); //console.log("found index: " + foundIndex); if (foundIndex > -1) { returnString = stringBuffer.substr(0, foundIndex); - this.serialBuffer = this.serialBuffer.slice(foundIndex + stringToFind.length); + this.serialBuffer = this.serialBuffer.slice( + foundIndex + stringToFind.length + ); } //console.log("Sending: " + returnString); return returnString; @@ -366,8 +367,8 @@ // readStringUntil("\r\n"); p5.SerialPort.prototype.readLine = function() { - return this.readStringUntil("\r\n"); - }; + return this.readStringUntil('\r\n'); + }; // TODO //p5.SerialPort.prototype.bufferUntil @@ -417,31 +418,31 @@ // Register callback methods from sketch p5.SerialPort.prototype.onData = function(_callback) { - this.on('data',_callback); + this.on('data', _callback); }; p5.SerialPort.prototype.onOpen = function(_callback) { - this.on('open',_callback); + this.on('open', _callback); }; p5.SerialPort.prototype.onClose = function(_callback) { - this.on('close',_callback); + this.on('close', _callback); }; p5.SerialPort.prototype.onError = function(_callback) { - this.on('error',_callback); + this.on('error', _callback); }; p5.SerialPort.prototype.onList = function(_callback) { - this.on('list',_callback); + this.on('list', _callback); }; p5.SerialPort.prototype.onConnected = function(_callback) { - this.on('connected',_callback); + this.on('connected', _callback); }; p5.SerialPort.prototype.onRawData = function(_callback) { - this.on('rawdata',_callback); + this.on('rawdata', _callback); }; // Version 2 @@ -462,6 +463,6 @@ this.rawDataCallback = _callback; } }; -})); +}); -// EOF \ No newline at end of file +// EOF diff --git a/Tutorials/P5JS/p5.js/10/10.03_p5.js_what_is_JSON_pt2/sketch.js b/Tutorials/P5JS/p5.js/10/10.03_p5.js_what_is_JSON_pt2/sketch.js index c811a4df0a..e0fca66934 100644 --- a/Tutorials/P5JS/p5.js/10/10.03_p5.js_what_is_JSON_pt2/sketch.js +++ b/Tutorials/P5JS/p5.js/10/10.03_p5.js_what_is_JSON_pt2/sketch.js @@ -5,7 +5,7 @@ Video referenced (9:05)"createP from DOM" https://vimeo.com/142698165 */ var data; function preload() { - data = loadJSON("birds.json"); + data = loadJSON('birds.json'); } function setup() { @@ -22,4 +22,4 @@ function setup() { createDiv(members[j]); } } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/10/10.04_p5.js_Loading_JSON_from_URL/sketch.js b/Tutorials/P5JS/p5.js/10/10.04_p5.js_Loading_JSON_from_URL/sketch.js index edb95c244f..07b01ceffe 100644 --- a/Tutorials/P5JS/p5.js/10/10.04_p5.js_Loading_JSON_from_URL/sketch.js +++ b/Tutorials/P5JS/p5.js/10/10.04_p5.js_Loading_JSON_from_URL/sketch.js @@ -4,7 +4,7 @@ var spaceData; function setup() { createCanvas(200, 200); - loadJSON("http://api.open-notify.org/astros.json", gotData, 'jsonp'); + loadJSON('http://api.open-notify.org/astros.json', gotData, 'jsonp'); } function gotData(data) { @@ -13,7 +13,7 @@ function gotData(data) { function draw() { background(0); - + if (spaceData) { randomSeed(4); for (var i = 0; i < spaceData.number; i++) { @@ -28,4 +28,4 @@ function draw() { if (x > width) { x = 0; } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/10/10.05_p5.js_Working_With_APIs/sketch.js b/Tutorials/P5JS/p5.js/10/10.05_p5.js_Working_With_APIs/sketch.js index 009a2d7826..7c0e140527 100644 --- a/Tutorials/P5JS/p5.js/10/10.05_p5.js_Working_With_APIs/sketch.js +++ b/Tutorials/P5JS/p5.js/10/10.05_p5.js_Working_With_APIs/sketch.js @@ -2,8 +2,10 @@ var weather; function setup() { createCanvas(400, 200); - loadJSON('https://api.openweathermap.org/data/2.5/weather?q=London&APPID=001b0f58045147663b1ea518d34d88b4', gotData); - + loadJSON( + 'https://api.openweathermap.org/data/2.5/weather?q=London&APPID=001b0f58045147663b1ea518d34d88b4', + gotData + ); } function gotData(data) { @@ -14,7 +16,7 @@ function draw() { background(0); if (weather) { fill(255); - ellipse(100,100, weather.main.temp, weather.main.temp); - ellipse(300,100, weather.main.humidity, weather.main.humidity); + ellipse(100, 100, weather.main.temp, weather.main.temp); + ellipse(300, 100, weather.main.humidity, weather.main.humidity); } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/10/10.06_p5.js_api_query_user_input/sketch.js b/Tutorials/P5JS/p5.js/10/10.06_p5.js_api_query_user_input/sketch.js index dd41563954..cc6ff24b32 100644 --- a/Tutorials/P5JS/p5.js/10/10.06_p5.js_api_query_user_input/sketch.js +++ b/Tutorials/P5JS/p5.js/10/10.06_p5.js_api_query_user_input/sketch.js @@ -32,4 +32,4 @@ function draw() { ellipse(100, 100, temp, temp); ellipse(300, 100, humidity, humidity); } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/10/10.07_p5.js_API_Query_With_setTimeInterval/sketch.js b/Tutorials/P5JS/p5.js/10/10.07_p5.js_API_Query_With_setTimeInterval/sketch.js index 0c48f0eeba..a1a53d0b54 100644 --- a/Tutorials/P5JS/p5.js/10/10.07_p5.js_API_Query_With_setTimeInterval/sketch.js +++ b/Tutorials/P5JS/p5.js/10/10.07_p5.js_API_Query_With_setTimeInterval/sketch.js @@ -33,4 +33,4 @@ function draw() { if (lineX > width) { lineX = 0; } -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/10/10.08_p5.js_Wordnik_API/sketch.js b/Tutorials/P5JS/p5.js/10/10.08_p5.js_Wordnik_API/sketch.js index 0e67843f75..e135de5bc5 100644 --- a/Tutorials/P5JS/p5.js/10/10.08_p5.js_Wordnik_API/sketch.js +++ b/Tutorials/P5JS/p5.js/10/10.08_p5.js_Wordnik_API/sketch.js @@ -1,7 +1,7 @@ - -var url1 = "https://api.wordnik.com/v4/word.json/"; -var word = "rainbow"; -var url2 = "/relatedWords?useCanonical=false&limitPerRelationshopType=10&api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5"; +var url1 = 'https://api.wordnik.com/v4/word.json/'; +var word = 'rainbow'; +var url2 = + '/relatedWords?useCanonical=false&limitPerRelationshopType=10&api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5'; var link; function setup() { diff --git a/Tutorials/P5JS/p5.js/10/10.09_p5.js_New_York_Times_API/sketch.js b/Tutorials/P5JS/p5.js/10/10.09_p5.js_New_York_Times_API/sketch.js index 6ab663aa07..0cf994ba06 100644 --- a/Tutorials/P5JS/p5.js/10/10.09_p5.js_New_York_Times_API/sketch.js +++ b/Tutorials/P5JS/p5.js/10/10.09_p5.js_New_York_Times_API/sketch.js @@ -1,4 +1,5 @@ -var url = "https://api.nytimes.com/svc/search/v2/articlesearch.json?q=rainbow&api-key=99cfea65a5bb30650b3d31eb1713233e:15:73386102"; +var url = + 'https://api.nytimes.com/svc/search/v2/articlesearch.json?q=rainbow&api-key=99cfea65a5bb30650b3d31eb1713233e:15:73386102'; function setup() { noCanvas(); @@ -14,4 +15,4 @@ function gotData(data) { } //println(data.response.docs[0].headline.main); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/10/10.10_p5.js_giphy_api/sketch.js b/Tutorials/P5JS/p5.js/10/10.10_p5.js_giphy_api/sketch.js index 1a4c5fc6a2..02bcf476a9 100644 --- a/Tutorials/P5JS/p5.js/10/10.10_p5.js_giphy_api/sketch.js +++ b/Tutorials/P5JS/p5.js/10/10.10_p5.js_giphy_api/sketch.js @@ -1,7 +1,6 @@ -var api = "https://api.giphy.com/v1/gifs/search?"; -var apiKey = "&api_key=dc6zaTOxFJmzC"; -var query = "&q=rainbow"; - +var api = 'https://api.giphy.com/v1/gifs/search?'; +var apiKey = '&api_key=dc6zaTOxFJmzC'; +var query = '&q=rainbow'; function setup() { noCanvas(); @@ -13,5 +12,4 @@ function gotData(giphy) { for (var i = 0; i < giphy.data.length; i++) { createImg(giphy.data[i].images.original.url); } - -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js/16/16.03_p5.js_Arrow_Function/sketch.js b/Tutorials/P5JS/p5.js/16/16.03_p5.js_Arrow_Function/sketch.js index 29838d93c5..d0d8818ae4 100644 --- a/Tutorials/P5JS/p5.js/16/16.03_p5.js_Arrow_Function/sketch.js +++ b/Tutorials/P5JS/p5.js/16/16.03_p5.js_Arrow_Function/sketch.js @@ -24,5 +24,4 @@ class Counter { this.count++; this.p.html(this.count); } - } diff --git a/Tutorials/P5JS/p5.js_sound/17.11_FFT/sketch.js b/Tutorials/P5JS/p5.js_sound/17.11_FFT/sketch.js index d87ecd6daf..ff8750fba0 100644 --- a/Tutorials/P5JS/p5.js_sound/17.11_FFT/sketch.js +++ b/Tutorials/P5JS/p5.js_sound/17.11_FFT/sketch.js @@ -51,6 +51,4 @@ function draw() { //rect(i * w, y, w - 2, height - y); } //endShape(); - - } diff --git a/Tutorials/P5JS/p5.js_sound/17.1_playSong/sketch.js b/Tutorials/P5JS/p5.js_sound/17.1_playSong/sketch.js index f1cfc641e1..b452e93d77 100644 --- a/Tutorials/P5JS/p5.js_sound/17.1_playSong/sketch.js +++ b/Tutorials/P5JS/p5.js_sound/17.1_playSong/sketch.js @@ -9,7 +9,7 @@ var sliderPan; function setup() { createCanvas(200, 200); - song = loadSound("rainbow.mp3", loaded); + song = loadSound('rainbow.mp3', loaded); song.setVolume(0.5); sliderRate = createSlider(0, 1.5, 1, 0.01); sliderPan = createSlider(-1, 1, 0, 0.01); diff --git a/Tutorials/P5JS/p5.js_sound/17.2_pauseSong/sketch.js b/Tutorials/P5JS/p5.js_sound/17.2_pauseSong/sketch.js index 5046246d94..0f226215f4 100644 --- a/Tutorials/P5JS/p5.js_sound/17.2_pauseSong/sketch.js +++ b/Tutorials/P5JS/p5.js_sound/17.2_pauseSong/sketch.js @@ -8,8 +8,8 @@ var button; function setup() { createCanvas(200, 200); - song = loadSound("rainbow.mp3", loaded); - button = createButton("play"); + song = loadSound('rainbow.mp3', loaded); + button = createButton('play'); button.mousePressed(togglePlaying); background(51); } @@ -18,13 +18,13 @@ function togglePlaying() { if (!song.isPlaying()) { song.play(); song.setVolume(0.3); - button.html("pause"); + button.html('pause'); } else { song.stop(); - button.html("play"); + button.html('play'); } } function loaded() { - console.log("loaded"); + console.log('loaded'); } diff --git a/Tutorials/P5JS/p5.js_sound/17.3_cueSong/sketch.js b/Tutorials/P5JS/p5.js_sound/17.3_cueSong/sketch.js index cf25d19503..2864ac15d1 100644 --- a/Tutorials/P5JS/p5.js_sound/17.3_cueSong/sketch.js +++ b/Tutorials/P5JS/p5.js_sound/17.3_cueSong/sketch.js @@ -9,10 +9,10 @@ var jumpButton; function setup() { createCanvas(200, 200); - song = loadSound("rainbow.mp3", loaded); - button = createButton("play"); + song = loadSound('rainbow.mp3', loaded); + button = createButton('play'); button.mousePressed(togglePlaying); - jumpButton = createButton("jump"); + jumpButton = createButton('jump'); jumpButton.mousePressed(jumpSong); background(51); @@ -36,29 +36,19 @@ function draw() { //if (song.currentTime() > 5) { //background(song.currentTime() * 10, 0, 255); //} - - } - - - - - - - - function togglePlaying() { if (!song.isPlaying()) { song.play(); song.setVolume(0.3); - button.html("pause"); + button.html('pause'); } else { song.stop(); - button.html("play"); + button.html('play'); } } function loaded() { - console.log("loaded"); + console.log('loaded'); } diff --git a/Tutorials/P5JS/p5.js_sound/17.4_amplitudeSong/sketch.js b/Tutorials/P5JS/p5.js_sound/17.4_amplitudeSong/sketch.js index 00a6865c13..1bf36dba47 100644 --- a/Tutorials/P5JS/p5.js_sound/17.4_amplitudeSong/sketch.js +++ b/Tutorials/P5JS/p5.js_sound/17.4_amplitudeSong/sketch.js @@ -9,13 +9,13 @@ var amp; function setup() { createCanvas(200, 200); - song = loadSound("rainbow.mp3", loaded); + song = loadSound('rainbow.mp3', loaded); amp = new p5.Amplitude(); background(51); } function loaded() { - button = createButton("play"); + button = createButton('play'); button.mousePressed(togglePlaying); } @@ -29,14 +29,13 @@ function draw() { ellipse(width / 2, height / 2, diam, diam); } - function togglePlaying() { if (!song.isPlaying()) { song.play(); song.setVolume(0.3); - button.html("pause"); + button.html('pause'); } else { song.stop(); - button.html("play"); + button.html('play'); } } diff --git a/Tutorials/P5JS/p5.js_sound/17.5_snake_game_sound/sketch.js b/Tutorials/P5JS/p5.js_sound/17.5_snake_game_sound/sketch.js index 3009614a58..c75bedb074 100644 --- a/Tutorials/P5JS/p5.js_sound/17.5_snake_game_sound/sketch.js +++ b/Tutorials/P5JS/p5.js_sound/17.5_snake_game_sound/sketch.js @@ -23,10 +23,10 @@ var food; var musicRate = 1; function preload() { - eatSound = loadSound("sounds/Alert/Alert - 06.mp3"); - startOverSound = loadSound("sounds/Voice/Voice - Cartoon Laugh 01.mp3"); - hello = loadSound("sounds/Voice/Voice - Hello 01.mp3"); - music = loadSound("sounds/Music/Music - 01.mp3"); + eatSound = loadSound('sounds/Alert/Alert - 06.mp3'); + startOverSound = loadSound('sounds/Voice/Voice - Cartoon Laugh 01.mp3'); + hello = loadSound('sounds/Voice/Voice - Hello 01.mp3'); + music = loadSound('sounds/Music/Music - 01.mp3'); } function setup() { @@ -43,7 +43,6 @@ function setup() { // Pick a food location pickLocation(); - } // Pick a food location @@ -73,14 +72,10 @@ function draw() { // Draw snake s.show(); - fill(150, 255, 255); rect(food.x, food.y, scl, scl); } - - - // Moving the snake function keyPressed() { //if (!hello.isPlaying()) { diff --git a/Tutorials/P5JS/p5.js_sound/17.5_snake_game_sound/snake.js b/Tutorials/P5JS/p5.js_sound/17.5_snake_game_sound/snake.js index 3e4a0db8da..14aac64457 100644 --- a/Tutorials/P5JS/p5.js_sound/17.5_snake_game_sound/snake.js +++ b/Tutorials/P5JS/p5.js_sound/17.5_snake_game_sound/snake.js @@ -17,78 +17,77 @@ function Snake() { // Check to see if it is eating food this.eat = function(pos) { - var d = dist(this.x, this.y, pos.x, pos.y); - if (d < 1) { - this.total++; - return true; - } else { - return false; - } - } + var d = dist(this.x, this.y, pos.x, pos.y); + if (d < 1) { + this.total++; + return true; + } else { + return false; + } + }; // Set its direction this.dir = function(x, y) { - this.xspeed = x; - this.yspeed = y; - } + this.xspeed = x; + this.yspeed = y; + }; // Check to see if it hits itself this.death = function() { - for (var i = 0; i < this.tail.length; i++) { - var pos = this.tail[i]; - var d = dist(this.x, this.y, pos.x, pos.y); - if (d < 1) { - console.log('starting over'); - startOverSound.play(); - music.rate(1); - fr = 1; - this.x = 0; - this.y = 0; - this.xspeed = 1; - this.yspeed = 0; - this.total = 0; - this.tail = []; - } - } - } + for (var i = 0; i < this.tail.length; i++) { + var pos = this.tail[i]; + var d = dist(this.x, this.y, pos.x, pos.y); + if (d < 1) { + console.log('starting over'); + startOverSound.play(); + music.rate(1); + fr = 1; + this.x = 0; + this.y = 0; + this.xspeed = 1; + this.yspeed = 0; + this.total = 0; + this.tail = []; + } + } + }; // Update location this.update = function() { - // Expand snake - if (this.total === this.tail.length) { - for (var i = 0; i < this.tail.length - 1; i++) { - this.tail[i] = this.tail[i + 1]; - } - } - // Newest position - this.tail[this.total - 1] = createVector(this.x, this.y); + // Expand snake + if (this.total === this.tail.length) { + for (var i = 0; i < this.tail.length - 1; i++) { + this.tail[i] = this.tail[i + 1]; + } + } + // Newest position + this.tail[this.total - 1] = createVector(this.x, this.y); - // Move snake - this.x = this.x + this.xspeed * scl; - this.y = this.y + this.yspeed * scl; + // Move snake + this.x = this.x + this.xspeed * scl; + this.y = this.y + this.yspeed * scl; - // Keep on screen - if (this.x > width - scl) { - this.x = 0; - } else if (this.x < 0) { - this.x = width - scl; - } - if (this.y > height - scl) { - this.y = 0; - } else if (this.y < 0) { - this.y = height - scl; - } - } + // Keep on screen + if (this.x > width - scl) { + this.x = 0; + } else if (this.x < 0) { + this.x = width - scl; + } + if (this.y > height - scl) { + this.y = 0; + } else if (this.y < 0) { + this.y = height - scl; + } + }; // Draw snake this.show = function() { - for (var i = 0; i < this.tail.length; i++) { - var hu = map(i - 1, -1, this.tail.length, 0, 255); - fill(hu, 255, 255); - rect(this.tail[i].x, this.tail[i].y, scl, scl); - } - fill(255, 255, 255); - rect(this.x, this.y, scl, scl); - - } + for (var i = 0; i < this.tail.length; i++) { + var hu = map(i - 1, -1, this.tail.length, 0, 255); + fill(hu, 255, 255); + rect(this.tail[i].x, this.tail[i].y, scl, scl); + } + fill(255, 255, 255); + rect(this.x, this.y, scl, scl); + }; } diff --git a/Tutorials/P5JS/p5.js_sound/17.6_soundSynthesis/sketch.js b/Tutorials/P5JS/p5.js_sound/17.6_soundSynthesis/sketch.js index 073afc2540..d3cf832a23 100644 --- a/Tutorials/P5JS/p5.js_sound/17.6_soundSynthesis/sketch.js +++ b/Tutorials/P5JS/p5.js_sound/17.6_soundSynthesis/sketch.js @@ -19,7 +19,6 @@ function setup() { wave.freq(440); wave.amp(0); - button = createButton('play/pause'); button.mousePressed(toggle); } @@ -41,6 +40,4 @@ function toggle() { wave.amp(0, 1); playing = false; } - - } diff --git a/Tutorials/P5JS/p5.js_sound/17.7_soundEnvelope/sketch.js b/Tutorials/P5JS/p5.js_sound/17.7_soundEnvelope/sketch.js index 63c477e728..5a4e6a7ce0 100644 --- a/Tutorials/P5JS/p5.js_sound/17.7_soundEnvelope/sketch.js +++ b/Tutorials/P5JS/p5.js_sound/17.7_soundEnvelope/sketch.js @@ -23,8 +23,6 @@ function setup() { wave.freq(440); wave.amp(env); - - button = createButton('play'); button.mousePressed(toggle); } @@ -47,6 +45,4 @@ function toggle() { // wave.amp(0, 1); // playing = false; // } - - } diff --git a/Tutorials/P5JS/p5.js_video/11.1_p5.js_createCapture/sketch.js b/Tutorials/P5JS/p5.js_video/11.1_p5.js_createCapture/sketch.js index 285876443e..b00c649e8b 100644 --- a/Tutorials/P5JS/p5.js_video/11.1_p5.js_createCapture/sketch.js +++ b/Tutorials/P5JS/p5.js_video/11.1_p5.js_createCapture/sketch.js @@ -6,10 +6,9 @@ function setup() { video = createCapture(VIDEO); video.size(320, 240); // video.hide(); - } function draw() { tint(255, 0, 150); image(video, 0, 0, mouseX, height); -} \ No newline at end of file +} diff --git a/Tutorials/P5JS/p5.js_video/11.2_p5.js_photoBooth/sketch.js b/Tutorials/P5JS/p5.js_video/11.2_p5.js_photoBooth/sketch.js index 7bfc263f95..218922ead1 100644 --- a/Tutorials/P5JS/p5.js_video/11.2_p5.js_photoBooth/sketch.js +++ b/Tutorials/P5JS/p5.js_video/11.2_p5.js_photoBooth/sketch.js @@ -40,5 +40,3 @@ function draw() { } } } - - diff --git a/Tutorials/P5JS/p5.js_video/11.3_p5.js_pixels/sketch.js b/Tutorials/P5JS/p5.js_video/11.3_p5.js_pixels/sketch.js index 9d05aafe7d..837ce6124a 100644 --- a/Tutorials/P5JS/p5.js_video/11.3_p5.js_pixels/sketch.js +++ b/Tutorials/P5JS/p5.js_video/11.3_p5.js_pixels/sketch.js @@ -9,15 +9,12 @@ function draw() { loadPixels(); for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { - var index = (x + y * width)*4; - pixels[index+0] = x; - pixels[index+1] = random(255) ; - pixels[index+2] = y; - pixels[index+3] = 255; + var index = (x + y * width) * 4; + pixels[index + 0] = x; + pixels[index + 1] = random(255); + pixels[index + 2] = y; + pixels[index + 3] = 255; } } updatePixels(); - } - - diff --git a/Tutorials/P5JS/p5.js_video/11.4_p5.js_brightness_mirror/sketch.js b/Tutorials/P5JS/p5.js_video/11.4_p5.js_brightness_mirror/sketch.js index 8428de999b..d4fb04cd5e 100644 --- a/Tutorials/P5JS/p5.js_video/11.4_p5.js_brightness_mirror/sketch.js +++ b/Tutorials/P5JS/p5.js_video/11.4_p5.js_brightness_mirror/sketch.js @@ -6,7 +6,7 @@ function setup() { createCanvas(640, 480); pixelDensity(1); video = createCapture(VIDEO); - video.size(width/vScale, height/vScale); + video.size(width / vScale, height / vScale); } function draw() { @@ -16,23 +16,19 @@ function draw() { loadPixels(); for (var y = 0; y < video.height; y++) { for (var x = 0; x < video.width; x++) { - var index = (video.width - x + 1 + (y * video.width))*4; - var r = video.pixels[index+0]; - var g = video.pixels[index+1]; - var b = video.pixels[index+2]; + var index = (video.width - x + 1 + y * video.width) * 4; + var r = video.pixels[index + 0]; + var g = video.pixels[index + 1]; + var b = video.pixels[index + 2]; - var bright = (r+g+b)/3; + var bright = (r + g + b) / 3; var w = map(bright, 0, 255, 0, vScale); noStroke(); fill(255); rectMode(CENTER); - rect(x*vScale, y*vScale, w, w); - + rect(x * vScale, y * vScale, w, w); } } - } - - diff --git a/Tutorials/P5JS/p5.js_video/11.5_checkbox_mirror/sketch.js b/Tutorials/P5JS/p5.js_video/11.5_checkbox_mirror/sketch.js index 78ca7b1d7f..a84e138c16 100644 --- a/Tutorials/P5JS/p5.js_video/11.5_checkbox_mirror/sketch.js +++ b/Tutorials/P5JS/p5.js_video/11.5_checkbox_mirror/sketch.js @@ -25,19 +25,18 @@ function setup() { var linebreak = createSpan('
'); linebreak.parent('mirror'); } - } function draw() { video.loadPixels(); for (var y = 0; y < video.height; y++) { for (var x = 0; x < video.width; x++) { - var index = (video.width - x + 1 + (y * video.width))*4; - var r = video.pixels[index+0]; - var g = video.pixels[index+1]; - var b = video.pixels[index+2]; + var index = (video.width - x + 1 + y * video.width) * 4; + var r = video.pixels[index + 0]; + var g = video.pixels[index + 1]; + var b = video.pixels[index + 2]; - var bright = (r+g+b)/3; + var bright = (r + g + b) / 3; var threshold = slider.value(); @@ -50,7 +49,4 @@ function draw() { } } } - } - - diff --git a/Tutorials/P5JS/p5.js_video/11.6_p5.js_painting/particle.js b/Tutorials/P5JS/p5.js_video/11.6_p5.js_painting/particle.js index ff26ba04e7..e2bdef1887 100644 --- a/Tutorials/P5JS/p5.js_video/11.6_p5.js_painting/particle.js +++ b/Tutorials/P5JS/p5.js_video/11.6_p5.js_painting/particle.js @@ -5,15 +5,15 @@ function Particle(x, y) { this.x = x; this.y = y; this.r = random(4, 32); - + this.update = function() { this.x += random(-10, 10); this.y += random(-10, 10); - this.x = constrain(this.x, 0, width); - this.y = constrain(this.y, 0, height); - } - + this.x = constrain(this.x, 0, width); + this.y = constrain(this.y, 0, height); + }; + this.show = function() { noStroke(); var px = floor(this.x / vScale); @@ -21,7 +21,6 @@ function Particle(x, y) { var col = video.get(px, py); //console.log(col); fill(col[0], col[1], col[2], slider.value()); - ellipse(this.x, this.y, this.r, this.r); - } - -} \ No newline at end of file + ellipse(this.x, this.y, this.r, this.r); + }; +} diff --git a/Tutorials/P5JS/p5.js_video/11.6_p5.js_painting/sketch.js b/Tutorials/P5JS/p5.js_video/11.6_p5.js_painting/sketch.js index bf5e2fdb2e..8269bc524b 100644 --- a/Tutorials/P5JS/p5.js_video/11.6_p5.js_painting/sketch.js +++ b/Tutorials/P5JS/p5.js_video/11.6_p5.js_painting/sketch.js @@ -9,7 +9,7 @@ function setup() { createCanvas(640, 480); pixelDensity(1); video = createCapture(VIDEO); - video.size(width/vScale, height/vScale); + video.size(width / vScale, height / vScale); for (var i = 0; i < 200; i++) { particles[i] = new Particle(random(width), random(height)); } @@ -20,10 +20,8 @@ function setup() { function draw() { background(51); video.loadPixels(); - for(var i = 0; i < particles.length; i++) { + for (var i = 0; i < particles.length; i++) { particles[i].update(); particles[i].show(); } } - - diff --git a/Tutorials/P5JS/p5.js_video/11.7_p5.js_slitscan/sketch.js b/Tutorials/P5JS/p5.js_video/11.7_p5.js_slitscan/sketch.js index 05e5784658..b86f76ccd3 100644 --- a/Tutorials/P5JS/p5.js_video/11.7_p5.js_slitscan/sketch.js +++ b/Tutorials/P5JS/p5.js_video/11.7_p5.js_slitscan/sketch.js @@ -17,14 +17,11 @@ function draw() { var w = video.width; var h = video.height; - copy(video, w/2, 0, 1, h, x, 0, 1, h); + copy(video, w / 2, 0, 1, h, x, 0, 1, h); x = x + 1; - + if (x > width) { x = 0; } - - } - diff --git a/Tutorials/P5JS/p5.js_video/11.8_p5.js_seriously/sketch.js b/Tutorials/P5JS/p5.js_video/11.8_p5.js_seriously/sketch.js index 244a4e33f4..5922e28c84 100644 --- a/Tutorials/P5JS/p5.js_video/11.8_p5.js_seriously/sketch.js +++ b/Tutorials/P5JS/p5.js_video/11.8_p5.js_seriously/sketch.js @@ -27,16 +27,7 @@ function setup() { var r = 98 / 255; var g = 175 / 255; var b = 116 / 255; - chroma.screen = [r,g,b,1]; - - - - + chroma.screen = [r, g, b, 1]; seriously.go(); - - - } - - diff --git a/Tutorials/Processing/11_video/sketch_11_9_BlobTrackingIDs_js/blob.js b/Tutorials/Processing/11_video/sketch_11_9_BlobTrackingIDs_js/blob.js index 37dfe7fb17..b971276eeb 100644 --- a/Tutorials/Processing/11_video/sketch_11_9_BlobTrackingIDs_js/blob.js +++ b/Tutorials/Processing/11_video/sketch_11_9_BlobTrackingIDs_js/blob.js @@ -4,7 +4,6 @@ // Code for: https://youtu.be/r0lvsMPGEoY class Blob { - constructor(x, y) { this.minx = x; this.miny = y; @@ -27,7 +26,6 @@ class Blob { text(this.id, this.minx + (this.maxx - this.minx) * 0.5, this.maxy - 10); } - add(x, y) { this.minx = min(this.minx, x); this.miny = min(this.miny, y); @@ -62,4 +60,4 @@ class Blob { return false; } } -} \ No newline at end of file +} diff --git a/Tutorials/Processing/11_video/sketch_11_9_BlobTrackingIDs_js/sketch.js b/Tutorials/Processing/11_video/sketch_11_9_BlobTrackingIDs_js/sketch.js index a14643fc29..97ebe9156e 100644 --- a/Tutorials/Processing/11_video/sketch_11_9_BlobTrackingIDs_js/sketch.js +++ b/Tutorials/Processing/11_video/sketch_11_9_BlobTrackingIDs_js/sketch.js @@ -21,7 +21,6 @@ function setup() { trackColor = color(183, 12, 83); } - function keyPressed() { if (key == 'a') { distThreshold += 5; @@ -82,7 +81,7 @@ function draw() { // There are no blobs! if (blobs.length < 1 && currentBlobs.length > 0) { - print("Adding blobs!"); + print('Adding blobs!'); for (let b of currentBlobs) { b.id = blobCounter; blobs.push(b); @@ -119,7 +118,6 @@ function draw() { b.taken = false; } - // Match whatever blobs you can match for (let cb of currentBlobs) { let recordD = 1000; @@ -151,19 +149,16 @@ function draw() { b.show(); } - - textAlign(RIGHT); fill(0); noStroke(); //text(currentBlobs.size(), width-10, 40); //text(blobs.size(), width-10, 80); textSize(12); - text("color threshold: " + threshold, width - 10, 50); - text("distance threshold: " + distThreshold, width - 10, 25); + text('color threshold: ' + threshold, width - 10, 50); + text('distance threshold: ' + distThreshold, width - 10, 25); } - function distSq(a1, b1, c1, a2, b2, c2) { let x1, y1, z1, x2, y2, z2; if (arguments.length == 4) { @@ -181,16 +176,19 @@ function distSq(a1, b1, c1, a2, b2, c2) { y2 = b2; z2 = c2; } - const d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z1 - z2) * (z1 - z2); + const d = + (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z1 - z2) * (z1 - z2); return d; } - - function mousePressed() { // Save color where the mouse is clicked in trackColor variable video.loadPixels(); const loc = (mouseX + mouseY * video.width) * 4; - trackColor = color(video.pixels[loc], video.pixels[loc + 1], video.pixels[loc + 2]); + trackColor = color( + video.pixels[loc], + video.pixels[loc + 1], + video.pixels[loc + 2] + ); console.log(trackColor); -} \ No newline at end of file +} diff --git a/package.json b/package.json index fa6601b341..cb0c5510bb 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,12 @@ "lint-cc": "./node_modules/.bin/eslint ./CodingChallenges/", "lint-cabana": "./node_modules/.bin/eslint ./CodingInTheCabana/", "lint-tutorials": "./node_modules/.bin/eslint ./Tutorials/", - "lint-courses": "./node_modules/.bin/eslint ./Courses/" + "lint-courses": "./node_modules/.bin/eslint ./Courses/", + "lint-fix": "npm run lint-cc-fix && npm run lint-cabana-fix && npm run lint-tutorials-fix && npm run lint-courses-fix", + "lint-cc-fix": "./node_modules/.bin/eslint ./CodingChallenges/ --fix", + "lint-cabana-fix": "./node_modules/.bin/eslint ./CodingInTheCabana/ --fix", + "lint-tutorials-fix": "./node_modules/.bin/eslint ./Tutorials/ --fix", + "lint-courses-fix": "./node_modules/.bin/eslint ./Courses/ --fix" }, "repository": { "type": "git",