Semaphore Code Using Python Turtle

flag-semaphoreFlag semaphore is a telegraphy system conveying information at a distance by means of visual signals with hand-held flags. Information is encoded by the position of the flags. The current flag semaphore system uses two short poles with square flags, which a signalman holds in different positions to signal letters of the alphabet and numbers. The signalman holds one pole in each hand, and extends each arm in one of eight possible directions. At sea, the flags are coloured red and yellow, while on land, they are white and blue.

The following table shows all the different flag positions to represent the 26 letters of the alphabet and the number digits 0 to 9:

Click on the picture to zoom in

Click on the picture to zoom in

Python Turtle Code


We have created an animation that will scan all the characters of a message and animate the signalman to display the right semaphore flags for each character in the message.

For this demo, the message variable is set on line 45 to “ABCDEFGHIJKLMNOPQRSTUVWXYZ” but you can change this message to any text.

message = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Our code also uses a dictionary called semaphore to store the 26 characters of the alphabet (and the space character). For each key of this dictionary, we store the two angles used to define the position of both arms using the following angles:
semaphore-angles

A dictionary is used to store the angles of both flags, for each character of the alphabet.

A dictionary is used to store the angles of both flags, for each character of the alphabet.

Did you like this challenge?

Click on a star to rate it!

Average rating 4.6 / 5. Vote count: 9

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,