Last active
September 21, 2020 05:45
-
-
Save sXakil/45c1e6c0747d3918b66ce4d65c63343b to your computer and use it in GitHub Desktop.
A python turtle drawing of the map of Bangladesh. Uses the same idea as this- https://gist.github.com/sXakil/d7e88da11830dc1370cb7f89b5ebaae1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import turtle | |
pen = turtle.Turtle() | |
pen.ht() | |
pen.speed(0) | |
pen.penup() | |
generator = "ED.GDAD.DLEB.COCC.CV.FS.HQ.JN.MP.Go.Cr.Cq.Cp.Fk.Jf.J`.I`.H`ID.J^HE.K^FG.N[" \ | |
"ABCG.L`CG.MTBT.MUCS.NTDBCBAJ.NUBBHI.OTMI.OROI.OGDCSI.PE[I.RC[I.rBDB.rB.sB.tB " | |
colors = ["#239B56", "#28B463", "#2ECC71", "#58D68D", "#82E0AA", | |
"#F1948A", "#EC7063", "#E74C3C", "#CB4335", "#E74C3C", "#EC7063", "#F1948A", | |
"#82E0AA", "#58D68D", "#2ECC71", "#28B463"] | |
x = -350.00 | |
y = 300.00 | |
switch = 0 | |
idx = 0 | |
RECT_WIDTH = 4 | |
RECT_HEIGHT = 12 | |
LINE_SPACING = 14 | |
pen.goto(x, y) | |
for c in generator: | |
pen.pencolor(colors[idx % len(colors)]) | |
width = ord(c) - 64 | |
if ord(c) == 46: | |
y -= LINE_SPACING | |
switch += 1 | |
pen.setpos(x, y) | |
idx += 1 | |
elif switch % 2 == 0: | |
pen.penup() | |
pen.fd(width * RECT_WIDTH * 2) | |
else: | |
for i in range(width): | |
pen.pendown() | |
pen.rt(90) | |
pen.fd(RECT_HEIGHT) | |
pen.lt(90) | |
pen.fd(RECT_WIDTH) | |
pen.lt(90) | |
pen.fd(RECT_HEIGHT) | |
pen.rt(90) | |
pen.fd(RECT_WIDTH) | |
pen.penup() | |
switch += 1 | |
turtle.done() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment