from PIL import Image,ImageDraw,ImageFont
import qrcode
URL='https://cloud.infero.net/rh-en'
BG=(21,22,20);INK=(236,235,230);MUTE=(155,154,147);ACC=(111,191,148);ACC2=(224,169,79);LINE=(51,52,47)
F='/usr/share/fonts/opentype/noto/NotoSansCJK-%s.ttc'
def f(sz,b=False): return ImageFont.truetype(F%('Bold' if b else 'Regular'),sz,index=2)
def mono(sz): return ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',sz)
def qr(size):
    q=qrcode.QRCode(border=2,box_size=10,error_correction=qrcode.constants.ERROR_CORRECT_M);q.add_data(URL);q.make(fit=True)
    return q.make_image(fill_color=BG,back_color=INK).convert('RGB').resize((size,size),Image.NEAREST)
def crit(d,x0,H,step,r,lab,left=False):
    d.line([(x0,0),(x0,H)],fill=(40,62,50),width=3)
    for y in range(step//2+20,H,step): d.ellipse([x0-r,y-r,x0+r,y+r],outline=ACC,width=3)
    t='Re(s) = ½'; w=d.textlength(t,font=f(lab))
    d.text(((x0-12-w) if left else (x0+12),22),t,font=f(lab),fill=(70,110,90))
def stats(d,x,y,cw,big,small):
    for i,(a,b) in enumerate([('175,187','files'),('17.4 M','lines of Lean'),('3','axioms allowed')]):
        xx=x+i*cw; d.text((xx,y),a,font=f(big,True),fill=ACC2); d.text((xx,y+big*1.3),b,font=f(small),fill=MUTE)

# 1200x675 (Twitter)
W,H=1200,675; im=Image.new('RGB',(W,H),BG); d=ImageDraw.Draw(im)
crit(d,W-70,H,110,7,20,left=True)
L=60;y=48
d.text((L,y),'Qianlu · live build',font=f(26),fill=ACC);y+=56
for line in ['A machine proof of the','Riemann Hypothesis.','Does it compile?']:
    d.text((L,y),line,font=f(58,True),fill=INK);y+=74
y+=24
for line in ['On Nov 20, Levent Alpöge announced he and Claude had','proved RH and formalized it in Lean. We are compiling','all 17 million lines from scratch on a 192-core server.']:
    d.text((L,y),line,font=f(25),fill=MUTE);y+=38
y+=26; stats(d,L,y,235,44,22)
q=qr(300); im.paste(q,(W-70-40-300,150))
qx=W-70-40-300
d.text((qx,470),'Scan for live progress',font=f(26,True),fill=INK)
d.text((qx,510),'axiom check & kernel',font=f(22),fill=MUTE)
d.text((qx,540),'replay posted when done',font=f(22),fill=MUTE)
d.text((L,H-58),'#print axioms riemannHypothesis',font=mono(22),fill=ACC)
d.text((qx,H-58),'cloud.infero.net/rh-en',font=f(22),fill=MUTE)
im.save('/home/ubuntu/qianlu/clones/lean_rh/card/card_en.png',optimize=True)

# 1080x1350 (portrait)
W,H=1080,1350; im=Image.new('RGB',(W,H),BG); d=ImageDraw.Draw(im)
crit(d,W-130,H,130,9,24)
L=72;y=90
d.text((L,y),'Qianlu · live build',font=f(32),fill=ACC);y+=74
for line in ['A machine proof','of the Riemann','Hypothesis.','Does it compile?']:
    d.text((L,y),line,font=f(76,True),fill=INK);y+=88
y+=24
for line in ['On Nov 20, Levent Alpöge announced','he and Claude had proved RH and','formalized it in Lean. We are compiling','all 17 million lines from scratch.']:
    d.text((L,y),line,font=f(33),fill=MUTE);y+=50
y+=30; stats(d,L,y,280,50,26); y+=122
d.line([(L,y),(W-180,y)],fill=LINE,width=2); y+=34
q=qr(290); im.paste(q,(L,y))
tx=L+325
d.text((tx,y+18),'Scan for',font=f(40,True),fill=INK)
d.text((tx,y+68),'live progress',font=f(40,True),fill=INK)
for k,line in enumerate(['updated every minute;','axiom check & kernel','replay posted when done']):
    d.text((tx,y+138+k*44),line,font=f(29),fill=MUTE)
y+=310
d.text((L,y),'#print axioms riemannHypothesis',font=mono(28),fill=ACC)
d.text((L,y+46),'cloud.infero.net/rh-en',font=f(28),fill=MUTE)
im.save('/home/ubuntu/qianlu/clones/lean_rh/card/card_en_1080x1350.png',optimize=True)
