Code Night: Drawing a Heart

Поділитися
Вставка
  • Опубліковано 8 лют 2017
  • Alright. You know all those times you wanted parametric equations for a heart but didn't know where to go or who to ask? Well, you are in luck! We're coding that up today!
    This video was part of a collaboration whose hub video (quiz) can be found here:
    • Who Is Your UA-cam Va...
    Anyway, thanks so much for watching and I'll see you next time!
    The music came from Josh Woodward (sped up 1.5 times):
    www.joshwoodward.com/
    Please feel free to follow me on Twitter:
    / leiosos
    Twitch (where I do all the simulations):
    / leioslabs
    My second youtube channel (where I put the streams):
    ua-cam.com/channels/Ff6.html...
    or Github:
    github.com/leios
    The code I used is available here:
    github.com/leios/simuleios/tr...
    (sorry it's so messy)
    Also, discord:
    / discord
  • Наука та технологія

КОМЕНТАРІ • 68

  • @LeiosLabs
    @LeiosLabs  7 років тому +15

    Hey guys, I am not sure when this video is going to go live, but I have a few things I would like to say:
    1. Seriously go check out the other folks. Some of them are quite good and definitely worth your time!
    2. This was a bit of an experimental video on my end. I like how it turned out, but it's obviously not perfect. I feel I went too quickly through the code, and I feel like this is one of the few cases where I should not have commented the code. The point of this video was to get more people into hobby programming, and I don't know if this did that or not.
    3. I realized recently that I have way too many lines of code put into this channel to *not* show any at all on stream. I genuinely love programming and want to slowly incorporating it into my videos, but I don't know how yet.
    4. I think the video might be a little easy for some of you guys, sorry about that!
    Anyway guys, thanks so much for watching / please leave your honest opinions (even if they are negative), and I will do my best to address them in future videos.
    See ya next time!

    • @GlazeAndMaren
      @GlazeAndMaren 7 років тому +3

      Glad i found you, your channel seems great! As a matter of fact I genuinely love programming too so I support you on incorporating more!

    • @b2366
      @b2366 4 роки тому

      Hi
      Please I need the function draw
      Please

  • @amenicHD
    @amenicHD 7 років тому +3

    I'm so glad that I found you! This video was quite interesting and made me hungry for more :P
    Seriously, I'm really happy right now. I love exactly that stuff what you are doing - programming, math, algorithms etc. Also, it's really cool that you upload your streams on your other channel, thank you for this, I definitely going to check them out!

    • @LeiosLabs
      @LeiosLabs  7 років тому +1

      Ah, great! I'm glad you enjoy the content! I seriously love hobby programming and stuff and would love to see more people enjoy it too! That said,t he streams are where I learn the algorithms and how to code, so they are sometimes a little rough.

  • @HebaruSan
    @HebaruSan 6 років тому +12

    Now to optimize! First obvious thing is to exploit the symmetry to cut the number of points to calculate in half, but can you do it with fewer trig calls per point?

    • @LeiosLabs
      @LeiosLabs  6 років тому +2

      Oh man, I like you.

    • @ThePharphis
      @ThePharphis 5 років тому +1

      I suppose memoization would work since with multiples of theta you will see several values many times. Then just apply that to both cos() and sin().
      Could also use identities for any multiple of theta to so that once you calculate each value for sin() and cos() (could probably use an identity here to only have to do one of them!) you only have to lookup the values in a table, having reusable values.
      For more precision/speed maybe just throw them all in a table and load it each time you run the program.

  • @Betacak3
    @Betacak3 7 років тому +17

    I came here expecting Java or something along those lines. And then you started typing C code in vi. I think I'm in love with you.

    • @strega-nil
      @strega-nil 7 років тому +2

      That's C++ :3

    • @Betacak3
      @Betacak3 7 років тому +1

      I know. But C++ is still kind of C. I just don't like to type out C/C++ each time. =p

    • @strega-nil
      @strega-nil 7 років тому +1

      Not really. C++ is significantly diverged from C. It has nice features like destructors, ranged-for, overloading, constexpr functions, and simplified Pi types. Go is more similar to C. The only thing that C and C++ share anymore, is the ability to compile a common subset (which shrinks in relation to the standards every year), an awful type syntax, and a shared ability to work with no GC (although C does this through manual memory management, a technique fraught with use after frees and leaks, while C++ does this through RAII).

    • @Betacak3
      @Betacak3 7 років тому +1

      You're the type of person who writes GNU/Linux, aren't you? :D
      Thanks, btw. I know a little C, but I didn't know C++ was so different from C. I always thought it was C with a bit glued on it.

    • @strega-nil
      @strega-nil 7 років тому +1

      Nope, just a C++ programmer. Yeah, C++ is a great language; I recommend learning it as its own language, not related to C. Pi types are nice.

  • @bastianjrgensen9513
    @bastianjrgensen9513 7 років тому +1

    Good, information rich video. Keep up the good work man :) enjoying your work and learning a bunch

  • @markusbilz5930
    @markusbilz5930 6 років тому +1

    I really like your way, how you teach us new things. Thank you :)

    • @LeiosLabs
      @LeiosLabs  6 років тому

      I'm glad it was helpful!

  • @bonafide9085
    @bonafide9085 7 років тому +22

    "You press the keys without effect,
    Your life is now a wreck.
    What a waste! Such a shame!
    And all you have is vi to blame."

  • @viliml2763
    @viliml2763 6 років тому +2

    "pre-increment for optimal performance"
    I love this.

    • @LeiosLabs
      @LeiosLabs  6 років тому +3

      My community always bugged me about that...

  • @Pnt1001
    @Pnt1001 7 років тому +2

    This is awesome! This video has encouraged me to sign up for a vector graphics class for next term.

    • @LeiosLabs
      @LeiosLabs  7 років тому

      Cool! I'm glad it was helpful!

  • @tim8602
    @tim8602 7 років тому +1

    Big shout out to Draw Curiosity who helped me find this channel!

  • @tibees
    @tibees 6 років тому +9

    awesome!

    • @LeiosLabs
      @LeiosLabs  6 років тому +3

      I'm glad you liked it!

  • @nmmm2000
    @nmmm2000 7 років тому +1

    this is kind of "figure of Lissajous" ( en.wikipedia.org/wiki/Lissajous_curve ).
    you can do it with oscilloscope as well but it must have 2 inputs for x and y

  • @nevillestyles
    @nevillestyles 7 років тому +1

    I arrived here from Draw Curiosity. Instant subscription :)

    • @LeiosLabs
      @LeiosLabs  7 років тому

      I'm glad you liked it! =)

  • @AdiDavid10
    @AdiDavid10 7 років тому +3

    Just being pedantic here, but when you solve for x you get x = ±√(r² - y²), which I guess is what you meant by having to plot two points for each y?
    Otherwise, ❤️ the video!

    • @LeiosLabs
      @LeiosLabs  7 років тому +2

      You are totally right. It bothered me too, but I didn't have time to refilm it. Sorry!

  • @jay-ar6593
    @jay-ar6593 5 років тому

    Hey curious how you change the code so the heart fits into a 1x1 square?

  • @DanielSantoAngel
    @DanielSantoAngel 6 років тому +2

    Color highlight that code please hahaha. Great video as always

    • @LeiosLabs
      @LeiosLabs  6 років тому

      Yeah, I don;t use syntax highlighting when I code, so I didn't think about it.

    • @DanielSantoAngel
      @DanielSantoAngel 6 років тому

      LeiosOS you really don't? Why so? I think I wouldn't be able to code without it 😬

    • @LeiosLabs
      @LeiosLabs  6 років тому

      I just never got used to it and it bugs me slightly when I'm writing code and all of a sudden my words are highlighted. It's like having your words highlighted / underlined when you misspell them. It's definitely useful, don't get me wrong... but it sometimes gets annoying and it's nice just to spell-check everything at the end.

  • @spacelightning6587
    @spacelightning6587 4 роки тому

    I went on the pick a date option and ended up back here. I think that means it's meant to be.

  • @HarleyPebley
    @HarleyPebley 7 років тому +2

    Haha, going old school C and vi! :-)
    I'll definitely check out your channel. Just a note, Processing (processing.org/) is a great environment for this type of thing. It's an integrated environment, so you don't need custom libraries or to download multiple things to get going, it's C based and it's focused on graphics. For this particular video, it would have been a perfect fit.

    • @LeiosLabs
      @LeiosLabs  7 років тому

      I know you say that processing is C-based, but I haven't seen any way to get it to work with any languages I use regularly (C/C++ Fortran, Julia, python...) I have actually been thinking about writing my own library to solve this problem, but we'll see where that goes. Processing is Open-Source, so I might just create a library for C++-based processing.

    • @HarleyPebley
      @HarleyPebley 7 років тому +1

      Sounds like you're trying to use Processing in conjunction with other languages. I don't know enough about it to know if that's possible.
      When I wrote my comment, I was thinking more about doing your entire example in Processing. It's sufficiently C-like that when I played around with it, I didn't have any issues with the syntax. I've spent a grand total of about three hours in Processing. In that time I went from "Hmm, what is this?" to having a working version of Conway's Game of Life. Just throwing it out there as a possible sandbox to play in that's self-contained for viewers to deal with.

    • @LeiosLabs
      @LeiosLabs  7 років тому

      Yeah. I guess the language, itself, doesn't matter. I'll look into it, thanks!

  • @neva2327
    @neva2327 Рік тому

    it is literally 3 a.m and I'm trying so hard to just to make a heart in c++ on xcode and nothing works :(((

  • @Afnanali-iu5zo
    @Afnanali-iu5zo 4 роки тому

    And pls also tell how to move the text around the heart

  • @leonardobrocchi7313
    @leonardobrocchi7313 7 років тому

    could you share your library? if you don't want it's fine, but it would be very cool.

    • @LeiosLabs
      @LeiosLabs  7 років тому

      I am actually working on a new library right now. I'm not entirely happy with it, though, I'll definitely update everyone when I am! =)

  • @strega-nil
    @strega-nil 7 років тому +1

    Why don't you use range-based for?

    • @strega-nil
      @strega-nil 7 років тому +1

      Anybody who invites off-by-one errors just isn't right for me :( (although I'll definitely still watch your videos :P)

    • @LeiosLabs
      @LeiosLabs  7 років тому

      Haha, wonderful! For me, this loop makes more sense, but it kinda depends on who I talk to. =)

    • @HarleyPebley
      @HarleyPebley 7 років тому +1

      Just curious, how would a range-based for loop made this more expressive? Does C++ have a container to generate a range like C#'s Enumerable.Range? I've only seen C++ range based loops with pre-existing containers/sets that doesn't seem like it'd lend itself well to this problem. Cheers.

    • @strega-nil
      @strega-nil 7 років тому +1

      Harley Pebley Well, std::vector is a container, so just `for (auto& i : v)` would work. It makes it impossible for things to get out of sync; for example, if @LeiosOS updated that points constant, or the vector's size. Also, AAA (almost always auto) is good, random thing.

    • @HarleyPebley
      @HarleyPebley 7 років тому +1

      Oh, I see what you're saying. However, in this particular case "i" is used for more than just the container index. It's also used for the calculations. I guess that's why I didn't see how a range for loop would improve it.
      I suppose a separate variable could be created to use for the calculations and incremented on each loop, but that doesn't seem to express the algorithm as well and could arguably introduce more room for things getting out of sync.
      An alternative would be to use a list instead of a vector, iterate over theta instead of the more abstract resolution and append vec structures to the list as they're calculated.
      Fun thing about code, there's always more than one way to do things and beauty is in the eye of the beholder. Ask 10 programmers for a solution to a problem and you'll get at least 20 solutions. :-)

  • @badhbhchadh
    @badhbhchadh 5 років тому

    You should add a gamma function somewhere.

  • @JP-gs3jw
    @JP-gs3jw 5 років тому

    cool

  • @Afnanali-iu5zo
    @Afnanali-iu5zo 4 роки тому

    Is this a c++ program

  • @suchitraroutray6903
    @suchitraroutray6903 6 років тому +1

    can you do the same with java?

    • @LeiosLabs
      @LeiosLabs  6 років тому

      You definitely can! I don't know if I'll make another video on it, though. With a good visualization library, you can do anything!

  • @Trident_Euclid
    @Trident_Euclid 5 років тому

    My only experience in programming is only in C++ 😅

    • @LeiosLabs
      @LeiosLabs  5 років тому

      Fair enough. Mine was too for a while!

  • @b2366
    @b2366 4 роки тому +1

    Hi
    Please I need the function draw
    Please