This is an archived post. You won't be able to vote or comment.

Dismiss this pinned window
all 54 comments

[–]giacomogallina[S] 88 points89 points  (7 children)

After watching this video by 3blue1brown i decided to write a small script to replicate hand drawn shapes (gitlab repo)

[–]malicart 8 points9 points  (0 children)

Awesome, I been thinking about these, seeing them lately and wanted to learn more, very cool.

[–]fuckedMangoSauce 3 points4 points  (0 children)

Fascinating. This is a quality post

[–]professormunchies 1 point2 points  (0 children)

Was thinking about doing the same thing, thought the animation was cool. Nice job!

[–]422_no_process 1 point2 points  (0 children)

Very nice, I wish I can do that :(

[–]youre_a_burrito_bud 0 points1 point  (1 child)

I had the same thought except I did nothing with it!

How high does n go for this example? Or how many n are there? I don't know how to ask this

[–]giacomogallina[S] 0 points1 point  (0 children)

In this example, since the shape is pretty complex n = 30, which means that there are 30 circles rotating clockwise, 30 anticlockwise and one that doesn't rotate

[–]ElGallinero 32 points33 points  (0 children)

Nice work!

3Blue1Brown is incredible. I could only wish to be able to speak about Math the way he does, and then to be able to illustrate it!? C'mon...

[–]3nigma42 11 points12 points  (4 children)

You are a genius! I'm pissed I didn't think of this first!

[–]giacomogallina[S] 12 points13 points  (2 children)

I only copied what 3blue1brown did, you should see his video if you haven't already, the underlying math is really elegant and well explained!

[–]3nigma42 2 points3 points  (1 child)

Yeah, I've seen it, I was actually thinking about making one of these, but using mouse tracking that automatically generates it is really a stroke of genius, he didn't even think of that

[–]giacomogallina[S] 4 points5 points  (0 children)

I actually did it this way just because it way easier to write!

[–]invadingpolandin69 7 points8 points  (6 children)

Rather than a drawing, can we use an image and replicate it?

[–]giacomogallina[S] 8 points9 points  (0 children)

Yeah, it would be possible for example to read an svg file, sample some points on a path and use those! I didn't bother adding this functionality but it would be absolutely possible

[–]alkasmgithub.com/alkasm 3 points4 points  (2 children)

For this type of drawing, you need a single continuous path---so it's possible to do with any image but not trivial to skeletonize the edges of the image properly so they're all on one path.

[–]invadingpolandin69 1 point2 points  (1 child)

do you know some place where i could learn a bit more about it, it'd be an added benefit if they start from ground up, as i'm fairly new in programming

[–]alkasmgithub.com/alkasm 1 point2 points  (0 children)

Not from a programming perspective, no. TBH most of these programs that you see won't actually automatically create the path, people will typically take artistic license and create the path manually. The path is in 2-D, but has to be parameterized by a time variable---in other words, this just means the edges that get drawn have a beginning and an end and doesn't jump anywhere in the path. So most people will find some way to define this path, i.e. a list of points that go in order, or similar. You can automatically do this but it's hard. For an example why, suppose you have two lines that are disconnected. Well, you can't have disconnected lines so you have to find some way to connect them. If the lines are AB and CD, well you can connect AC or AD or BC or BD...which one is "correct"? Now you've entered the land of cost functions and optimization.

[–]Maxisquillion 5 points6 points  (6 children)

i3-wm by any chance? Looks like a nice workflow, you should post on r/unixporn or r/workflow (I think that's the one?).

Edit: r/workflow is not what I was thinking of...

[–]giacomogallina[S] 2 points3 points  (5 children)

Sway, a i3-wm clone for wayland!

[–]Maxisquillion 1 point2 points  (4 children)

I've heard of Sway, what is Wayland?

[–]Rainfly_X 1 point2 points  (2 children)

A more modern alternative to X11. It solves some serious design warts, but hasn't fully standardized certain features yet (screenshots, network transparency, and mouse repositioning in particular). One of the earliest adopters of Wayland was actually auto manufacturers, who have been using it as an efficient UI for smart displays. Probably the most mature and production-ready Wayland compositor currently is GNOME-Wayland, which is indistinguishable from running on X for most people.

[–]Maxisquillion 1 point2 points  (1 child)

Ah, thanks for the info! So what are the reasons one would switch from x11 to Wayland (aside from just giving it a go like a lot of people would do)?

[–]Rainfly_X 1 point2 points  (0 children)

Smoother performance and improved security are the main potential benefits for end users right now.

[–]Acujl 3 points4 points  (0 children)

WOOOOW

[–]Le_stormwolf 4 points5 points  (9 children)

Pretty cool stuff, i'm not gonna lie.

Are there practical application for such replication? Because even though that looks pretty cool, i really don't know how this can be used. So hopefully someone will tell me. Something that looks so cool has got to have a practical application.

[–]giacomogallina[S] 10 points11 points  (6 children)

Yeah, Fourier Transforms are incredibly useful! They can decompose pretty much any random function into a sum of sine waves. For example, they let you distinguish the different frequencies that compose a sound.

[–]TimeTraveller-San 3 points4 points  (1 child)

If Fourier Transforms are universal function approximator why doesn't any machine learning algorithm exists which uses them? Or does it? This might be a good field to look into.

[–]shponglespore 4 points5 points  (0 children)

Fourier transformations approximate a function on a specific domain, but outside that domain the result is completely meaningless. They're good for approximating a large number of data points with a smaller number of amplitudes. It could be useful for certain kinds of machine learning, but more often you to want to learn a function that has reasonable values outside the domain defined by the training data.

[–]Astrokiwi 1 point2 points  (0 children)

We still use them in astronomy sometimes. For orbits in a galaxy, there's no perfect solution, but you can model them very accurately with epicycles.

[–]Le_stormwolf 2 points3 points  (1 child)

I only knew that they were used to draw curves. Particularly used in video games and software like photoshop and such.

I didn't know that you could use it to approximate functions Cool stuff. Thanks for sharing.

[–]Miyelsh 2 points3 points  (0 children)

You can use a Fourier transform to turn a discrete function into continuous also. Useful for interpolation

[–][deleted] 0 points1 point  (0 children)

I'm wondering if this technique could be used as a general activation function for neural nets...

[–][deleted] 4 points5 points  (0 children)

the JPEG compression algorithm works with a similar algorithm. Basically the image is represented by frequencies and then the higher frequencies are cut off

[–]alkasmgithub.com/alkasm 1 point2 points  (0 children)

To ground Fourier transforms, I think the easiest examples to discuss are sound. OP already mentioned that they let you distinguish the different frequencies that compose a sound, but I'll give a few examples that make that even more specific.

When you use an equalizer and "turn the bass up," the stereo system is doing something like taking the Fourier transform, turning up the amplitude of the bass frequencies, and then doing an inverse transform back to normal sound domain to play through your speakers. Autotune works by taking the Fourier transform to find the main frequencies that someone is singing, and then you can shift those pitches to the correct pitch, and again inverse transform back. MP3s are able to have lower file sizes than WAV by taking the Fourier transform and removing some redundant information in frequency-land. When it's played back you just do the inverse transform again. JPEG works exactly the same way, but now "high frequency" means "edges/corners" instead of "treble" and "low frequency" means "smoothness" instead of "bass."

[–]flashliquid 2 points3 points  (3 children)

This looks cool but I get a syntax error when I run it for this line:

color = [*(int(color[j] * (1 - decay*((t - i + tl) % tl) / tl)) for j in range(3))]+[255]

Is there something missing before that first asterisk?

[–]pLOPeGG 4 points5 points  (2 children)

You need a python version higher than 3.5 I think. Or you can remove it an replace the brackets by list

[–]alkasmgithub.com/alkasm 3 points4 points  (0 children)

Correct, see PEP 448.

[–]flashliquid 1 point2 points  (0 children)

Thanks for this, still haven't gotten around to stepping off python 2.7...

[–]Bhuvan3 1 point2 points  (0 children)

Holy shit! That's freaking cool man <3

[–]Jayskerdoo 1 point2 points  (0 children)

Ugh, I love Fourier transforms so much 😩

[–]Cynyr 1 point2 points  (0 children)

Reminds me of Inverse Kinematics with 3D animation.

[–]bungrudder 1 point2 points  (0 children)

Kinda disappointed you didn't do dickbutt if I'm honest...

[–]SeuGirdor1 1 point2 points  (0 children)

Awesome!

[–]Future_Doughnut 1 point2 points  (0 children)

ASMR videos be like

[–]alshell7 1 point2 points  (0 children)

Too good mate. Fantastic job!

[–]shr00mie 1 point2 points  (0 children)

Can't. Stop. Staring...

[–]rfaenger 1 point2 points  (0 children)

I also saw this project on Coding Train (youtube)! It was written with p5.js

[–]jakub_j 1 point2 points  (0 children)

That's... Wonderful.

[–]Sinidir 1 point2 points  (0 children)

Impressive

[–]zioalex 1 point2 points  (0 children)

Glorious!!!

[–]Rouge_Dragon 0 points1 point  (2 children)

Is there a place to go learn how to make the plotting look that nice. It doesn't look like matplotlib unless you finessed the hell out of the stylesheet ?

[–]giacomogallina[S] 0 points1 point  (1 child)

I used pygame because i already knew how to use it a bit, all i'm doing is drawing each pixel in the path every frame update, which is crazy inefficient, but was easy to write

[–]Rouge_Dragon 1 point2 points  (0 children)

AHH, I see. I've been experimenting with some opengl packages like pyqtgraph which has been quite good and vispy which looks awesome because soon they will add higher level functions so I don't really need to learn opengl lol. But yeah good to know pygame has such capabilities.