Coding Challenge

Sdílet
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...

Komentáře • 129

  • @joaoferreira_yt
    @joaoferreira_yt Před 3 lety +14

    I'm so happy that you exist, Daniel.

  • @Snoo29293
    @Snoo29293 Před 3 lety +19

    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.

  • @rafaelgpontes
    @rafaelgpontes Před 3 lety +5

    Always nice to watch another Coding Train with Dan. Much love from Brazil! 🇧🇷 :)

  • @rrMaxwell
    @rrMaxwell Před 3 lety +14

    13:50 my childhood experiment while standing on swing in the park😎

  • @tahasharjeel
    @tahasharjeel Před 3 lety +5

    Please please dont stop making videos ever , im so glad that you exist ♥️

  • @gkreisman
    @gkreisman Před 3 lety +9

    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.

  • @bobingstern4448
    @bobingstern4448 Před 3 lety +8

    So well explained, I love your nature of code series!

  • @neerajkatiyar8868
    @neerajkatiyar8868 Před 3 lety +47

    Now I know the science behind a pendulum

    • @eugenetswong
      @eugenetswong Před rokem

      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 Před rokem

      @@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 Před rokem

      @@dr_mafarioyt4313 thank you for saying this! His behaviour makes more sense.

  • @malucifer
    @malucifer Před rokem

    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 Před 3 lety +79

    7:04 actually, the mass won't affect the period of the pendulum anyway. It only depends on the length of it.

    • @ryaneakins7269
      @ryaneakins7269 Před 3 lety +1

      Does that not depend on the small-angle approximation?

    • @LegendaryFartMaster
      @LegendaryFartMaster Před 3 lety +9

      @@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 Před 3 lety

      can you explain why

    • @Hagledesperado
      @Hagledesperado Před 3 lety +5

      ​@@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 Před 3 lety +5

      @@shanewalsch the same reason that the gravity acceleration dosnt depends on the mass

  • @mattiesavage4905
    @mattiesavage4905 Před 2 lety +1

    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!

  • @LegendaryFartMaster
    @LegendaryFartMaster Před 3 lety +13

    8:07 Checkmate globe earthers

  • @claverbarreto5588
    @claverbarreto5588 Před 2 lety +1

    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.

  • @tejasgurav1047
    @tejasgurav1047 Před 3 lety +16

    Finally a coding challenge video!

  • @zinsy23
    @zinsy23 Před 3 lety +2

    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 Před 3 lety +1

    I love this guy! The best teacher I would say

  • @BrunoidGames
    @BrunoidGames Před 2 lety +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!

  • @martinv9751
    @martinv9751 Před 2 lety

    What you do is amazing and so helpfull! Thanks !

  • @Quidoute
    @Quidoute Před 3 lety +1

    Thanks for helping us

  • @Max-os4xb
    @Max-os4xb Před 3 lety

    I love your coding challeges

  • @circuitguru4554
    @circuitguru4554 Před 3 lety +1

    Yay! Thanks!

  • @bodrexloverz2190
    @bodrexloverz2190 Před 3 lety

    Love this video.

  • @sobhanbera
    @sobhanbera Před 3 lety

    I was just waiting for this.

  • @scottherr5922
    @scottherr5922 Před 3 lety

    Great video!

  • @adognamedsally
    @adognamedsally Před 3 lety +1

    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.

  • @aidanfarrell1926
    @aidanfarrell1926 Před 2 lety

    thanks mate very helpful

  • @LNum
    @LNum Před 3 lety +1

    You are a treasure.

  • @1993muadh
    @1993muadh Před 3 lety

    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!

  • @maciejkaminski8535
    @maciejkaminski8535 Před rokem

    Very helpful

  • @Abhishek-tr4oi
    @Abhishek-tr4oi Před 3 lety

    Just wow🤯

  • @nihalr9827
    @nihalr9827 Před 3 lety +1

    Nice, amazing "nature of code". I am only subscribed to ur channel

  • @fireboss05
    @fireboss05 Před 3 lety

    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

  • @MrKhan-ci3uy
    @MrKhan-ci3uy Před 3 lety

    Yay!!!! coding challenges!!!

  • @krishnamania1
    @krishnamania1 Před rokem +1

    you can use SHM equation for this or solve langrange like ur double pendulum video . y(t)=Asin(wt+phi)

  • @kemoxplus
    @kemoxplus Před 3 lety

    its so fun to learn from u

  • @vladbach8605
    @vladbach8605 Před 2 lety +1

    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?

  • @kpunkt.klaviermusik
    @kpunkt.klaviermusik Před rokem

    Whoa, this was so much more complicated than I expected. And we didn't even pay attention to the weight of the "bob".

  • @cuckooo123
    @cuckooo123 Před 3 lety

    thanku

  • @kushagra64
    @kushagra64 Před 3 lety +2

    Wait you created a coding challenge about double pendulum before you created a coding challenge about simple pendulum

  • @IsaacPiera
    @IsaacPiera Před 3 lety

    You could apply a RK4 integration method to the system to update the values.

  • @wshockmc2445
    @wshockmc2445 Před 2 lety

    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 Před 2 lety +1

      i found working along in other languages to be useful even, generally, since it forces you to at least slightly rethink everything

    • @wshockmc2445
      @wshockmc2445 Před 2 lety

      @@julians.2597 Exactly!

    • @wshockmc2445
      @wshockmc2445 Před 2 lety

      @@julians.2597 At first I thought I picked the wrong language but I realized it's not bad

  • @FridgeFucker96
    @FridgeFucker96 Před 3 lety

    I understood armonic motion thanks to you

  • @vancemccarthy2554
    @vancemccarthy2554 Před 2 lety

    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.

  • @82kerouac
    @82kerouac Před 3 lety

    Great Scott! Great Dan ! where to find an explanation of creatVector() function ? Thanks

  • @disdis6127
    @disdis6127 Před 3 lety

    Hey new sub here.,your videos are great

  • @sajeevanfuels1980
    @sajeevanfuels1980 Před 3 lety +1

    Hey can you tell me what all I included in nature of code book

  • @freeshavaacadooo1095
    @freeshavaacadooo1095 Před 3 lety

    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.

  • @bobjones7114
    @bobjones7114 Před 3 lety

    Thank you so much I have a science project to do about pendulums

  • @amedeoborsini8733
    @amedeoborsini8733 Před 3 lety +2

    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 Před 2 lety +1

      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.

  • @zhabiboss
    @zhabiboss Před rokem

    This is more of a math challenge than a coding challenge now

  • @DaniloSouzaMoraes
    @DaniloSouzaMoraes Před 2 lety

    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?

  • @arqlesma
    @arqlesma Před 3 lety

    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 Před 3 lety

    Yooooooohohoooooooooooo!!!!!!!!!!;;/
    I can't express as hooow excited I am!!!!!!!!
    ITS A CODING CHALLENGE!!!!!
    Wooohooooo

  • @frankkoslowski6917
    @frankkoslowski6917 Před rokem

    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.

  • @chefbennyj
    @chefbennyj Před 2 lety

    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? 🤔

  • @abrorabyyu6221
    @abrorabyyu6221 Před 2 lety

    someday i want to being this guy

  • @maikha8963
    @maikha8963 Před 3 lety

    this pendulum is kind of... HYPNOTIZING

  • @judi6787
    @judi6787 Před 3 lety +2

    I was been waiting for a coding challenge and now here😋😳
    5min and the 5th comment 😎

  • @Troy-ol5fk
    @Troy-ol5fk Před 2 lety

    More matter js videos please

  • @Crunchybiscuit01
    @Crunchybiscuit01 Před 3 lety

    Can you do a video about spherical pendulum?

  • @Brahvim
    @Brahvim Před 3 lety +1

    OMG this was posted 6 minutes ago!!

  • @wristdisabledwriter2893

    I’m requesting your next challenge be a wormhole

  • @santiagojaramillorodriguez8272

    now I understand the new yugioh mechanics, thanks

  • @wizwildworld2407
    @wizwildworld2407 Před 3 lety

    How to make it with "mouseX and mouseY"?

  • @kevnar
    @kevnar Před 3 lety +2

    I was going to decide whether or not the pendulum looked natural, but I fell asleep and had a dream about my parents fighting.

  • @dragonrock8467
    @dragonrock8467 Před 3 lety

    When you wanna learn programming but you have a physics test

  • @simeonetim5600
    @simeonetim5600 Před 3 lety +1

    Wow you still look younger

  • @CanalDoCCoala
    @CanalDoCCoala Před 3 lety

    what I do if I want the pendulum slow down gradually and stop in the middle?

    • @CanalDoCCoala
      @CanalDoCCoala Před 3 lety

      i figured it out just need add "angleV *= 0.995;" after "angleV += angleA;"

  • @dasonn
    @dasonn Před 3 lety

    hey can you make one video about the basics of coding java?

  • @woeshbot5104
    @woeshbot5104 Před 3 lety +1

    Make a Newtons cradle!

  • @springrollwang4441
    @springrollwang4441 Před 3 lety

    I thank god when he design this universe, he didn't mass up the sequence of force so we can exist.

  • @gower1973
    @gower1973 Před 3 lety

    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  Před 3 lety

      I will have to try this thank you for the suggestion!

  • @norcal6181
    @norcal6181 Před 3 lety

    I got my associate's degree at San Joaquin Delta College.. yay!

  • @prashantkumarsingh4548

    Hey... I m a beginner.. I know bit JavaScript... Is it good to start with p5. Js...??.. Plzz reply..

    • @Brahvim
      @Brahvim Před 3 lety

      Yep, go ahead, watch his playlist for beginners :)

    • @Xnoob545
      @Xnoob545 Před 3 lety

      yes

    • @Xnoob545
      @Xnoob545 Před 3 lety

      maybe

    • @SimonTiger
      @SimonTiger Před 3 lety

      YUP! That's, like, the entire reason p5 exists: to be beginner-friendly.

  • @king-zu3ih
    @king-zu3ih Před 3 lety

    please create a spin wheel or wheel fortune

  • @user-ym8ui3wu6c
    @user-ym8ui3wu6c Před 2 lety

    1 ≈ 9.81 nice

  • @rodakdev
    @rodakdev Před 3 lety

    The first thing i said when i played this video was: "Wow"

  • @eduardoh.m2072
    @eduardoh.m2072 Před 3 lety

    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)

  • @SachinSharma-bk2lg
    @SachinSharma-bk2lg Před 3 lety

    i want to see the video for conical pendulum

  • @ramkumars2329
    @ramkumars2329 Před 3 lety

    You can very easily create it using matter.js i guess

  • @baxi9227
    @baxi9227 Před 3 lety

    18:40 how did he not get it before? his equation was dimensionally incorrect

  • @infernious
    @infernious Před 3 lety

    Bro you showed my school lmao

  • @lordpablo1985
    @lordpablo1985 Před 3 lety

    You've done a video about this before 🤔

  • @MARC-yo7mo
    @MARC-yo7mo Před 3 lety

    remember when he did a double pendulum

  • @alwysrite
    @alwysrite Před 3 lety

    can you do the same simulation using python?

    • @IsaacPiera
      @IsaacPiera Před 3 lety +1

      the calculations can be done in any language. for plotting you could use matplotlib if you want to use python

  • @darkfrei2
    @darkfrei2 Před 3 lety

    How about N-Pendulum? Double is too easy.

  • @SimonTiger
    @SimonTiger Před 3 lety +2

    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 Před 3 lety

      Yeah xD
      Also no one said you were a time traveller yet, I am the first replier, xD.

    • @ricksidwell
      @ricksidwell Před 3 lety

      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.

  • @mujtabasaeed6697
    @mujtabasaeed6697 Před 3 lety

    Can some one guide me to the biginners Playlist

    • @TheCodingTrain
      @TheCodingTrain  Před 3 lety +2

      Hey Mujtaba,
      You can find the playlist through the website, at thecodingtrain.com/beginners/p5js/index.html!
      ~The Coding Train Team 🚂

  • @2I6
    @2I6 Před 3 lety

    good job . Please translate the video into Arabic. you are creative

  • @toastyPredicament
    @toastyPredicament Před 2 lety

    I'm Melissa

  • @sangeetadighe6945
    @sangeetadighe6945 Před 3 lety +1

    I love coding but I dont have a laptop I only have a potato 10 yrs old phone

  • @michalbotor
    @michalbotor Před 3 lety

    (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"

  • @fredV35
    @fredV35 Před 3 lety

    I just noticed something :
    You're kinda like the Bob Ross of computer animation

  • @cuckooo123
    @cuckooo123 Před 3 lety

    what's ur github account name

    • @Roknok
      @Roknok Před 3 lety

      Coding rainbow

  • @sql64
    @sql64 Před 3 lety

    i am existance

    • @acm1812
      @acm1812 Před 3 lety

      Ok

    • @Brahvim
      @Brahvim Před 3 lety

      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 Před 3 lety

      @@Brahvim i am not bot because if i was bot i would not be existance

  • @ACTIONFORT00
    @ACTIONFORT00 Před 3 lety

    boring boring

  • @simeonetim5600
    @simeonetim5600 Před 3 lety

    Wow you still look younger