Coding Challenge 144: 2D Black Hole Visualization

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024

Комментарии • 272

  • @mockingbird3809
    @mockingbird3809 5 лет назад +111

    Wow....You are really a Prodigy in JavaScript....Love your Enthusiasm and Teaching Style.

    • @Trekfolie
      @Trekfolie 5 лет назад +4

      I'm learning Python atm but his style makes me want to learn JS instead.
      Welp I'm still watching his videos and enjoying it so much.

    • @sortof3337
      @sortof3337 5 лет назад +1

      @@Trekfolie l did python for 5 years before I decided to come to JS. I still use python for ML and data stuff and scripting, but Node and P5 are on next level for web and Graphics stuff.

  • @lucafelicetti9605
    @lucafelicetti9605 5 лет назад +221

    0:25 that synched-up hand gesture looks almost intentional

  • @SirPhysics
    @SirPhysics 5 лет назад +5

    Not sure if anyone has pointed this out yet, but one reason all of your photons may be getting sucked into black hole is that you're not accounting for the timestep when updating velocity, only position. This means that the "force" being exerted on all of your photons is much larger than it should be.

  • @MasterHigure
    @MasterHigure 5 лет назад +38

    4:45 RIP youtube compression algorithm.

  • @TheMultifun
    @TheMultifun 5 лет назад +325

    No one
    Engineers: c=30 and G=6

    • @francoissaab374
      @francoissaab374 5 лет назад +1

      Don Grille super great

    • @ΛεωνίδαςΓκώγκος
      @ΛεωνίδαςΓκώγκος 5 лет назад +11

      What are you talking about c = 299752458 m/s *SQUARED*

    • @johnheikens
      @johnheikens 5 лет назад +11

      ​@@ΛεωνίδαςΓκώγκος r/woooosh

    • @bartekm3878
      @bartekm3878 5 лет назад +6

      @@johnheikens Speaking of reddit, is there a dedicaated subreddit for Processsing or coding challenges?
      I mean those coding challenges that The Coding Train does.

    • @simonmaracine4721
      @simonmaracine4721 5 лет назад

      @@ΛεωνίδαςΓκώγκος Actually it's 299792458.

  • @kevnar
    @kevnar 5 лет назад +33

    We know what the speed of light is. Now, at 24:04, we know what the sound of light is, too!

    • @thockinity
      @thockinity 4 года назад +3

      That sound he made was so funny, mostly because in his position i'd do exactly the same. That nice smooth animation, just asks for that sound

  • @JonathanChute
    @JonathanChute 5 лет назад +12

    I watched you do this live - but I'm watching this just to see how you edited all your mistakes and corrections together XD
    Edit: Ah, you just refilmed the intro... Well played, Shiffman.

    • @TheCodingTrain
      @TheCodingTrain  5 лет назад +6

      Yeah, I like leaving coding mistakes in, but if I'm getting actual science wrong it's too painful to watch!

  • @luyuan0
    @luyuan0 5 лет назад +143

    It's Friday night; wanted to relax and watch a movie, and ended up watching this :D Thank you for the video - you are one of the best!!!

  • @chefbennyj
    @chefbennyj Год назад +1

    "Then, I calculate the change in angle based on the relativistic curvature of space time" -Dan 👏 using JavaScript. 😀 😆 Man I love this channel.

  • @avi12
    @avi12 5 лет назад +1

    Thanks to you, Dan, I was able to understand Derek's video. When I first watched it, I didn't understand it very much

  • @Небудьбараном-к1м
    @Небудьбараном-к1м 5 лет назад +3

    Why is your channel doesn't get millions of views? It's such a good and quality content herw

    • @ammarkamel6324
      @ammarkamel6324 5 лет назад

      cus the most people like to do easy things

  • @PilatusAnon
    @PilatusAnon 2 года назад

    I love how Veritasium's video on the black hole image was the 5th recommended video in my sidebar

  • @venido8308
    @venido8308 5 лет назад +120

    How he is doing the same movement with his hand at 0:24 xD

  • @mattiarecchi4024
    @mattiarecchi4024 5 лет назад +14

    Can you combine "rendering raycasting" with this? Would be awesome 😍

  • @guyr989
    @guyr989 5 лет назад +1

    Daniel. You are the BEST most annoying teacher I've ever seen. Thank you.

  • @hrishikeshpatil7901
    @hrishikeshpatil7901 5 лет назад +92

    I'd rather learn physics from you

    • @army6669990101
      @army6669990101 5 лет назад +22

      I would learn anything from my professors if they had 1/3 of the amount of enthusiasm and heart he puts into his videos.

    • @zoltankurti
      @zoltankurti 5 лет назад +5

      But you couldn't. He doesn't knoe much about physics.

  • @RAWRCoding
    @RAWRCoding 5 лет назад +1

    Great Video! I used to love making these types of projects in university!

  • @tezza48
    @tezza48 5 лет назад +5

    "I don't play a physicist on youtube" is that a loose Scott Manley reference? :D

  • @Red_Skies
    @Red_Skies 5 лет назад +1

    0:25 I like how he does the same arm gesture in both vids

    • @TheZenytram
      @TheZenytram 5 лет назад

      the sync, pleasures my OCD

  • @NobleMarcos
    @NobleMarcos 5 лет назад

    I don't know you, i can't program for shit, would like to change that, and i would like to see a more serious simulation of a black hole, but none of that matters because you're so entertaining and make all this so interesting to watch, i'm amazed!

  • @lazyyw4081
    @lazyyw4081 5 лет назад +1

    I was about to go and sleep but a coding train notification popped up

  • @iradnuriel9087
    @iradnuriel9087 5 лет назад

    Love those long videos so much!!!!!!!!!!!
    Very good video(I actually learned a lot from this video!!)

  • @42Hz
    @42Hz 5 лет назад +3

    Is it possible to create a space-bend effect like on this picture:
    physicsworld.com/wp-content/uploads/2006/09/LLOYDblack-hole.jpg
    So this JS blackhole would warp a background image like this.

    • @thockinity
      @thockinity 4 года назад +2

      I'm pretty sure almost anything is possible to code, if you are a good enough programmer... Could i do it? saddly no, do i believe a good programmer could do that space-bend effect? I am pretty sure they could

  • @FakeFakovick
    @FakeFakovick 10 месяцев назад

    Broooo.... My own task of my p5 chalange was make a black hole model, but u also does it😮

  • @kwinvdv
    @kwinvdv 5 лет назад

    If one would use the exact solution of Newtonian gravity (Kepler orbits), so do not compensate that the "photons" speeds up while faling towards the black hole, it can be shown that a particle would just graze the Schwarzschild radius (rs) if it start at sqrt(3)*rs≈1.73*rs. Coincidentally these particles also speed up at rs to a speed of sqrt(3) times the speed of light.

  • @Melthornal
    @Melthornal 5 лет назад +1

    If you want to keep a trail without a performance hit, couldnt you get rid of the background in the draw loop and instead put it in setup? That way each photon line update is permanent? All you need to do is connect the most recent step to the second most recent. So your history would be maxed at 1 instead of 500 or whatever. In many applications this could make a messy mess but in something like this I see no downside.

    • @TheCodingTrain
      @TheCodingTrain  5 лет назад +1

      Yes, this is a good idea! Using createGraphics() for the photon trails would be a great solution.

  • @finnk2551
    @finnk2551 2 года назад

    thank you for making such a great video! love it

  • @brunoharari6454
    @brunoharari6454 5 лет назад +5

    You have to try to make it 3D that is gonna be cool!

  • @jakubkurdziel2407
    @jakubkurdziel2407 3 года назад

    In JS you can write numbers like 100_000_000 it means the same as 100000000 but its very better to read

  • @ethanhermsey
    @ethanhermsey 5 лет назад +1

    Hats off to matthieu ;) :D

  • @enverko
    @enverko 5 лет назад +4

    5:36 Black holes are flat confirmed!

  • @QuiqueFlowers
    @QuiqueFlowers 5 лет назад

    I luv JS and your explanation

  • @morphman86
    @morphman86 5 лет назад

    Funny thing, if you could get close enough to the black hole, within the event horizon, you would see something. Nobody knows what, but you would see something.
    The light is not fast enough to escape the event horizon, but it can still bounce up a bit before it is sucked back down.
    Because we don't know how the light behaves inside the event horizon, we're not really sure how to visualise it, or calculate its behaviour.

  • @olma97
    @olma97 Год назад

    Could you do this and actually solve the field equations in js? Personally I would do it as a reverse ray-trace

  • @mina86
    @mina86 5 лет назад

    12:25 - 6.67e-11. No need for pow plus using e is likely more precise.

  • @hamadaag5659
    @hamadaag5659 4 года назад

    I have a question, people always say that objects bend the spacetime mesh but is the spacetime mesh a 2d mesh or a 3d mesh? And if it’s a 3d mesh how does it “bend”?

  • @M.MaX1
    @M.MaX1 5 лет назад

    I think is photon should be point not line so we can have batter imagination to the horizon and the photons should came from screen top right and down right to improve the some relation is really work...
    And thanks to the tutorial

  • @luismiguelgallegogomez8000
    @luismiguelgallegogomez8000 5 лет назад

    Still starting to watch, but i'm sure the challenge will be awesome!

  • @ThankYouESM
    @ThankYouESM 4 года назад

    Request: Colliding Galaxies

  • @Pablo-um5cm
    @Pablo-um5cm 3 года назад +1

    Good video, but you completely messed up with physics. For black holes you need to use relativistic mechanics and schwarzschild space-time metric.

  • @arefdelphi8520
    @arefdelphi8520 5 лет назад

    Which programing language his coding with???its awwwweeesoooome

    • @TheCodingTrain
      @TheCodingTrain  5 лет назад

      This video uses JavaScript with the p5.js library, for more: p5js.org.

  • @robertlister5192
    @robertlister5192 5 лет назад

    Hi I have a question on your 7.6 object intersection how would it work with a square and a circle intersecting?

  • @argore9709
    @argore9709 4 года назад

    would be interesting to see this used in a raycaster

  • @luckylmj
    @luckylmj 4 года назад

    Your photons can go slower then the speed of light, that's why it's so innacurate (Relativity is part of it, but photons going slower then the speed of light is part of it, too!)

  • @manasmahale5906
    @manasmahale5906 5 лет назад +1

    Great visualisation sir. I would like to suggest you that rather than going more and more into good looking animation with Mass you should try out Energy . It will be more accurate. And actually Rs is actually calculated by the formula of escape velocity which technically is Newtonian so I mean you have a ton of math and stuff to do so I will suggest you to use processing instead for obvious reasons.
    Thanks and good luck (I'm waiting).😊

    • @SirPhysics
      @SirPhysics 5 лет назад +1

      Predicting motion with energy is much more complicated than it is with forces. But I'd love to see him use Lagrangian mechanics at some point.

    • @mbrusyda9437
      @mbrusyda9437 2 года назад

      No, while calculating Rs using Newtonian gravity does give the same result, no physicist post Einstein is going to say that that is how you theoretically derive it.

  • @todesdigga3891
    @todesdigga3891 2 года назад

    lol thought this is a blender tutorial cause the orange black circle looks like the blender logo

  • @jahirraihan5700
    @jahirraihan5700 3 года назад

    we like Dan because he never act like teacher. This attitude makes him great teacher on internet.

  • @rutik42
    @rutik42 5 лет назад

    What apps you use to edit your videos. Like a video in video background

    • @tinylittleanj2
      @tinylittleanj2 5 лет назад

      RUTIK WANKHADE the second video is from his live streams (the long videos). Watch almost any of those and he almost always goes over the set up :)

  • @edilmolinafernandez7670
    @edilmolinafernandez7670 2 года назад

    It does not work because Rs depends on G, c and M these values were set arbitrarily.

  • @TheGabrielMoon
    @TheGabrielMoon 5 лет назад

    how can i blur my strokes with p5js?

  • @torchit2302
    @torchit2302 Год назад +1

    Universe: Unzip here....

  • @TheZenytram
    @TheZenytram 5 лет назад

    the mass of the black hole is 6,5B bot 2,6B

  • @shivangtiwari554
    @shivangtiwari554 2 года назад

    The lights are traveling in a straight line it's just that the space-time around the black hole is warned due to intense gravity so the light never really changed its trajectory

  • @Reanplayzz
    @Reanplayzz 5 лет назад

    re-upload?

  • @programmingwiththotho4641
    @programmingwiththotho4641 5 лет назад

    nice

  • @XKCDism
    @XKCDism 5 лет назад

    ace stuff

  • @stephenratz8312
    @stephenratz8312 5 лет назад

    Could you update the code on github? Looks like blackhole.js is still the old version.

    • @stephenratz8312
      @stephenratz8312 5 лет назад

      Ok. Looking at the code changes at the end, I also had to set this.theta = this.vel.heading(); in the Photon class for the whole thing to work.

    • @TheCodingTrain
      @TheCodingTrain  5 лет назад +1

      Here are the two sketches!
      editor.p5js.org/codingtrain/sketches/2zZqSkxtj
      editor.p5js.org/codingtrain/sketches/4DvaeH0Ur

  • @anonymouspyro2820
    @anonymouspyro2820 5 лет назад

    using python might make this a tribute!

  • @GabrelaAmarela
    @GabrelaAmarela 5 лет назад

    te amo

  • @joshuadelorimier1619
    @joshuadelorimier1619 5 лет назад

    a b o u t t i m e.....get it

  • @qasimimtiaz114
    @qasimimtiaz114 5 лет назад

    Why you code everythinh in javascript? 😆

  • @hub.ski_
    @hub.ski_ 5 лет назад

    4:49
    this.this.distance

  • @Xnoob545
    @Xnoob545 5 лет назад

    10:00 brb

  • @julienmarmur6545
    @julienmarmur6545 5 лет назад

    Watch his hands as he says "to DO this simulation". They're the same gestures in the stream clip and in his future commentary! 0:22 hilarious!

  • @franchello1105
    @franchello1105 3 года назад

    7.673208867×10^12m

  • @juschu85
    @juschu85 5 лет назад

    13:05 That's stupid. Everybody knows you should not use kg but "solar masses" as a unit for such large objects.

  • @rorororov8293
    @rorororov8293 5 лет назад

    a

  • @dhaneshabhipraya
    @dhaneshabhipraya 3 года назад

    r_s

  • @aetoksy
    @aetoksy 5 лет назад +1

    *prove earth isn't flat, my friend wanna see it* ( me )

  • @dhnsh1843
    @dhnsh1843 5 лет назад

    U could have used CSS , it's much simpler than this algorithm

  • @sanchitverma2892
    @sanchitverma2892 5 лет назад +1

    pls c++

    • @zackytalib5393
      @zackytalib5393 5 лет назад

      sanchit verma that’s like so far from his specialty

    • @sanchitverma2892
      @sanchitverma2892 5 лет назад

      @@zackytalib5393 as you see he is very influential and encourages people to code . c plus plus is one of the most dreaded and versatile languages out there. if he starts doing things in cpp ,you can clearly see whats gonna happen. I mean like he might not have that many of subscribers but his influence on people is real

    • @zackytalib5393
      @zackytalib5393 5 лет назад

      sanchit verma well he can’t code in c++, his whole vibe is coding visually and sometimes with machine learning. C++ isn’t practical for visual programming and machine learning

    • @sanchitverma2892
      @sanchitverma2892 5 лет назад

      @@zackytalib5393 aww man

  • @MRods47
    @MRods47 2 года назад

    At 35:32 I had a question, whether light can orbit black holes. Found the answer en.wikipedia.org/wiki/Innermost_stable_circular_orbit

  • @visualeyescollective8193
    @visualeyescollective8193 5 лет назад +86

    Dan, your videos have helped me evolve from knowing basically nothing about Javascript to being offered a full time job in the space of one year. Thank you dude.

    • @badunius_code
      @badunius_code 2 года назад +2

      This is great but scary. I mean all the fors, and ifs, and vars, and scope pollution...

    • @Crazyclay78YT
      @Crazyclay78YT 2 года назад +4

      @@badunius_code can't forget the "this dot"

  • @domninin
    @domninin 5 лет назад +43

    You could maybe write a ray tracer which does all of that stuff but from the front (send photons out from the "pixel layer" into the third dimension and see where they hit your pixel layer again) to render a picture

  • @williampecoraro653
    @williampecoraro653 5 лет назад +41

    c=30
    G=6
    All my engineering teachers are crying...
    But i love your videos

    • @williampecoraro653
      @williampecoraro653 5 лет назад +10

      I would rather take one constant and make everything else in percentage about the first one

    • @TheCodingTrain
      @TheCodingTrain  5 лет назад +7

      @@williampecoraro653 Yes, that's a great suggestion!

    • @Xnoob545
      @Xnoob545 5 лет назад

      Isn't it like 9.8m/s sQuaREd?

    • @halusinjackbow8043
      @halusinjackbow8043 4 года назад +1

      Xnoob Speakable That would be lowercase g, the acceleration of gravity. Uppercase G is the gravitational constant, which doesn’t really directly apply to anything we see, but it is a vital value in calculating most gravitational interactions in the universe. But don’t take my word for it; I don’t know much about it at all.

  • @melvinlijiabraham4165
    @melvinlijiabraham4165 5 лет назад +62

    One way to boost performance could be removing `background(255)` from `draw()` function and `history` from `Photon` class, so that there's no need to redraw the photon trails...

  • @OrangeC7
    @OrangeC7 5 лет назад +17

    10:40 - And hence one of the most terribly drawn whatever-those-squiggly-things-are-called-anyways-because-they're-probably-not-called-curly-brackets-when-they're-drawn-like-that-but-I-might-be-wrong was created!

  • @iminni3459
    @iminni3459 5 лет назад +15

    Nice editing for this video. :-)

  • @SotamiesTrolli
    @SotamiesTrolli 5 лет назад +44

    The physicist inside me screamed you to set c=1

    • @luisangelpantojaarredondo4460
      @luisangelpantojaarredondo4460 5 лет назад +1

      shoehaze and also g=1 😭

    • @thechrisgrice
      @thechrisgrice 4 года назад +6

      Then you're not really that much of a physicist. We often set c=1 in what's called Natural Units.

    • @kr4301
      @kr4301 4 года назад +4

      well theoretical physicists actually use natural units where c=hbar=1

  • @zacharymcarthur9013
    @zacharymcarthur9013 4 года назад +5

    While doing this coding challenge myself I named my class Blackhole and then created a Blackhole object saying, “let bhole;” “bhole = new Blackhole;” I did this for quite a while before my fiancé pointed out that maybe b-hole isn’t the best name for my Blackhole.

  • @iritesh
    @iritesh 5 лет назад +6

    From a dull drawing to a crazy good simulation, this is what programming is!

  • @ersinmisto81
    @ersinmisto81 5 лет назад +5

    I just wanna say thank you a lot for adding subtitles for hard of hearing. Please do so in the future

  • @jut2357
    @jut2357 Год назад +2

    Did you ever multiply the added gravitational force with your delta time? I feel like you will get different results depending on your time scale (dt) with this solution, since it affects the photons speed but not its attraction to the black hole. I know I'm three years late to this but if I'm wrong I'd be happy to hear an explanation :)

  • @Helios.vfx.
    @Helios.vfx. 5 лет назад +15

    You're the best, bro! Just got the book "The Nature of Code" and I'm enjoying it.

  • @boggo3848
    @boggo3848 5 лет назад +1

    The reason it doesn't work is because in general relativity you have an extra cubed term in the attractive "force" you have to simulate, which results in some really unintuitive orbits very close to the black hole. I really really recommend this amazing interactive applet that simulates the actual equations. www.fourmilab.ch/gravitation/orbits/
    In a way those crazy orbits are always possible but hidden because you can't go so close to the centre of mass of say the Earth. Black holes just make it possible to get close enough for those extra terms to start causing rosettes and photon spheres and other weird orbits.
    Anyway I'm not a physicist but I went down the rabbit hole trying to simulate this in a shader a while back and I can't remember all of the details, but I found some articles that managed to make me understand what's different.

  • @yourteacher4353
    @yourteacher4353 5 лет назад +17

    I am speechless. You, sir, are a living legend.

  • @_general_error
    @_general_error Год назад +1

    I am sorry, but I would not thank Veritassium, Derek has a lot of people who'll tell him stuff. That's how he gets extreme amount of traffic for "science" videos, which fall just short on correctness, thoroughness, and as we all know are examples of bad scientific process.

  • @connorclub6244
    @connorclub6244 Год назад +1

    I noticed that you said something like "30 pixels per frame.. thats pretty slow for movement". But thats 900 pixels travelled a second, already past the screen!

  • @jingato
    @jingato 2 года назад +1

    you'd probably get a significant performance increase if you did not add to one end of the array an then delete from the other every frame. Instead, keep an index and just replace the item at that index. The way it is now causes you to have to shift every element of the array over every frame after you delete that first element. I'd also preallocate all the memory needed for that array rather than just add to it on demand. That way you won't need to keep reallocating memory for the buffer and copying the items to the new memory location when it grows.
    To piggyback off that, you should also be constantly updating the history so it represents a path of vertices using the least number of vertices needed. For example, those lines are straight for a long while so they really only need 2 vertices, whereas you have hundreds all in that straight line.

  • @zonetwelve5881
    @zonetwelve5881 5 лет назад +4

    Oh ya!, I love to see that again.

  • @BrainKlar
    @BrainKlar 2 года назад +1

    hey one thing I do know is the movie interstellar they used allot of data to recreate the black hole. They scaled it up for visual aesthetics but supposedly was pretty accurate. They have a book on that movie and stuff that has it labeled speculative and factual or data driven ect. Their minds would be a good one to pick in how they rendered that prob love your videos!

  • @user-og2lt8ou8i
    @user-og2lt8ou8i 4 года назад +1

    _Thanks for having English captions Or subtitles_

  • @MijeshDeuja
    @MijeshDeuja 5 лет назад +3

    The quality on these videos are are getting amazing.

  • @connorclub6244
    @connorclub6244 Год назад +1

    6:24 I'm not entirely sure if my math is correct, but it came out to about 7.67616655e12

    • @connorclub6244
      @connorclub6244 Год назад

      edited 3 times just because of how bad my math was

  • @hanniffydinn6019
    @hanniffydinn6019 5 лет назад +1

    Here is a black hole in shader toy. www.shadertoy.com/view/tsBXW3
    Really need GPU shaders with raytracing to do this.

  • @effzee73
    @effzee73 5 лет назад +2

    My new favorite channel on RUclips. Your stuff's brilliant so glad I found this channel

  • @calebsherman886
    @calebsherman886 5 лет назад +2

    YES, I've always wanted to see this! Thank you!

  • @johaneric1400
    @johaneric1400 5 лет назад +7

    Owh yeah....i love this when u talk about science and javascript..........😍😍😍😍😍😍😍

  • @morphman86
    @morphman86 5 лет назад +1

    This was relatively interesting. Here, have a thumbs up!

  • @JohnPatchesMicallef
    @JohnPatchesMicallef 5 лет назад +1

    So, just for your information, when scientists run simulations of the caliber you want to do they run it on super computers and it takes days to months. My research advisor is doing gamma-ray burst jet simulations and he said it takes several minutes to generate just a few nanoseconds of simulation data. And that generation time will only increase as the jets expand outwards (getting exponentially larger).

    • @JohnPatchesMicallef
      @JohnPatchesMicallef 5 лет назад +1

      Of course a 2 dimensional version with simplified visuals of a "simpler" system (like a black hole) would be much "easier" to generate, but I imagine the level of difficulty scales down about the same amount as the loss in computational power does. So it would still take a long time to generate the data.

    • @TheCodingTrain
      @TheCodingTrain  5 лет назад +1

      Thanks for this feedback and additional info!