Skip to content

Instantly share code, notes, and snippets.

@ziot

ziot/retracing.py

Created May 20, 2021
Embed
What would you like to do?
The python script we used to validate angles and retrace the whitepaper
import math
from PIL import Image, ImageDraw, ImageFont
def getText():
f = open("whitepaper.txt", "r")
return f.read()
text = getText()
height = 8192
width = 8192
prevSet = [0,0]
prevSetX, prevSetY = [4096,4096]
set = []
# im = Image.new('RGB', (height, width), (255, 255, 255))
im = Image.open('zd3n.png')
draw = ImageDraw.Draw(im)
font = ImageFont.truetype("verdana.ttf", 13)
for idx,char in enumerate(text):
set.append(char)
if len(set)==2:
set[0] = (ord(set[0])-96)
set[1] = -1*(ord(set[1])-96)
setX = prevSetX + set[0]*4
setY = prevSetY - set[1]*4
finalSetX = setX % 8192
finalSetY = setY % 8192
if finalSetX != setX or finalSetY != setY:
if finalSetY != setY:
if finalSetY > setY:
finalSetY = finalSetY-6
else:
finalSetY = finalSetY+6
else:
if finalSetX > setX:
finalSetX = finalSetX-6
else:
finalSetX = finalSetX+6
setX = finalSetX
setY = finalSetY
lineColor = "blue"
textColor = "white"
textBorderColor = "green"
else:
lineColor = "red"
textColor = "white"
textBorderColor = "green"
upTill = 13300
if idx>=upTill:
lineColor = "orange"
textColor = "white"
textBorderColor = "orange"
# print(prevSet, set, prevSetX, prevSetY, setX, setY, finalSetX, finalSetY, color)
draw.line((prevSetX, prevSetY, setX, setY), fill=lineColor, width=4)
text = str(idx)
draw.text((setX-1, setY-1), text, font=font, fill=textBorderColor)
draw.text((setX+1, setY-1), text, font=font, fill=textBorderColor)
draw.text((setX-1, setY+1), text, font=font, fill=textBorderColor)
draw.text((setX+1, setY+1), text, font=font, fill=textBorderColor)
draw.text((setX,setY), text, font = font, fill=textColor)
prevSet = set
prevSetX, prevSetY = setX, setY
set = []
im.save('test.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment