separated drawing function, sigil functions generate coordinate lists
This commit is contained in:
parent
a4278682ce
commit
1b736b876f
1 changed files with 56 additions and 63 deletions
119
sigilize.py
119
sigilize.py
|
|
@ -57,78 +57,45 @@ def astroChart(lat, lon, epoch, canvas, colors = ['violet', 'yellow', 'white', '
|
|||
radius = 180 + i * 10
|
||||
canvas.append(svg.ArcLine(0, 0, radius, startArc, endArc, stroke=circleColor, stroke_width=7, fill='none'))
|
||||
|
||||
def magicSquareSigil(plusCode, canvas, color='white'): # draw sigil based on OLC magic square
|
||||
def magicSquareSigil(plusCode): # create sigil coordinates based on OLC magic square
|
||||
|
||||
codeList = list(plusCode.replace('+', '')) # remove the + in the string
|
||||
print("sigilizing", codeList)
|
||||
length = len(codeList)
|
||||
coordList = []
|
||||
grid = {
|
||||
'R' : [-103, 112], 'V' : [-35, 112], 'W' : [35, 112], 'X' : [103, 112], # | R | V | W | X |
|
||||
'J' : [-103, 56], 'M' : [-35, 56], 'P' : [35, 56], 'Q' : [103, 56], # | J | M | P | Q |
|
||||
'C' : [-103, 0], 'F' : [-35, 0], 'G' : [35, 0], 'H' : [103, 0], # | C | F | G | H |
|
||||
'6' : [-103, -56], '7' : [-35, -56], '8' : [35, -56], '9' : [103, -56], # | 6 | 7 | 8 | 9 |
|
||||
'2' : [-103, -112], '3' : [-35, -112], '4' : [35, -112], '5' : [103, -112] # | 2 | 3 | 4 | 5 |
|
||||
'R' : [-105, 112], 'V' : [-35, 112], 'W' : [35, 112], 'X' : [105, 112], # | R | V | W | X |
|
||||
'J' : [-105, 56], 'M' : [-35, 56], 'P' : [35, 56], 'Q' : [105, 56], # | J | M | P | Q |
|
||||
'C' : [-105, 0], 'F' : [-35, 0], 'G' : [35, 0], 'H' : [105, 0], # | C | F | G | H |
|
||||
'6' : [-105, -56], '7' : [-35, -56], '8' : [35, -56], '9' : [105, -56], # | 6 | 7 | 8 | 9 |
|
||||
'2' : [-105, -112], '3' : [-35, -112], '4' : [35, -112], '5' : [105, -112] # | 2 | 3 | 4 | 5 |
|
||||
}
|
||||
|
||||
# setup sigil
|
||||
dash = svg.Marker(-0.5, -0.5, 0.5, 0.5, scale=5, orient='auto') # define line to terminate the sigil
|
||||
dash.append(svg.Line(-0., -0.5, 0., 0.5, stroke_width=0.2, stroke=color))
|
||||
dot = svg.Marker(-0.8, -0.5, 0.5, 0.5, scale=5, orient='auto') # define circle to start the sigil
|
||||
dot.append(svg.Circle(-0.3, 0.0, 0.3, stroke_width=0.2, stroke=color, fill='none'))
|
||||
p = svg.Path(stroke_width=7, stroke=color, fill='none', marker_start=dot, marker_end=dash)
|
||||
for char in codeList:
|
||||
coordList.append(grid[char]) # write center coordinates to sigil coordinate list
|
||||
return coordList
|
||||
|
||||
# draw sigil
|
||||
for c in range(length):
|
||||
if c == 0:
|
||||
originX = grid[codeList[0]][0]
|
||||
originY = grid[codeList[0]][1]
|
||||
p.M(originX, originY)
|
||||
else:
|
||||
x = grid[codeList[c]][0] - originX # abs. to rel. coords
|
||||
y = grid[codeList[c]][1] - originY # abs. to rel. coords
|
||||
p.l(x, y) # draw
|
||||
originX = grid[codeList[c]][0]
|
||||
originY = grid[codeList[c]][1]
|
||||
|
||||
# add to canvas
|
||||
canvas.append(p)
|
||||
|
||||
def radialSigil(plusCode, canvas, color='red'): # draw sigil based on concentric circle positions
|
||||
def radialSigil(plusCode): # create sigil coordinates based on concentric circle positions
|
||||
|
||||
codeList = list(plusCode.replace('+', '')) # remove the + in the string
|
||||
print("sigilizing", codeList)
|
||||
length = len(codeList)
|
||||
coordList = []
|
||||
decoder = ['2', '3', '4', '5', '6', '7', '8', '9', 'C', 'F', 'G', 'H', 'J', 'M', 'P', 'Q', 'R', 'V', 'W', 'X']
|
||||
|
||||
#draw global area sigil
|
||||
arrow2 = svg.Marker(-0.5, -0.5, 0.5, 0.5, scale=5, orient='auto') # define line to terminate the sigil
|
||||
arrow2.append(svg.Line(-0., -0.5, 0., 0.5, stroke_width=0.2, stroke=color))
|
||||
dot2 = svg.Marker(-0.8, -0.5, 0.5, 0.5, scale=5, orient='auto') # define circle to start the sigil
|
||||
dot2.append(svg.Circle(-0.3, 0.0, 0.3, stroke_width=0.2, stroke=color, fill='none'))
|
||||
# set up sigil path
|
||||
p = svg.Path(stroke_width=7, stroke=color, fill='none', marker_start=dot2, marker_end=arrow2)
|
||||
|
||||
for c in range(length):
|
||||
index = decoder.index(codeList[c])
|
||||
|
||||
count = 0
|
||||
for char in codeList:
|
||||
index = decoder.index(char)
|
||||
# find coordinates on circle every 18° (360° / 20 digits)
|
||||
radius = 145 - c * 20
|
||||
radius = 145 - count * 20
|
||||
angle = 18 * index
|
||||
x = radius * math.cos(angle)
|
||||
y = radius * math.sin(angle)
|
||||
coordList.append([x, y]) # write center coordinates to sigil coordinate list
|
||||
count = count + 1
|
||||
|
||||
if c == 0:
|
||||
p.M(x,y) # starting point
|
||||
originX = x
|
||||
originY = y
|
||||
else:
|
||||
p.l(x - originX, y - originY) # draw
|
||||
originX = x
|
||||
originY = y
|
||||
|
||||
canvas.append(p)
|
||||
return coordList
|
||||
|
||||
def nameToPlusCode(name): # turns an alphabetic string into a sigilizable plusCode
|
||||
|
||||
def nameToPlusCode(name):
|
||||
vowels = [ 'A', 'E', 'I', 'O', 'U']
|
||||
translate = {
|
||||
'B' : '2',
|
||||
|
|
@ -141,15 +108,41 @@ def nameToPlusCode(name):
|
|||
'Z' : '9',
|
||||
'Y' : 'J'
|
||||
}
|
||||
newName = name.upper().replace(" ", "")
|
||||
newName = name.upper().replace(" ", "") # make all uppercase and get rid of spaces
|
||||
for x in newName:
|
||||
if x in vowels:
|
||||
newName = newName.replace(x,"")
|
||||
newName = newName.replace(x,"") # get rid of all vowels
|
||||
if x in translate.keys():
|
||||
newName = newName.replace(x, translate[x])
|
||||
newName = newName.replace(x, translate[x]) # translate consonant string into plusCode
|
||||
|
||||
return newName
|
||||
|
||||
def drawSigil(lat, lon, epoch, squareSigilize, radialSigilize, fileName):
|
||||
def drawSigil(points, canvas, color='white'): # draw sigil from coordinate list
|
||||
|
||||
# setup sigil
|
||||
dash = svg.Marker(-0.5, -0.5, 0.5, 0.5, scale=5, orient='auto') # define line to terminate the sigil
|
||||
dash.append(svg.Line(-0., -0.5, 0., 0.5, stroke_width=0.2, stroke=color))
|
||||
dot = svg.Marker(-0.8, -0.5, 0.5, 0.5, scale=5, orient='auto') # define circle to start the sigil
|
||||
dot.append(svg.Circle(-0.3, 0.0, 0.3, stroke_width=0.2, stroke=color, fill='none'))
|
||||
p = svg.Path(stroke_width=7, stroke=color, fill='none', marker_start=dot, marker_end=dash)
|
||||
|
||||
# draw sigil
|
||||
for point in points:
|
||||
if points.index(point) == 0:
|
||||
originX = point[0]
|
||||
originY = point[1]
|
||||
p.M(originX, originY)
|
||||
else:
|
||||
x = point[0] - originX # abs. to rel. coords
|
||||
y = point[1] - originY # abs. to rel. coords
|
||||
p.l(x, y) # draw
|
||||
originX = point[0]
|
||||
originY = point[1]
|
||||
|
||||
# add to canvas
|
||||
canvas.append(p)
|
||||
|
||||
def createSigil(lat, lon, epoch, squareSigilize, radialSigilize, fileName): # function called by main() according to CLI arguments
|
||||
|
||||
# set up SVG canvas
|
||||
d = svg.Drawing(600, 600, origin='center') # define canvas
|
||||
|
|
@ -173,8 +166,8 @@ def drawSigil(lat, lon, epoch, squareSigilize, radialSigilize, fileName):
|
|||
astroChart(lat, lon, epoch, d, [rusty, rusty, rusty, rusty, rusty, rusty, rusty, rusty])
|
||||
|
||||
# draw sigils
|
||||
radialSigil(radialSigilize, d, rusty)
|
||||
magicSquareSigil(squareSigilize, d, silver)
|
||||
drawSigil( radialSigil(radialSigilize), d, rusty)
|
||||
drawSigil( magicSquareSigil(squareSigilize), d, silver)
|
||||
|
||||
# save sigil to SVG file
|
||||
d.saveSvg(fileName)
|
||||
|
|
@ -191,7 +184,7 @@ def main():
|
|||
squareSigilize = nameToPlusCode(sys.argv[4]) # first name
|
||||
radialSigilize = nameToPlusCode(sys.argv[5]) # last name
|
||||
fileName = '%s_%s.svg' % (sys.argv[5], sys.argv[4])
|
||||
drawSigil(lat, lon, epoch, squareSigilize, radialSigilize, fileName)
|
||||
createSigil(lat, lon, epoch, squareSigilize, radialSigilize, fileName)
|
||||
|
||||
if argNo == 3: # if coordinates, and timestamp are provided
|
||||
|
||||
|
|
@ -202,7 +195,7 @@ def main():
|
|||
squareSigilize = plusCode[4:]
|
||||
radialSigilize = plusCode[0:4]
|
||||
fileName = '%s-%s.svg' % (plusCode, epoch)
|
||||
drawSigil(lat, lon, epoch, squareSigilize, radialSigilize, fileName)
|
||||
createSigil(lat, lon, epoch, squareSigilize, radialSigilize, fileName)
|
||||
|
||||
|
||||
if argNo == 2: # if just coordinates are provided
|
||||
|
|
@ -214,7 +207,7 @@ def main():
|
|||
squareSigilize = plusCode[4:]
|
||||
radialSigilize = plusCode[0:4]
|
||||
fileName = '%s-%s.svg' % (plusCode, epoch)
|
||||
drawSigil(lat, lon, epoch, squareSigilize, radialSigilize, fileName)
|
||||
createSigil(lat, lon, epoch, squareSigilize, radialSigilize, fileName)
|
||||
else:
|
||||
print("--------------------------------------------")
|
||||
print("Please provide arguments: <decimal latitude> <decimal longitude> (<epoch timestamp> <first name> <last name>)")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue