Coding Challenge

  Рет қаралды 95,552

The Coding Train

The Coding Train

Күн бұрын

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 2
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: kzbin.infojoin
🛒 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...

Пікірлер: 129
@gkreisman
@gkreisman 3 жыл бұрын
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.
@rafaelgpontes
@rafaelgpontes 3 жыл бұрын
Always nice to watch another Coding Train with Dan. Much love from Brazil! 🇧🇷 :)
@tahasharjeel
@tahasharjeel 3 жыл бұрын
Please please dont stop making videos ever , im so glad that you exist ♥️
@bobingstern4448
@bobingstern4448 3 жыл бұрын
So well explained, I love your nature of code series!
@joaoferreira_yt
@joaoferreira_yt 3 жыл бұрын
I'm so happy that you exist, Daniel.
@malucifer
@malucifer Жыл бұрын
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.
@wallacesantos0
@wallacesantos0 3 жыл бұрын
7:04 actually, the mass won't affect the period of the pendulum anyway. It only depends on the length of it.
@ryaneakins7269
@ryaneakins7269 3 жыл бұрын
Does that not depend on the small-angle approximation?
@LegendaryFartMaster
@LegendaryFartMaster 3 жыл бұрын
@@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!
@shanewalsch
@shanewalsch 3 жыл бұрын
can you explain why
@Hagledesperado
@Hagledesperado 3 жыл бұрын
​@@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.
@gabriellasso8808
@gabriellasso8808 3 жыл бұрын
@@shanewalsch the same reason that the gravity acceleration dosnt depends on the mass
@Snoo29293
@Snoo29293 3 жыл бұрын
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.
@rrMaxwell
@rrMaxwell 3 жыл бұрын
13:50 my childhood experiment while standing on swing in the park😎
@mattiesavage4905
@mattiesavage4905 2 жыл бұрын
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!
@claverbarreto5588
@claverbarreto5588 2 жыл бұрын
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.
@neerajkatiyar8868
@neerajkatiyar8868 3 жыл бұрын
Now I know the science behind a pendulum
@eugenetswong
@eugenetswong Жыл бұрын
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.
@dr_mafarioyt4313
@dr_mafarioyt4313 Жыл бұрын
@@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
@eugenetswong
@eugenetswong Жыл бұрын
@@dr_mafarioyt4313 thank you for saying this! His behaviour makes more sense.
@zinsy23
@zinsy23 3 жыл бұрын
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!
@Noobmaster_x69
@Noobmaster_x69 3 жыл бұрын
I love this guy! The best teacher I would say
@BrunoidGames
@BrunoidGames 2 жыл бұрын
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!
@LegendaryFartMaster
@LegendaryFartMaster 3 жыл бұрын
8:07 Checkmate globe earthers
@TheCodingTrain
@TheCodingTrain 3 жыл бұрын
lol
@tejasgurav1047
@tejasgurav1047 3 жыл бұрын
Finally a coding challenge video!
@Muslim_qui_doute
@Muslim_qui_doute 3 жыл бұрын
Thanks for helping us
@martinv9751
@martinv9751 2 жыл бұрын
What you do is amazing and so helpfull! Thanks !
@adognamedsally
@adognamedsally 3 жыл бұрын
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.
@circuitguru4554
@circuitguru4554 3 жыл бұрын
Yay! Thanks!
@Max-os4xb
@Max-os4xb 3 жыл бұрын
I love your coding challeges
@1993muadh
@1993muadh 2 жыл бұрын
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!
@sobhanbera
@sobhanbera 3 жыл бұрын
I was just waiting for this.
@bodrexloverz2190
@bodrexloverz2190 3 жыл бұрын
Love this video.
@aidanfarrell1926
@aidanfarrell1926 2 жыл бұрын
thanks mate very helpful
@scottherr5922
@scottherr5922 3 жыл бұрын
Great video!
@wshockmc2445
@wshockmc2445 2 жыл бұрын
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!
@julians.2597
@julians.2597 2 жыл бұрын
i found working along in other languages to be useful even, generally, since it forces you to at least slightly rethink everything
@wshockmc2445
@wshockmc2445 2 жыл бұрын
@@julians.2597 Exactly!
@wshockmc2445
@wshockmc2445 2 жыл бұрын
@@julians.2597 At first I thought I picked the wrong language but I realized it's not bad
@fireboss05
@fireboss05 3 жыл бұрын
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
@kpunkt.klaviermusik
@kpunkt.klaviermusik Жыл бұрын
Whoa, this was so much more complicated than I expected. And we didn't even pay attention to the weight of the "bob".
@LNum
@LNum 3 жыл бұрын
You are a treasure.
@Abhishek-tr4oi
@Abhishek-tr4oi 3 жыл бұрын
Just wow🤯
@krishnamania1
@krishnamania1 Жыл бұрын
you can use SHM equation for this or solve langrange like ur double pendulum video . y(t)=Asin(wt+phi)
@MrKhan-ci3uy
@MrKhan-ci3uy 3 жыл бұрын
Yay!!!! coding challenges!!!
@freeshavaacadooo1095
@freeshavaacadooo1095 3 жыл бұрын
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.
@IsaacPiera
@IsaacPiera 3 жыл бұрын
You could apply a RK4 integration method to the system to update the values.
@vancemccarthy2554
@vancemccarthy2554 2 жыл бұрын
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.
@maciejkaminski8535
@maciejkaminski8535 Жыл бұрын
Very helpful
@FridgeFucker96
@FridgeFucker96 3 жыл бұрын
I understood armonic motion thanks to you
@cuckooo123
@cuckooo123 3 жыл бұрын
thanku
@kemoxplus
@kemoxplus 3 жыл бұрын
its so fun to learn from u
@nihalr9827
@nihalr9827 3 жыл бұрын
Nice, amazing "nature of code". I am only subscribed to ur channel
@82kerouac
@82kerouac 3 жыл бұрын
Great Scott! Great Dan ! where to find an explanation of creatVector() function ? Thanks
@kushagra64
@kushagra64 3 жыл бұрын
Wait you created a coding challenge about double pendulum before you created a coding challenge about simple pendulum
@bobjones7114
@bobjones7114 3 жыл бұрын
Thank you so much I have a science project to do about pendulums
@zhabiboss
@zhabiboss Жыл бұрын
This is more of a math challenge than a coding challenge now
@frankkoslowski6917
@frankkoslowski6917 Жыл бұрын
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.
@abrorabyyu6221
@abrorabyyu6221 2 жыл бұрын
someday i want to being this guy
@maikha8963
@maikha8963 3 жыл бұрын
this pendulum is kind of... HYPNOTIZING
@arqlesma
@arqlesma 3 жыл бұрын
I wanted to know how to speak English so I could see your classes better, kkk XD. very good, thanks for the videos.
@sudome5907
@sudome5907 3 жыл бұрын
Yooooooohohoooooooooooo!!!!!!!!!!;;/ I can't express as hooow excited I am!!!!!!!! ITS A CODING CHALLENGE!!!!! Wooohooooo
@disdis6127
@disdis6127 3 жыл бұрын
Hey new sub here.,your videos are great
@Troy-ol5fk
@Troy-ol5fk 2 жыл бұрын
More matter js videos please
@wristdisabledwriter2893
@wristdisabledwriter2893 3 жыл бұрын
I’m requesting your next challenge be a wormhole
@vladbach8605
@vladbach8605 2 жыл бұрын
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?
@judi6787
@judi6787 3 жыл бұрын
I was been waiting for a coding challenge and now here😋😳 5min and the 5th comment 😎
@amedeoborsini8733
@amedeoborsini8733 3 жыл бұрын
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.
@arihansharma6384
@arihansharma6384 2 жыл бұрын
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.
@Crunchybiscuit01
@Crunchybiscuit01 3 жыл бұрын
Can you do a video about spherical pendulum?
@gower1973
@gower1973 3 жыл бұрын
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
@TheCodingTrain
@TheCodingTrain 3 жыл бұрын
I will have to try this thank you for the suggestion!
@santiagojaramillorodriguez8272
@santiagojaramillorodriguez8272 2 жыл бұрын
now I understand the new yugioh mechanics, thanks
@simeonetim5600
@simeonetim5600 3 жыл бұрын
Wow you still look younger
@Brahvim
@Brahvim 3 жыл бұрын
OMG this was posted 6 minutes ago!!
@sajeevanfuels1980
@sajeevanfuels1980 3 жыл бұрын
Hey can you tell me what all I included in nature of code book
@springrollwang4441
@springrollwang4441 2 жыл бұрын
I thank god when he design this universe, he didn't mass up the sequence of force so we can exist.
@norcal6181
@norcal6181 3 жыл бұрын
I got my associate's degree at San Joaquin Delta College.. yay!
@SimonTiger
@SimonTiger 3 жыл бұрын
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)
@Brahvim
@Brahvim 3 жыл бұрын
Yeah xD Also no one said you were a time traveller yet, I am the first replier, xD.
@ricksidwell
@ricksidwell 3 жыл бұрын
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.
@woeshbot5104
@woeshbot5104 3 жыл бұрын
Make a Newtons cradle!
@dasonn
@dasonn 3 жыл бұрын
hey can you make one video about the basics of coding java?
@chefbennyj
@chefbennyj 2 жыл бұрын
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? 🤔
@rodakdev
@rodakdev 3 жыл бұрын
The first thing i said when i played this video was: "Wow"
@king-zu3ih
@king-zu3ih 3 жыл бұрын
please create a spin wheel or wheel fortune
@DaniloSouzaMoraes
@DaniloSouzaMoraes 2 жыл бұрын
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?
@user-ym8ui3wu6c
@user-ym8ui3wu6c 2 жыл бұрын
1 ≈ 9.81 nice
@ramkumars2329
@ramkumars2329 3 жыл бұрын
You can very easily create it using matter.js i guess
@dragonrock8467
@dragonrock8467 3 жыл бұрын
When you wanna learn programming but you have a physics test
@eduardoh.m2072
@eduardoh.m2072 3 жыл бұрын
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)
@lordpablo1985
@lordpablo1985 3 жыл бұрын
You've done a video about this before 🤔
@SachinSharma-bk2lg
@SachinSharma-bk2lg 3 жыл бұрын
i want to see the video for conical pendulum
@michalbotor
@michalbotor 3 жыл бұрын
(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"
@baxi9227
@baxi9227 3 жыл бұрын
18:40 how did he not get it before? his equation was dimensionally incorrect
@kevnar
@kevnar 3 жыл бұрын
I was going to decide whether or not the pendulum looked natural, but I fell asleep and had a dream about my parents fighting.
@MARC-yo7mo
@MARC-yo7mo 3 жыл бұрын
remember when he did a double pendulum
@wizwildworld2407
@wizwildworld2407 2 жыл бұрын
How to make it with "mouseX and mouseY"?
@CanalDoCCoala
@CanalDoCCoala 3 жыл бұрын
what I do if I want the pendulum slow down gradually and stop in the middle?
@CanalDoCCoala
@CanalDoCCoala 3 жыл бұрын
i figured it out just need add "angleV *= 0.995;" after "angleV += angleA;"
@darkfrei2
@darkfrei2 3 жыл бұрын
How about N-Pendulum? Double is too easy.
@infernious
@infernious 3 жыл бұрын
Bro you showed my school lmao
@prashantkumarsingh4548
@prashantkumarsingh4548 3 жыл бұрын
Hey... I m a beginner.. I know bit JavaScript... Is it good to start with p5. Js...??.. Plzz reply..
@Brahvim
@Brahvim 3 жыл бұрын
Yep, go ahead, watch his playlist for beginners :)
@Xnoob545
@Xnoob545 3 жыл бұрын
yes
@Xnoob545
@Xnoob545 3 жыл бұрын
maybe
@SimonTiger
@SimonTiger 3 жыл бұрын
YUP! That's, like, the entire reason p5 exists: to be beginner-friendly.
@alwysrite
@alwysrite 3 жыл бұрын
can you do the same simulation using python?
@IsaacPiera
@IsaacPiera 3 жыл бұрын
the calculations can be done in any language. for plotting you could use matplotlib if you want to use python
@toastyPredicament
@toastyPredicament 2 жыл бұрын
I'm Melissa
@sangeetadighe6945
@sangeetadighe6945 3 жыл бұрын
I love coding but I dont have a laptop I only have a potato 10 yrs old phone
@Brahvim
@Brahvim 3 жыл бұрын
; - ;) Sad
@sangeetadighe6945
@sangeetadighe6945 3 жыл бұрын
Its india bro talent but no opportunity's
@2I6
@2I6 3 жыл бұрын
good job . Please translate the video into Arabic. you are creative
@fredV35
@fredV35 3 жыл бұрын
I just noticed something : You're kinda like the Bob Ross of computer animation
@mujtabasaeed6697
@mujtabasaeed6697 3 жыл бұрын
Can some one guide me to the biginners Playlist
@TheCodingTrain
@TheCodingTrain 3 жыл бұрын
Hey Mujtaba, You can find the playlist through the website, at thecodingtrain.com/beginners/p5js/index.html! ~The Coding Train Team 🚂
@cuckooo123
@cuckooo123 3 жыл бұрын
what's ur github account name
@Roknok
@Roknok 3 жыл бұрын
Coding rainbow
@sql64
@sql64 3 жыл бұрын
i am existance
@acm1812
@acm1812 3 жыл бұрын
Ok
@Brahvim
@Brahvim 3 жыл бұрын
Ok. (That's spelt wrong and we don't want useless commenters on this channel and you are probably a bot, but *OK.* )
@sql64
@sql64 3 жыл бұрын
@@Brahvim i am not bot because if i was bot i would not be existance
@ACTIONFORT00
@ACTIONFORT00 3 жыл бұрын
boring boring
@simeonetim5600
@simeonetim5600 3 жыл бұрын
Wow you still look younger
Coding Challenge #160: Spring Forces
32:43
The Coding Train
Рет қаралды 101 М.
Coding Challenge 93: Double Pendulum
31:11
The Coding Train
Рет қаралды 914 М.
Each found a feeling.#Short #Officer Rabbit #angel
00:17
兔子警官
Рет қаралды 7 МЛН
Cute Barbie Gadget 🥰 #gadgets
01:00
FLIP FLOP Hacks
Рет қаралды 55 МЛН
New Gadgets! Bycycle 4.0 🚲 #shorts
00:14
BongBee Family
Рет қаралды 18 МЛН
Coding Challenge #117: Seven-Segment Display
18:11
The Coding Train
Рет қаралды 142 М.
Coding Marching Squares
26:28
The Coding Train
Рет қаралды 175 М.
Coding the Collatz Conjecture
23:08
The Coding Train
Рет қаралды 129 М.
Coding Challenge #14: Fractal Trees - Recursive
15:53
The Coding Train
Рет қаралды 888 М.
7 Amazing Science Gadgets!
7:02
brusspup
Рет қаралды 18 МЛН
Visualize Spectral Decomposition | SEE Matrix, Chapter 2
15:55
Visual Kernel
Рет қаралды 59 М.
Coding Challenge 125: Fourier Series
28:47
The Coding Train
Рет қаралды 581 М.
An introduction to Shader Art Coding
22:40
kishimisu
Рет қаралды 916 М.
Coding Challenge #145: 2D Raycasting
36:02
The Coding Train
Рет қаралды 632 М.
Each found a feeling.#Short #Officer Rabbit #angel
00:17
兔子警官
Рет қаралды 7 МЛН