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

— 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!

3/

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]

/1

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!]

thepythoncodingbook.com/2022/0

and another one…

Here's another example

/14

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

/13

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.

/12

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

/11

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.

/10

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

/9

You can create a 2D sinusoidal grating in using and display it using

/8

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

/7

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

/6

…different amplitudes…

Sinusoidal gratings can have different orientations…

/4

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

/3

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

A sinusoidal grating looks like this…

/2

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👇🧵🪡

/1

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