Skip to content

Instantly share code, notes, and snippets.

@gferreira
Last active August 29, 2015 14:23
Show Gist options
  • Save gferreira/1be5035b4121101537ef to your computer and use it in GitHub Desktop.
Save gferreira/1be5035b4121101537ef to your computer and use it in GitHub Desktop.
International Maritime Signal Flags — CodeFont Remix
"""
International Maritime Signal Flags
by Christopher P. Cacho @thenss
CodeFont Remix by Gustavo Ferreira @hipertipo
"""
# colors
white = 1, .99, .90
black = .28
blue = .29, .47, .79
yellow = .92, .80, .26
red = .79, .29, .29
# flag drawing functions
def Alfa():
fill(*white)
rect(0, 0, 100, 200)
path = BezierPath()
path.moveTo((100, 100))
path.lineTo((100, 200))
path.lineTo((200, 200))
path.lineTo((120, 100))
path.lineTo((200, 0))
path.lineTo((100, 0))
path.closePath()
fill(*blue)
drawPath(path)
def Bravo():
path = BezierPath()
path.moveTo((0, 0))
path.lineTo((0, 200))
path.lineTo((200, 200))
path.lineTo((120, 100))
path.lineTo((200, 0))
path.lineTo((100, 0))
path.closePath()
fill(*red)
drawPath(path)
def Charlie():
fill(*white)
rect(0, 0, 200, 200)
fill(*blue)
rect(0, 0, 200, 40)
fill(*red)
rect(0, 80, 200, 40)
fill(*blue)
rect(0, 160, 200, 40)
def Delta():
fill(*blue)
rect(0, 0, 200, 200)
fill(*yellow)
rect(0, 0, 200, 50)
rect(0, 150, 200, 50)
def Echo():
fill(*red)
rect(0, 0, 200, 100)
fill(*blue)
rect(0, 100, 200, 100)
def Foxtrot():
fill(*white)
rect(0, 0, 200, 200)
path = BezierPath()
path.moveTo((100, 100))
path.lineTo((0, 100))
path.lineTo((100, 200))
path.lineTo((200, 100))
path.lineTo((100, 0))
path.lineTo((0, 100))
path.closePath()
fill(*red)
drawPath(path)
def Golf():
fill(*blue)
rect(0, 0, 33.333333333, 200)
fill(*yellow)
rect(33.333333333, 0, 33.333333333, 200)
fill(*blue)
rect(66.666666666, 0, 33.333333333, 200)
fill(*yellow)
rect(99.999999999, 0, 33.333333333, 200)
fill(*blue)
rect(133.333333332, 0, 33.333333333, 200)
fill(*yellow)
rect(166.666666665, 0, 33.333333333, 200)
def Hotel():
fill(*white)
rect(0, 0, 100, 200)
fill(*red)
rect(100, 0, 100, 200)
def India():
fill(*yellow)
rect(0, 0, 200, 200)
fill(black)
oval(60, 60, 80, 80)
def Juliet():
fill(*white)
rect(0, 0, 200, 200)
fill(*blue)
rect(0, 0, 200, 50)
fill(*blue)
rect(0, 150, 200, 50)
def Kilo():
fill(*yellow)
rect(0, 0, 100, 200)
fill(*blue)
rect(100, 0, 100, 200)
def Lima():
fill(*yellow)
rect(0, 0, 200, 200)
fill(.28)
rect(0, 0, 100, 100)
rect(100, 100, 100, 100)
def Mike():
fill(*blue)
rect(0, 0, 200, 200)
path = BezierPath()
path.moveTo((0, 200))
path.lineTo((15, 200))
path.lineTo((200, 15))
path.lineTo((200, 0))
path.lineTo((185, 0))
path.lineTo((0, 185))
path.moveTo((200, 200))
path.lineTo((200, 185))
path.lineTo((15, 0))
path.lineTo((0, 0))
path.lineTo((0, 15))
path.lineTo((185, 200))
path.closePath()
fill(*white)
drawPath(path)
def November():
fill(*white)
rect(0, 0, 200, 200)
fill(*blue)
rect(0, 50, 50, 50)
rect(0, 150, 50, 50)
rect(50, 0, 50, 50)
rect(50, 100, 50, 50)
rect(100, 50, 50, 50)
rect(100, 150, 50, 50)
rect(150, 0, 50, 50)
rect(150, 100, 50, 50)
def Oscar():
fill(*yellow)
rect(0, 0, 200, 200)
path = BezierPath()
path.moveTo((0, 200))
path.lineTo((200, 200))
path.lineTo((200, 0))
path.lineTo((0, 200))
path.closePath()
fill(*red)
drawPath(path)
def Papa():
fill(*blue)
rect(0, 0, 200, 200)
fill(*white)
rect(50, 50, 100, 100)
def Quebec():
fill(*yellow)
rect(0, 0, 200, 200)
def Romeo():
fill(*red)
rect(0, 0, 200, 200)
fill(*yellow)
rect(75, 0, 50, 200)
rect(0, 75, 200, 50)
def Sierra():
fill(*white)
rect(0, 0, 200, 200)
fill(*blue)
rect(50, 50, 100, 100)
def Tango():
fill(*white)
rect(0, 0, 200, 200)
fill(*red)
rect(0, 0, 66.666666667, 200)
fill(*blue)
rect(133.333333333, 0, 66.666666667, 200)
def Uniform():
fill(*red)
rect(0, 0, 200, 200)
fill(*white)
rect(0, 0, 100, 100)
rect(100, 100, 100, 100)
def Victor():
fill(*white)
rect(0, 0, 200, 200)
path = BezierPath()
path.moveTo((0, 200))
path.lineTo((15, 200))
path.lineTo((200, 15))
path.lineTo((200, 0))
path.lineTo((185, 0))
path.lineTo((0, 185))
path.moveTo((200, 200))
path.lineTo((200, 185))
path.lineTo((15, 0))
path.lineTo((0, 0))
path.lineTo((0, 15))
path.lineTo((185, 200))
path.closePath()
fill(*red)
drawPath(path)
def Whiskey():
fill(*blue)
rect(0, 0, 200, 200)
fill(*white)
rect(50, 50, 100, 100)
fill(*red)
rect(75, 75, 50, 50)
def Xray():
fill(*white)
rect(0, 0, 200, 200)
fill(*blue)
rect(75, 0, 50, 200)
rect(0, 75, 200, 50)
def Yankee():
fill(*red)
rect(0, 0, 200, 200)
B = BezierPath()
B.rect(0, 0, 200, 200)
save()
clipPath(B)
stroke(*yellow)
strokeWidth(25)
line((-10, 180), (20, 210))
line((-10, 110), (90, 210))
line((-10, 30), (170, 210))
line((-10, -55), (253, 210))
line((-10, -130), (325, 210))
line((-10, -190), (400, 210))
restore()
def Zulu():
fill(black)
rect(0, 0, 200, 200)
path = BezierPath()
path.moveTo((0, 200))
path.lineTo((200, 200))
path.lineTo((100, 100))
path.closePath()
fill(*red)
drawPath(path)
path = BezierPath()
path.moveTo((0, 200))
path.lineTo((0, 0))
path.lineTo((100, 100))
path.closePath()
fill(*blue)
drawPath(path)
path = BezierPath()
path.moveTo((0, 0))
path.lineTo((200, 0))
path.lineTo((100, 100))
path.closePath()
fill(*yellow)
drawPath(path)
def Zero():
fill(*white)
rect(0, 0, 200, 200)
fill(*blue)
rect(30, 20, 15, 40)
rect(18, 32, 40, 15)
fill(*blue)
rect(152, 20, 15, 40)
rect(140, 32, 40, 15)
fill(*blue)
rect(90, 80, 15, 40)
rect(78, 92, 40, 15)
fill(*blue)
rect(30, 140, 15, 40)
rect(18, 152, 40, 15)
fill(*blue)
rect(152, 140, 15, 40)
rect(140, 152, 40, 15)
def One():
fill(*yellow)
rect(0, 0, 200, 200)
fill(*red)
rect(0, 0, 200, 50)
rect(0, 150, 200, 50)
def Two():
fill(*red)
rect(0, 0, 200, 200)
fill(*yellow)
rect(0, 0, 200, 50)
rect(0, 150, 200, 50)
def Three():
fill(*red)
rect(0, 0, 200, 200)
fill(*blue)
rect(0, 0, 200, 50)
rect(0, 150, 200, 50)
def Four():
fill(*red)
rect(0, 0, 200, 200)
path = BezierPath()
path.moveTo((0, 200))
path.lineTo((15, 200))
path.lineTo((200, 15))
path.lineTo((200, 0))
path.lineTo((185, 0))
path.lineTo((0, 185))
path.moveTo((200, 200))
path.lineTo((200, 185))
path.lineTo((15, 0))
path.lineTo((0, 0))
path.lineTo((0, 15))
path.lineTo((185, 200))
path.closePath()
fill(*white)
drawPath(path)
def Five():
fill(*yellow)
rect(0, 0, 200, 200)
path = BezierPath()
path.moveTo((0, 200))
path.lineTo((15, 200))
path.lineTo((200, 15))
path.lineTo((200, 0))
path.lineTo((185, 0))
path.lineTo((0, 185))
path.moveTo((200, 200))
path.lineTo((200, 185))
path.lineTo((15, 0))
path.lineTo((0, 0))
path.lineTo((0, 15))
path.lineTo((185, 200))
path.closePath()
fill(*blue)
drawPath(path)
def Six():
fill(*blue)
rect(0, 0, 200, 200)
B = BezierPath()
B.rect(0, 0, 200, 200)
save()
clipPath(B)
stroke(*white)
strokeWidth(40)
line((-20, 160), (40, 220))
line((-20, 30), (170, 220))
line((-20, -80), (280, 220))
line((-20, -190), (400, 220))
restore()
def Seven():
fill(*white)
rect(0, 0, 200, 200)
fill(*red)
rect(0, 0, 66.666666667, 200)
rect(133.333333333, 0, 66.666666667, 200)
def Eight():
fill(*blue)
rect(0, 0, 200, 200)
fill(*yellow)
rect(0, 0, 66.666666667, 200)
rect(133.333333333, 0, 66.666666667, 200)
def Nine():
fill(*white)
rect(0, 0, 200, 200)
fill(*blue)
rect(0, 0, 66.666666667, 200)
rect(133.333333333, 0, 66.666666667, 200)
# character-to-flag dictionary
Flags = {
'A' : Alfa,
'B' : Bravo,
'C' : Charlie,
'D' : Delta,
'E' : Echo,
'F' : Foxtrot,
'G' : Golf,
'H' : Hotel,
'I' : India,
'J' : Juliet,
'K' : Kilo,
'L' : Lima,
'M' : Mike,
'N' : November,
'O' : Oscar,
'P' : Papa,
'Q' : Quebec,
'R' : Romeo,
'S' : Sierra,
'T' : Tango,
'U' : Uniform,
'V' : Victor,
'W' : Whiskey,
'X' : Xray,
'Y' : Yankee,
'Z' : Zulu,
'0' : Zero,
'1' : One,
'2' : Two,
'3' : Three,
'4' : Four,
'5' : Five,
'6' : Six,
'7' : Seven,
'8' : Eight,
'9' : Nine,
}
# text input ui
Variable([
{
'name' : "txt",
'ui' : "EditText",
'args' : {
'text' : 'the quick brown fox jumps over the lazy dog 012346789',
},
}
], globals())
# flag size
s = 20.0
# flag scale
f = s / 200
# margin
m = s * 0.5
# tracking
t = s * 0.2
# position
x, y = m, m
# document size
w = (len(txt) * s) + ((len(txt) - 1) * t) + (2 * m)
h = s + (2 * m)
# draw it!
size(w, h)
fill(0.6)
rect(0, 0, w, h)
translate(x, y)
for char in txt.upper():
save()
scale(f)
# get glyph
try:
Flags[char]()
# .notdef
except:
pass
# character caption
fill(0)
font('Verdana Bold')
fontSize(s*2)
text(char, (x, -s*3))
restore()
translate(s + t, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment