-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #335 from nature-of-code/notion-update-docs
[Notion] edits and rewritings for 6 and 9, also 4 and 7
- Loading branch information
Showing
38 changed files
with
1,364 additions
and
671 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
content/examples/06_libraries/soft_body_character_copy/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/gh/hapticdata/[email protected]/build/toxiclibs.js"></script> | ||
<link rel="stylesheet" type="text/css" href="style.css" /> | ||
</head> | ||
<body> | ||
<script src="sketch.js"></script> | ||
<script src="particle.js"></script> | ||
<script src="spring.js"></script> | ||
</body> | ||
</html> |
13 changes: 13 additions & 0 deletions
13
content/examples/06_libraries/soft_body_character_copy/particle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Particle extends VerletParticle2D { | ||
constructor(x, y) { | ||
super(x, y); | ||
this.r = 4; | ||
physics.addParticle(this); | ||
} | ||
|
||
show() { | ||
fill(0); | ||
stroke(0); | ||
circle(this.x, this.y, this.r * 2); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
content/examples/06_libraries/soft_body_character_copy/sketch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Coding Train / Daniel Shiffman | ||
|
||
const { VerletPhysics2D, VerletParticle2D, VerletSpring2D } = toxi.physics2d; | ||
|
||
const { GravityBehavior } = toxi.physics2d.behaviors; | ||
|
||
const { Vec2D, Rect } = toxi.geom; | ||
|
||
let physics; | ||
|
||
let particles = []; | ||
let springs = []; | ||
|
||
function setup() { | ||
createCanvas(640, 240); | ||
|
||
physics = new VerletPhysics2D(); | ||
|
||
let bounds = new Rect(0, 0, width, height); | ||
physics.setWorldBounds(bounds); | ||
physics.addBehavior(new GravityBehavior(new Vec2D(0, 0.5))); | ||
|
||
particles.push(new Particle(200, 25)); | ||
particles.push(new Particle(400, 25)); | ||
particles.push(new Particle(350, 125)); | ||
particles.push(new Particle(400, 225)); | ||
particles.push(new Particle(200, 225)); | ||
particles.push(new Particle(250, 125)); | ||
|
||
springs.push(new Spring(particles[0], particles[1])); | ||
springs.push(new Spring(particles[1], particles[2])); | ||
springs.push(new Spring(particles[2], particles[3])); | ||
springs.push(new Spring(particles[3], particles[4])); | ||
springs.push(new Spring(particles[4], particles[5])); | ||
springs.push(new Spring(particles[5], particles[0])); | ||
springs.push(new Spring(particles[5], particles[2])); | ||
springs.push(new Spring(particles[0], particles[3])); | ||
springs.push(new Spring(particles[1], particles[4])); | ||
} | ||
|
||
function draw() { | ||
background(255); | ||
|
||
physics.update(); | ||
|
||
fill(127); | ||
stroke(0); | ||
strokeWeight(2); | ||
beginShape(); | ||
for (let particle of particles) { | ||
vertex(particle.x, particle.y); | ||
} | ||
endShape(CLOSE); | ||
|
||
if (mouseIsPressed) { | ||
particles[0].lock(); | ||
particles[0].x = mouseX; | ||
particles[0].y = mouseY; | ||
particles[0].unlock(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
content/examples/06_libraries/soft_body_character_copy/spring.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Spring extends VerletSpring2D { | ||
constructor(a, b, strength) { | ||
let length = dist(a.x, a.y, b.x, b.y); | ||
super(a, b, length, 0.01); | ||
physics.addSpring(this); | ||
} | ||
|
||
show() { | ||
stroke(0); | ||
line(this.a.x, this.a.y, this.b.x, this.b.y); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
content/examples/06_libraries/soft_body_character_copy/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
html, body { | ||
margin: 0; | ||
padding: 0; | ||
} |
13 changes: 13 additions & 0 deletions
13
content/examples/06_libraries/soft_body_character_enhanced_copy/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/gh/hapticdata/[email protected]/build/toxiclibs.js"></script> | ||
<link rel="stylesheet" type="text/css" href="style.css" /> | ||
</head> | ||
<body> | ||
<script src="sketch.js"></script> | ||
<script src="particle.js"></script> | ||
<script src="spring.js"></script> | ||
</body> | ||
</html> |
16 changes: 16 additions & 0 deletions
16
content/examples/06_libraries/soft_body_character_enhanced_copy/particle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Particle extends VerletParticle2D { | ||
constructor(x, y) { | ||
super(x, y); | ||
this.r = 2; | ||
physics.addParticle(this); | ||
} | ||
|
||
show() { | ||
fill(252, 238, 33); | ||
strokeWeight(1); | ||
circle(this.x, this.y, this.r * 12); | ||
|
||
strokeWeight(this.r * 4); | ||
point(this.x, this.y); | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
content/examples/06_libraries/soft_body_character_enhanced_copy/sketch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// Coding Train / Daniel Shiffman | ||
|
||
const { VerletPhysics2D, VerletParticle2D, VerletSpring2D } = toxi.physics2d; | ||
|
||
const { GravityBehavior } = toxi.physics2d.behaviors; | ||
|
||
const { Vec2D, Rect } = toxi.geom; | ||
|
||
let physics; | ||
|
||
let particles = []; | ||
let eyes = []; | ||
let springs = []; | ||
|
||
let showSprings = false; | ||
|
||
function keyPressed() { | ||
if (key == ' ') { | ||
showSprings = !showSprings; | ||
} | ||
} | ||
|
||
function setup() { | ||
createCanvas(640, 240); | ||
|
||
physics = new VerletPhysics2D(); | ||
|
||
let bounds = new Rect(0, 0, width, height); | ||
physics.setWorldBounds(bounds); | ||
|
||
particles.push(new Particle(200, 25)); | ||
particles.push(new Particle(250, 25)); | ||
particles.push(new Particle(300, 25)); | ||
particles.push(new Particle(350, 25)); | ||
particles.push(new Particle(400, 25)); | ||
particles.push(new Particle(350, 125)); | ||
particles.push(new Particle(400, 225)); | ||
particles.push(new Particle(350, 225)); | ||
particles.push(new Particle(300, 225)); | ||
particles.push(new Particle(250, 225)); | ||
particles.push(new Particle(200, 225)); | ||
particles.push(new Particle(250, 125)); | ||
|
||
eyes.push(new Particle(275, 75)); | ||
eyes.push(new Particle(325, 75)); | ||
eyes.push(new Particle(250, -25)); | ||
eyes.push(new Particle(350, -25)); | ||
|
||
for (let i = 0; i < particles.length; i++) { | ||
for (let j = i + 1; j < particles.length; j++) { | ||
if (i !== j) { | ||
let a = particles[i]; | ||
let b = particles[j]; | ||
// let b = particles[(i + 1) % particles.length]; | ||
springs.push(new Spring(a, b)); | ||
} | ||
} | ||
} | ||
|
||
for (let particle of particles) { | ||
springs.push(new Spring(particle, eyes[0])); | ||
springs.push(new Spring(particle, eyes[1])); | ||
} | ||
|
||
springs.push(new Spring(eyes[2], particles[1])); | ||
springs.push(new Spring(eyes[3], particles[3])); | ||
|
||
springs.push(new Spring(eyes[2], particles[3])); | ||
springs.push(new Spring(eyes[3], particles[1])); | ||
|
||
springs.push(new Spring(eyes[2], particles[0])); | ||
springs.push(new Spring(eyes[3], particles[4])); | ||
|
||
springs.push(new Spring(eyes[3], particles[2])); | ||
springs.push(new Spring(eyes[2], particles[2])); | ||
|
||
springs.push(new Spring(eyes[2], eyes[3])); | ||
|
||
springs.push(new Spring(eyes[0], eyes[3])); | ||
springs.push(new Spring(eyes[0], eyes[2])); | ||
springs.push(new Spring(eyes[1], eyes[2])); | ||
springs.push(new Spring(eyes[1], eyes[3])); | ||
} | ||
|
||
function draw() { | ||
background(255); | ||
|
||
physics.update(); | ||
|
||
stroke(112, 50, 126); | ||
if (showSprings) stroke(112, 50, 126, 100); | ||
|
||
strokeWeight(4); | ||
line(particles[1].x, particles[1].y, eyes[2].x, eyes[2].y); | ||
line(particles[3].x, particles[3].y, eyes[3].x, eyes[3].y); | ||
strokeWeight(16); | ||
point(eyes[2].x, eyes[2].y); | ||
point(eyes[3].x, eyes[3].y); | ||
|
||
fill(45, 197, 244); | ||
if (showSprings) fill(45, 197, 244, 100); | ||
strokeWeight(2); | ||
beginShape(); | ||
for (let particle of particles) { | ||
vertex(particle.x, particle.y); | ||
} | ||
endShape(CLOSE); | ||
|
||
// fill(127, 127); | ||
// stroke(0); | ||
// strokeWeight(2); | ||
// beginShape(); | ||
// for (let particle of particles) { | ||
// vertex(particle.x, particle.y); | ||
// } | ||
// endShape(CLOSE); | ||
|
||
// for (let particle of particles) { | ||
// particle.show(); | ||
// } | ||
|
||
eyes[0].show(); | ||
eyes[1].show(); | ||
|
||
// for (let eye of eyes) { | ||
// eye.show(); | ||
// } | ||
|
||
if (showSprings) { | ||
for (let spring of springs) { | ||
spring.show(); | ||
} | ||
} | ||
|
||
if (mouseIsPressed) { | ||
particles[0].lock(); | ||
particles[0].x = mouseX; | ||
particles[0].y = mouseY; | ||
particles[0].unlock(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
content/examples/06_libraries/soft_body_character_enhanced_copy/spring.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Spring extends VerletSpring2D { | ||
constructor(a, b, strength) { | ||
let length = dist(a.x, a.y, b.x, b.y); | ||
super(a, b, length, 0.001); | ||
physics.addSpring(this); | ||
} | ||
|
||
show() { | ||
strokeWeight(1); | ||
stroke(0, 127); | ||
line(this.a.x, this.a.y, this.b.x, this.b.y); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
content/examples/06_libraries/soft_body_character_enhanced_copy/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
html, body { | ||
margin: 0; | ||
padding: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.