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 - Наука та технологія
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!
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!
Hi
Please I need the function draw
Please
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!
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.
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?
Oh man, I like you.
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.
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.
That's C++ :3
I know. But C++ is still kind of C. I just don't like to type out C/C++ each time. =p
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).
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.
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.
Good, information rich video. Keep up the good work man :) enjoying your work and learning a bunch
I really like your way, how you teach us new things. Thank you :)
I'm glad it was helpful!
"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."
beautiful! =)
"pre-increment for optimal performance"
I love this.
My community always bugged me about that...
This is awesome! This video has encouraged me to sign up for a vector graphics class for next term.
Cool! I'm glad it was helpful!
Big shout out to Draw Curiosity who helped me find this channel!
awesome!
I'm glad you liked it!
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
I arrived here from Draw Curiosity. Instant subscription :)
I'm glad you liked it! =)
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!
You are totally right. It bothered me too, but I didn't have time to refilm it. Sorry!
Hey curious how you change the code so the heart fits into a 1x1 square?
Color highlight that code please hahaha. Great video as always
Yeah, I don;t use syntax highlighting when I code, so I didn't think about it.
LeiosOS you really don't? Why so? I think I wouldn't be able to code without it 😬
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.
I went on the pick a date option and ended up back here. I think that means it's meant to be.
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.
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.
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.
Yeah. I guess the language, itself, doesn't matter. I'll look into it, thanks!
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 :(((
And pls also tell how to move the text around the heart
could you share your library? if you don't want it's fine, but it would be very cool.
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! =)
Why don't you use range-based for?
Anybody who invites off-by-one errors just isn't right for me :( (although I'll definitely still watch your videos :P)
Haha, wonderful! For me, this loop makes more sense, but it kinda depends on who I talk to. =)
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.
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.
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. :-)
You should add a gamma function somewhere.
cool
Thanks, you too!
Is this a c++ program
can you do the same with java?
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!
My only experience in programming is only in C++ 😅
Fair enough. Mine was too for a while!
Hi
Please I need the function draw
Please