forked from CodingTrain/website-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding page for coding challenge 159 (CodingTrain#3064)
* spelling fix * Adding page for CC159 * adding lint exception * Update 159-simple-pendulum-simulation.md Co-authored-by: Daniel Shiffman <[email protected]>
- Loading branch information
1 parent
a68a039
commit 46ca712
Showing
8 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
CodingChallenges/CC_159_simple_pendulum_simulation/P5/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,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.min.js"></script> | ||
|
||
<meta charset="utf-8" /> | ||
</head> | ||
|
||
<body> | ||
<script src="sketch.js"></script> | ||
</body> | ||
|
||
</html> |
44 changes: 44 additions & 0 deletions
44
CodingChallenges/CC_159_simple_pendulum_simulation/P5/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,44 @@ | ||
// Simple Pendulum Simulation | ||
// The Coding Train / Daniel Shiffman | ||
// https://thecodingtrain.com/CodingChallenges/159-simple-pendulum-simulation.html | ||
// https://youtu.be/NBWMtlbbOag | ||
// https://editor.p5js.org/codingtrain/sketches/SN-39sHAC | ||
|
||
let angle; | ||
|
||
let angleV = 0; | ||
let angleA = 0; | ||
|
||
let bob; | ||
let len; | ||
let origin; | ||
|
||
let gravity = 1; | ||
|
||
function setup() { | ||
createCanvas(600, 800); | ||
origin = createVector(300, 0); | ||
angle = PI / 4; | ||
bob = createVector(); | ||
len = 200; | ||
} | ||
|
||
function draw() { | ||
background(0); | ||
|
||
let force = gravity * sin(angle); | ||
angleA = (-1 * force) / len; | ||
angleV += angleA; | ||
angle += angleV; | ||
|
||
// angleV *= 0.99; | ||
|
||
bob.x = len * sin(angle) + origin.x; | ||
bob.y = len * cos(angle) + origin.y; | ||
|
||
stroke(255); | ||
strokeWeight(8); | ||
fill(127); | ||
line(origin.x, origin.y, bob.x, bob.y); | ||
circle(bob.x, bob.y, 64); | ||
} |
44 changes: 44 additions & 0 deletions
44
...lation/Processing/cc_159_simple_pendulum_simulation/cc_159_simple_pendulum_simulation.pde
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,44 @@ | ||
// Simple Pendulum Simulation | ||
// The Coding Train / Daniel Shiffman | ||
// https://thecodingtrain.com/CodingChallenges/159-simple-pendulum-simulation.html | ||
// https://youtu.be/NBWMtlbbOag | ||
// https://editor.p5js.org/codingtrain/sketches/SN-39sHAC | ||
|
||
float angle; | ||
|
||
float angleV = 0; | ||
float angleA = 0; | ||
|
||
PVector bob; | ||
float len; | ||
PVector origin; | ||
|
||
float gravity = 1; | ||
|
||
void setup() { | ||
size(600, 800); | ||
origin = new PVector(300, 0); | ||
angle = PI/4; | ||
bob = new PVector(); | ||
len = 200; | ||
} | ||
|
||
void draw() { | ||
background(0); | ||
|
||
float force = gravity * sin(angle); | ||
angleA = (-1 * force) / len; | ||
angleV += angleA; | ||
angle += angleV; | ||
|
||
// angleV *= 0.99 | ||
|
||
bob.x = len * sin(angle) + origin.x; | ||
bob.y = len * cos(angle) + origin.y; | ||
|
||
stroke(255); | ||
strokeWeight(8); | ||
fill(127); | ||
line(origin.x, origin.y, bob.x, bob.y); | ||
circle(bob.x, bob.y, 64); | ||
} |
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,73 @@ | ||
--- | ||
title: "Simple Pendulum Simulation" | ||
video_number: 159 | ||
date: 2021-02-16 | ||
video_id: NBWMtlbbOag | ||
web_editor: SN-39sHAC | ||
repository: CC_159_simple_pendulum_simulation | ||
|
||
links: | ||
- title: "Nature of Code Playlist" | ||
url: /learning/nature-of-code/index | ||
- title: "Applications of Differential Equations - The Simple Pendulum" | ||
author: "San Joaquin Delta College" | ||
url: http://calculuslab.deltacollege.edu/ODE/7-A-2/7-A-2-h.html | ||
- title: "Simple Pendulum (myPhysicsLab.com)" | ||
url: https://www.myphysicslab.com/pendulum/pendulum-en.html | ||
- title: "Object Oriented Simple Pendulum (Nature of Code Book)" | ||
url: https://github.com/nature-of-code/noc-examples-p5.js/tree/master/chp03_oscillation/NOC_3_10_PendulumExampleSimplified | ||
|
||
videos: | ||
- title: "Polar Coordinates - Nature of Code" | ||
author: "The Coding Train" | ||
url: /learning/nature-of-code/3.4-polar-coordinates | ||
- title: "3.2 Angular Motion - Nature of Code" | ||
author: "The Coding Train" | ||
url: /learning/nature-of-code/3.2-angular-motion | ||
- title: "Double Pendulum - Coding Challenge #93" | ||
author: "The Coding Train" | ||
url: /CodingChallenges/093-double-pendulum | ||
- title: "Coding Train Live! (February 6th 2021)" | ||
author: "The Coding Train" | ||
video_id: dpqNqyQCcbY | ||
|
||
topics: | ||
- title: "Choo choo!! 2021 Coding Challenge!" | ||
time: "0:00" | ||
- title: "Code! Drawing a bob and an arm." | ||
time: "0:43" | ||
- title: "Explain! How are we going to think about this?" | ||
time: "1:08" | ||
- title: "Code! Add our main variables." | ||
time: "2:55" | ||
- title: "Explain! How do we figure out where the bob is? Trigonometry is the answer!" | ||
time: "3:20" | ||
- title: "Code! Use the polar coordinates formulas we just worked out." | ||
time: "4:39" | ||
- title: "Code! Let's use angular motion!" | ||
time: "6:30" | ||
- title: "Explain! What is the force of the pendulum? Trigonometry is the answer!" | ||
time: "7:55" | ||
- title: "Code! Add the pendulum force." | ||
time: "10:46" | ||
- title: "Whoops! Correction on why we multiply by -1." | ||
time: "12:04" | ||
- title: "Code! Add -1 to the formula." | ||
time: "13:34" | ||
- title: "Whoops! I figured out some things that I never really understood." | ||
time: "13:57" | ||
- title: "Code! Correct the 3 step process." | ||
time: "14:24" | ||
- title: "Something doesn't feel quite right." | ||
time: "15:32" | ||
- title: "Explain! Angular acceleration relates to the arm length!" | ||
time: "16:59" | ||
- title: "Code! Let's divide by length." | ||
time: "18:58" | ||
- title: "Code! You could add some damping." | ||
time: "19:54" | ||
- title: "Ideas! What could you do next?" | ||
time: "20:21" | ||
--- | ||
|
||
Choo choo! In this challenge, I build on chapter 3 (Oscillating Motion) of the Nature of Code series and simulate a simple pendulum in p5.js via angular acceleration. |
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
File renamed without changes.
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