Draw many country flags with the great Python Turtle. Have fun!
If you are learning Python, please do not simply copy/paste the source code from here because you will not really learn programming :-(... Instead, try first to do your programming homeworks & challenges then come back to have a look to what I propose here... and the most important: Have fun programming the Python Turtle 😄.
There are various ways for drawing flags, hereafter my own requirements list:
- No Python external modules to avoid dependencies (PIL, svg, pygame...).
- Country flags close to original ones.
- Not "too complex" Python code.
- Country drawing flag functions as short as possible using good and readable helpers, in order to be easily copy/paste somewhere else. Below a short example:
def flag_Bulgaria(x, y, width, height):
horizontal_strips(x, y, width, height, 'white', '#00966E', '#D62612')
def flag_China(x, y, width, height):
rectangle_filled_color(x, y, width, height, '#DE2910')
bsw = width * 19 / 100 # big star width
ssw = bsw / 3 # small star width
ct.color('#FFDE00')
five_pointed_star_filled(x + width * 1/6, y - height * 1/4, bsw)
five_pointed_star_filled(x + width * 1/3, y - height * 1/10, ssw, 360-23)
five_pointed_star_filled(x + width * 2/5, y - height * 1/5, ssw, 360-46)
five_pointed_star_filled(x + width * 2/5, y - height * 7/20, ssw, 360-70)
five_pointed_star_filled(x + width * 1/3, y - height * 9/20, ssw, 360-21)
...
# Draw flags (simple function calls)
flag_Bulgaria(0, 0, 100, 67)
flag_China(0, 100, 100, 67)
...
Of course, another solution could be to download Wikipedia svg flags and to draw them with a Python svg library but it was not the goal here 😄.
Yes, you can do whatever you want with the source code here. Please have a look to the LICENSE file.
If you have any comments or questions, feel free to send me an email at [email protected] 📧.
--
Peace
coolcornucopia 😄