Coding Challenge
Vložit
- čas přidán 5. 08. 2024
- 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. thecodingtrain.com/challenges...
🕹️ p5.js Simple Pendulum editor.p5js.org/codingtrain/s...
🕹️ p5.js OOP Pendulum: editor.p5js.org/codingtrain/s...
🕹️ p5.js Pendulum Array: editor.p5js.org/codingtrain/s...
🎥 Pendulum Array Exploration: • Coding Train Live!
🎥 Previous Coding Challenge: • Coding Challenge #158:...
🎥 Next Coding Challenge: • Coding Challenge #160:...
🎥 All Coding Challenges: • Coding Challenges
🎥 Previous Nature of Code Video: • 3.7: Additive Waves - ...
🎥 Next Nature of Code Video: • Coding Challenge #160:...
🎥 All Nature of Code Videos: • The Nature of Code
Links discussed in this video:
🔗 Nature of Code Playlist: thecodingtrain.com/learning/n...
🔗 Applications of Differential Equations - The Simple Pendulum: calculuslab.deltacollege.edu/O...
🔗 Simple Pendulum (myPhysicsLab.com): www.myphysicslab.com/pendulum...
🔗 Object Oriented Simple Pendulum (Nature of Code Book): github.com/nature-of-code/noc...
Other videos mentioned in this video:
🎥 Polar Coordinates - Nature of Code: • 3.4 Polar Coordinates ...
🎥 3.2 Angular Motion - Nature of Code: • 3.2 Angular Motion - N...
🎥 Double Pendulum - Coding Challenge #93: • Coding Challenge 93: D...
🎥 Coding Train Live! (February 6th 2021): • Coding Train Live!
Timestamps:
0:00 Choo choo!! 2021 Coding Challenge!
0:43 Code! Drawing a bob and an arm.
1:08 Explain! How are we going to think about this?
2:55 Code! Add our main variables.
3:20 Explain! How do we figure out where the bob is? Trigonometry is the answer!
4:39 Code! Use the polar coordinates formulas we just worked out.
6:30 Code! Let's use angular motion!
7:55 Explain! What is the force of the pendulum? Trigonometry is the answer!
10:46 Code! Add the pendulum force.
12:04 Whoops! Correction on why we multiply by -1.
13:34 Code! Add -1 to the formula.
13:57 Whoops! I figured out some things that I never really understood.
14:24 Code! Correct the 3 step process.
15:32 Something doesn't feel quite right.
16:59 Explain! Angular acceleration relates to the arm length!
18:58 Code! Let's divide by length.
19:54 Code! You could add some damping.
20:21 Ideas! What could you do next?
🚂 Website: thecodingtrain.com/
👾 Share Your Creation! thecodingtrain.com/Guides/com...
🚩 Suggest Topics: github.com/CodingTrain/Rainbo...
💡 GitHub: github.com/CodingTrain
💬 Discord: / discord
💖 Membership: czcams.com/users/thecodingtrainjoin
🛒 Store: standard.tv/codingtrain
📚 Books: www.amazon.com/shop/thecoding...
🖋️ Twitter: / thecodingtrain
📸 Instagram: / the.coding.train
🎥 Coding Challenges: • Coding Challenges
🎥 Intro to Programming: • Start learning here!
🔗 p5.js: p5js.org
🔗 p5.js Web Editor: editor.p5js.org/
🔗 Processing: processing.org
📄 Code of Conduct: github.com/CodingTrain/Code-o...
I'm so happy that you exist, Daniel.
Few days ago I was wondering how could I create something like that and this video just appeared in my recommendations today, I didn't even search about anything related to that in google, I'm getting convinced google is able to read my mind or something.
Always nice to watch another Coding Train with Dan. Much love from Brazil! 🇧🇷 :)
13:50 my childhood experiment while standing on swing in the park😎
Please please dont stop making videos ever , im so glad that you exist ♥️
Thank you for this amazing video. Thanks for sharing you own learning and discovery with those entertaining correction clips. It encourages me to keep improving my understanding of things I am familiar with, but really don't know as well as I should.
So well explained, I love your nature of code series!
Now I know the science behind a pendulum
I was thinking something similar: I noticed that this seems much more applicable than what we learn in Physics class. If we could learn it in programming classes, then we ought to be given transferable credits.
@@eugenetswong
It was in this particular video that I realized I could actually learn things that arent code while learning to code, and that he is more of a physicist than a coder
@@dr_mafarioyt4313 thank you for saying this! His behaviour makes more sense.
I would just like to say thank you! I was able to understand and convert this to game maker in order to make a working pendulum that I am now using to make a space pendulum to create procedural music and background flare for my game. You made this really easy to grasp.
7:04 actually, the mass won't affect the period of the pendulum anyway. It only depends on the length of it.
Does that not depend on the small-angle approximation?
@@ryaneakins7269 no, while doing the time period calculation, the mass gets "cancelled out". The time period of a pendulum of same length is the same, regardless of mass!
can you explain why
@@shanewalsch Higher mass causes the force from gravity to be higher, so the pendulum accelerates more, but higher mass also gives the pendulum greater inertia, so the pendulum accelerates less.
@@shanewalsch the same reason that the gravity acceleration dosnt depends on the mass
Dan, I am so glad you make these videos!I learn on khan academy, but i dont understand most of it!You helped me out of so much jams!
8:07 Checkmate globe earthers
lol
Even though i code with Python and C, i still catch you explanations so easily, your the best mate, i was getting mad with the pendulum code, you saved my sanity. Thank you.
Finally a coding challenge video!
Wow! Love the passion and enthusiasm! Great video as always! Something I really want to mess with someday when I have more time and skill is taking the double pendulum concept and trying to simulate a cuckoo clock with time, weights that would supposedly reach the floor after a certain amount of time, and maybe eventually a cuckoo! There could be an analog clock that moves based on a certain amount of pendulum ticking (to be accurate to a minute) and the weights could slowly move down so it simulates a one day or eight day cuckoo clock! I grew up with about five or six cuckoo clocks throughout my childhood, so it would make me so happy to see that in a simulation! We could increment certain numbers without having to worry about a physics gear simulation behind the scenes. I think it would be so cool to implement music and quail as well so there could be three doors with four weights, etc! If any of you guys (or even Daniel!) could do any form of this idea, I'd love to see any form of this simulation!
I love this guy! The best teacher I would say
The general pendulum equation (3D) is a lagrangian equation and the solution is a sphere. It's very elegant to solve it using energy instead of vectors.
Thanks for your videos, inspires me a lot!
What you do is amazing and so helpfull! Thanks !
Thanks for helping us
I love your coding challeges
Yay! Thanks!
Love this video.
I was just waiting for this.
Great video!
I just spent the last 4 hours learning about derivatives and integrals to take a shot at this and my brain is scrambled at this point.
thanks mate very helpful
You are a treasure.
I had a similar issue long time ago when my dad told me that if you look at a rotating car wheel, the velocity of a point on the rim would be slower than the velocity of a point on the tire. I had a lot of trouble digesting that!
Very helpful
Just wow🤯
Nice, amazing "nature of code". I am only subscribed to ur channel
Hey, to solve the simulation when it accelerate, even a little bit, you can transform the acceleration in the speed, in the position and get the position equation
Yay!!!! coding challenges!!!
you can use SHM equation for this or solve langrange like ur double pendulum video . y(t)=Asin(wt+phi)
its so fun to learn from u
Can anyone help me with this? I wanna add an if statement in order to change something automatically when the pendulum almost stops swinging, but this seems little tricky to do. Is there a function to give an average over certain frames, like an average of angleV over the last 60 frames in this case?
Whoa, this was so much more complicated than I expected. And we didn't even pay attention to the weight of the "bob".
thanku
Wait you created a coding challenge about double pendulum before you created a coding challenge about simple pendulum
You could apply a RK4 integration method to the system to update the values.
I'm from c# and had just discovered generative code like this and still understood your explanations thank you mate my version works just flashy because i had to make the draw function myself from timer ticks definitely worth a like!
i found working along in other languages to be useful even, generally, since it forces you to at least slightly rethink everything
@@julians.2597 Exactly!
@@julians.2597 At first I thought I picked the wrong language but I realized it's not bad
I understood armonic motion thanks to you
It also needed a height start. sin/cos (angleS x angle). With angle=pi/180. This will count, in degrees, - or + from the resting position of 0.
Great Scott! Great Dan ! where to find an explanation of creatVector() function ? Thanks
Hey new sub here.,your videos are great
Hey can you tell me what all I included in nature of code book
I was writing my own physics engine for fun and I also encountered that issue, where you have to update velocity first then position, otherwise, energy is not conserved lmao.
Thank you so much I have a science project to do about pendulums
Thank you for the nice video. I have a question. How about simulating in real-time? I mean, when you put the update inside the draw function it runs a number of times each second due to the frameRate, but the framRate is not the effective "real time" of the problem. Moreover, when you use the Euler integration method you don't make a mention to a time step in order to write this.angle+=this.vel*timestep. In other words, how to get a simulation that when I put real parametres like g=9.81 and the pendulum length equal to 1 meter, show a truly 2 seconds period animation?
I hope I was clear. Thanks in advance.
I suppose this could be solved by multiplying the force applied to the pendulum by the delta time of each frame (the time elapsed between one frame and another). That said, usually, during physics-based simulations, you want to maintain a constant framerate to avoid delta time conversions, so your best course would be to call the draw function at a fixed interval (like 60fps or something) and then multiply the force applied each frame by that fixed delta time. Hope this helps.
This is more of a math challenge than a coding challenge now
Theres one aspect of pendulums that won't work with this code wich is when you have multiple pendulums of same length but starting at different angles they should all have the same period, meaning, they should all get to their maximum height at the same time. This won't work because of how numbers get approximated and I still haven't figured out how to fix it. Any help?
I wanted to know how to speak English so I could see your classes better, kkk XD. very good, thanks for the videos.
Yooooooohohoooooooooooo!!!!!!!!!!;;/
I can't express as hooow excited I am!!!!!!!!
ITS A CODING CHALLENGE!!!!!
Wooohooooo
I put the whole thing together by hand as a concentration exercise using only an ATOM Editor,
a browser, and a dedicated source directory containing the necessary script.js files,
and still feel that JS-script is a pain to work with, unless one implements a linter that points out all those tiny errors that make
JS-code stop dead in it's tracks without any indication of the single one error responsible for the blank browser display.
Why does it happen that a pendulum seem to almost pause at the height of it's swing on either side before swinging back? Does it actually do that? Does the weight of the Bob have something to do with this? 🤔
someday i want to being this guy
this pendulum is kind of... HYPNOTIZING
I was been waiting for a coding challenge and now here😋😳
5min and the 5th comment 😎
More matter js videos please
Can you do a video about spherical pendulum?
OMG this was posted 6 minutes ago!!
I’m requesting your next challenge be a wormhole
now I understand the new yugioh mechanics, thanks
How to make it with "mouseX and mouseY"?
I was going to decide whether or not the pendulum looked natural, but I fell asleep and had a dream about my parents fighting.
When you wanna learn programming but you have a physics test
Wow you still look younger
what I do if I want the pendulum slow down gradually and stop in the middle?
i figured it out just need add "angleV *= 0.995;" after "angleV += angleA;"
hey can you make one video about the basics of coding java?
Make a Newtons cradle!
I thank god when he design this universe, he didn't mass up the sequence of force so we can exist.
It’s a natural intuition to know that the shorter the length the faster it swings, have you never snapped a ruler on the edge of a desk and then moved it in, what happened it speeds up
I will have to try this thank you for the suggestion!
I got my associate's degree at San Joaquin Delta College.. yay!
Hey... I m a beginner.. I know bit JavaScript... Is it good to start with p5. Js...??.. Plzz reply..
Yep, go ahead, watch his playlist for beginners :)
yes
maybe
YUP! That's, like, the entire reason p5 exists: to be beginner-friendly.
please create a spin wheel or wheel fortune
1 ≈ 9.81 nice
The first thing i said when i played this video was: "Wow"
1:40 "And a very important piece of information is the angle of the arm relativ to the x-axis. Y is that" Hmm, I usually call the angle theta LOL (jokes, people. just jokes)
i want to see the video for conical pendulum
You can very easily create it using matter.js i guess
18:40 how did he not get it before? his equation was dimensionally incorrect
Bro you showed my school lmao
You've done a video about this before 🤔
remember when he did a double pendulum
can you do the same simulation using python?
the calculations can be done in any language. for plotting you could use matplotlib if you want to use python
How about N-Pendulum? Double is too easy.
I think this is the first coding train vid to be interrupted *twice over*
(EDIT: I'm not a time traveler. I'm just a member, and members get early access to videos)
Yeah xD
Also no one said you were a time traveller yet, I am the first replier, xD.
By doing so, he emphasizes the subtle complexity of this seemingly simple exercise. He could have started over and re-recorded the whole thing, but that lesson would have been lost in the process.
Can some one guide me to the biginners Playlist
Hey Mujtaba,
You can find the playlist through the website, at thecodingtrain.com/beginners/p5js/index.html!
~The Coding Train Team 🚂
good job . Please translate the video into Arabic. you are creative
I'm Melissa
I love coding but I dont have a laptop I only have a potato 10 yrs old phone
; - ;) Sad
Its india bro talent but no opportunity's
(19:52)
"t.h.e h.y.p.n.o.t.o.a.d c.l.a.p c.l.a.p a.l.l g.l.o.r.y t.o t.h.e h.y.p.n.o.t.o.a.d c.l.a.p c.l.a.p c.l.a.p"
I just noticed something :
You're kinda like the Bob Ross of computer animation
what's ur github account name
Coding rainbow
i am existance
Ok
Ok.
(That's spelt wrong and we don't want useless commenters on this channel and you are probably a bot, but *OK.* )
@@Brahvim i am not bot because if i was bot i would not be existance
boring boring
Wow you still look younger