Drawing CIRCLES in 10 Different Ways with JavaScript

Sdílet
Vložit
  • čas přidán 4. 01. 2024
  • Let's test the limits of the HTML Canvas and use JavaScript to draw circles in 10 different ways! And, fun story, @Goukiesm pointed out a way that is faster than the usual way of doing it. Watch the whole video to find out :-)
    Things I mention in the video
    My Videos on Circles: • Videos about Circles
    Pythagorean Theorem: • Pythagorean Theorem: P...
    2D Vectors Tutorial: • Learn 2D Vectors with ...
    Draw the Portal Game: • Doctor Strange portal ...
    My Kamehameha: • JavaScript Kamehameha
    Self-driving Car Course: • Self-driving Car :: Ph...
    Machine Learning Course: • Machine Learning Course

Komentáře • 52

  • @catakuri6678
    @catakuri6678 Před 4 měsíci +2

    i tried to draw a lot of stars for my game, and method 9 (lineCap = rad * 2 method) was WAY faster than the arc method, thanks!

    • @Radu
      @Radu  Před 4 měsíci +2

      Yeah, surprising, isn't it :-)

  • @4ram16
    @4ram16 Před 5 měsíci +1

    I began my programming career over 50 years ago with APL. While seeking to learn AI, I came across this video. My first programming project was to determine a fourth circle that is tangent to three other tangent circles. Since many math geeks use APL, one associate told me that I could solve for x, y and r using a system of three quadratic equations using one of APL's matrix functions. APL has many multi-dimensional, primitive operators that would be well suited to AI data processing. You seem to passionate about AI, Math and geometry, so perhaps you could write a JavaScript function to determine and draw a circle tangent to three other circles. BTW, I later learned that this geometry problem is known as the Problem of Apollonius: en.wikipedia.org/wiki/Problem_of_Apollonius.

    • @Radu
      @Radu  Před 5 měsíci +2

      Thank you for your comment :-)
      Adding the idea to my list. Will fit well after I teach 'trilateration'... it's on my list as well, but I already have videos planned for the rest of the year, so, these will have to come after that at some point :-\

  • @offgridvince
    @offgridvince Před 5 měsíci +4

    Happy New Year!

    • @Radu
      @Radu  Před 5 měsíci

      Thanks! Same to you :-)

  • @TheZibx
    @TheZibx Před 5 měsíci +1

    Instead of emulating shader (11) - you can use a real one with canvas 3d.
    Also I know another crippy way of drawing a circle: create an Image, use base64 encoded svg circle as src, then draw that image with drawImage on our 2d canvas.

    • @Radu
      @Radu  Před 5 měsíci

      True, could have used webgl for the shader.
      And your way of drawing the circle sounds legit :-)

  • @Eternam
    @Eternam Před 5 měsíci +1

    happy new year Radu! very interesting and ilustrative video. thank you very much

    • @Radu
      @Radu  Před 5 měsíci

      You're welcome :-)

  • @adilsonbuset738
    @adilsonbuset738 Před 6 měsíci +1

    Feliz Ano Novo, Mestre Radu!

    • @Radu
      @Radu  Před 6 měsíci +1

      Thanks! Same to you :-)

  • @DanielJoseAutodesk
    @DanielJoseAutodesk Před 5 měsíci +2

    This method 11 is pretty crazy ... 😂😂👍

    • @Radu
      @Radu  Před 5 měsíci +1

      Glad you liked it :-)

  • @santiagosalazar4694
    @santiagosalazar4694 Před 5 měsíci +1

    Gran video muy interesante! thanks Radu.

    • @Radu
      @Radu  Před 5 měsíci

      You're welcome :-)

  • @adilsonbuset738
    @adilsonbuset738 Před 6 měsíci +2

    O exemplo 11 foi genial. Parabéns!

    • @Radu
      @Radu  Před 6 měsíci +1

      Thanks, but it's a very basic thing for those who work with shaders .

  • @bokulroy6285
    @bokulroy6285 Před 5 měsíci +1

    ##todays, i see your content you are the best ,you content is higher value, thanks

    • @Radu
      @Radu  Před 5 měsíci

      Thanks for watching :-)

  • @lourencodesouza8191
    @lourencodesouza8191 Před 6 měsíci +2

    Hi Radu, from this code, how could I improve it to create a pie chart?

    • @Radu
      @Radu  Před 6 měsíci +3

      For a pie chart I would use the arc method (or maybe the ellipse if I want it to have a bit of a 3D look). You would have to play with the start and end angle of the arc and also do a lineTo the center after making each slice.
      Hope this helps!

  • @bokulroy6285
    @bokulroy6285 Před 5 měsíci +1

    today i subcribe this channel

    • @Radu
      @Radu  Před 5 měsíci

      Thank you!

  • @javifontalva7752
    @javifontalva7752 Před 6 měsíci +1

    🎉🎉🎉🎉Happy new year! An nou fericit!!

    • @Radu
      @Radu  Před 6 měsíci

      Thanks :-) Happy new year! La multi ani!

  • @aditya2005_found
    @aditya2005_found Před 5 měsíci +2

    24:58
    For c = rad * 0.959494,
    For d = rad * 0.551915

    • @Radu
      @Radu  Před 5 měsíci +2

      Wow! Cool. How did you come up with those? :-)

    • @aditya2005_found
      @aditya2005_found Před 5 měsíci +4

      @@Radu for d it was quite easy as there is a cubic Bezier approximation constant formula [(4/3) * (Math.sqrt(2) - 1)],
      d = rad * [(4/3) * (Math.sqrt(2) - 1)]
      But for c I couldn't figure it out, so I started hit & trail. I actually multiplied the formula by pi/2.
      c = rad * [(4/3) * (Math.sqrt(2) - 1) * ( 1.1* Math.PI / 2)]
      I got the value 1.1 by equating (4/3) * (Math.sqrt(2) - 1) * ( x* Math.PI/2) = 0.95 (Used in the video!)
      That actually worked I was shocked!! lol :D

    • @Radu
      @Radu  Před 5 měsíci +1

      @@aditya2005_found I think they are correct :-) good job!

    • @aditya2005_found
      @aditya2005_found Před 5 měsíci +1

      @@RaduThanks 😊😊

  • @phamcongtoan1399
    @phamcongtoan1399 Před 5 měsíci +1

    I find your videos very impressive but I don't know anything about JavaScript yet, can you help me choose a source to learn JavaScript?

    • @Radu
      @Radu  Před 5 měsíci +2

      I don't really know what to recommend... I learned it just by doing various projects and looking up what I don't know or asking questions when stuck.

    • @phamcongtoan1399
      @phamcongtoan1399 Před 5 měsíci +1

      @@Radu Thank you, I will do it your way and will follow your course because it is very interesting ,especially machine learning

    • @offgridvince
      @offgridvince Před 5 měsíci +3

      Netninja

    • @phamcongtoan1399
      @phamcongtoan1399 Před 5 měsíci +1

      @@offgridvince thanks

    • @offgridvince
      @offgridvince Před 5 měsíci

      @phamcongtoan1399 you're welcome. I learned a lot from his content. Even bought the course on udemy. Worth every penny I go back to it from time to time. Much success to you.

  • @mesmartboy1985
    @mesmartboy1985 Před 2 měsíci +1

    i like i subscribe.

    • @Radu
      @Radu  Před 2 měsíci +1

      Cool. Thanks :-)

  • @ChandrashekarCN
    @ChandrashekarCN Před 5 měsíci +1

    💖💖💖💖

  • @alemran4388
    @alemran4388 Před 5 měsíci +1

    Happy new year....🎄

    • @Radu
      @Radu  Před 5 měsíci

      Happy new year :-)

  • @StarsManny
    @StarsManny Před 5 měsíci +1

    Why is it so quiet?

    • @Radu
      @Radu  Před 5 měsíci +1

      Unfortunately it's because of the microphone in the room I was filming. It was set as high as possible, but that's the best it could pick up :-\
      Also, unfortunately, I recorded about 10 videos in this way and I tried to increase the volume a bit + denoise the result, but this is the best I could, so... things will be a bit quiet for a while (hope you can manage).
      Luckily, I noticed the problem and Phase 3 of the self-driving car course (starting in February) has good audio, but these other 'silent' videos will come at some point :-\

  • @bokulroy6285
    @bokulroy6285 Před 5 měsíci +2

    radu is best, radu is best , radu is best

    • @Radu
      @Radu  Před 5 měsíci +1

      :-)

  • @pizdaxyu
    @pizdaxyu Před 5 měsíci +1

    I asked GPT because I am lazy and it gave me
    ctx.setLineDash([5, 5]);
    ctx.arc(0, 0, rad, 0, 2 * Math.PI);
    ctx.setLineDash([]);

    • @Radu
      @Radu  Před 5 měsíci

      What is this answer for? Did I ask something in the video? I forgot :-D

    • @pizdaxyu
      @pizdaxyu Před 5 měsíci +1

      @@Radu another method to draw circle

    • @Radu
      @Radu  Před 5 měsíci +1

      @@pizdaxyuwell, that is basically method 1 from my video, but the circle will be a dashed line instead of continuous.