Show more

Using Python to create a solar system

If anyone is looking for a fun exercise to flex their fingers…

Using just gravitational attraction between bodies, you can create your own 2D solar system with as many stars and planets as you want. Here’s a binary star system with some relatively stable planets

Here’s the article, including a detailed step-by-step tutorial, if you want to read more: Simulating Orbiting Planets in a Solar System Using Python

…and there’s also a 3D version (next post)

Addendum (some sad news): Since taking those pictures for the article, that sole remaining espresso cup has suffered this fate

I was told I can’t say Rest In Pieces

Show thread

— 2 —
You press the "On" button—this is equivalent to calling the function.

You can almost see the similarity between the typical "On" button and the parentheses ( ) used to call a function in Python!


Show thread

As it’s time for my morning coffee (the coffee not the biscuits), it’s as good a time as any to share my one of my favourite analogies

(narrated from a -viewpoint but general enough for in general)

The Coffee Machine - Function analogy

Let’s make some coffee…

[read on]


is for serious stuff, sure, but one of the most fun modules is the `turtle` module, but…

I know, I can hear you say: "That's just for drawing simple, boring drawings, right"

Think again! Here's a great learning project that is not merely a "boring set of squares!"

You can follow the detailed step-by-step tutorial here [WARNING: game is addictive and may adversely affect your productivity!]

And therefore, you can reconstruct the image by adding all of those sinusoidal gratings together.

The more gratings you add, the closer the result is to the actual image


Show thread

Now, here’s the “magical” part of theory.

Any image is made up of lots of sinusoidal gratings. So, the 2D Fourier Transform of an image gives you thousands of pairs of dots, and each pair represent a sinusoidal grating.


Show thread

Now, if you have lots of gratings superimposed on each other, the gives you a pair of dots for each of the components


Show thread

You can find the parameters of a sinusoidal grating by using the 2D .

The dots shown contain the amplitude and phase of the grating. Their position from the centre gives the frequency, and their orientation represents the orientation of the grating.


Show thread

Or even better, you can use a function of both x and y to make any grating


Show thread

There's one more parameter that defines a sinusoidal grating: the phase. Gratings with a different phase are shifted with respect to each other…


Show thread

…and different frequencies—these are spatial frequencies, not temporal ones


Show thread

It’s called a sinusoidal grating because the grayscale values vary according to the sine function.

If you plot the values along a horizontal line of the grating, you’ll get a plot of a sine function


Show thread

Any image can be reconstructed from a series of sinusoidal gratings.

A sinusoidal grating looks like this…


Show thread

What's an image made of?

There are many correct answers.

But the most fascinating one is: << sines & cosines >>

Read on if you're intrigued👇🧵🪡


Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.