from PIL import Image,ImageDraw,ImageFont
import qrcode
URL='https://cloud.infero.net/pages/rh-8a933a16a0/'
W,H=1080,1580
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)
mono=ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',30)
im=Image.new('RGB',(W,H),BG);d=ImageDraw.Draw(im)
# 背景：临界线 Re(s)=1/2 与零点
x0=W-170
d.line([(x0,0),(x0,H)],fill=(40,62,50),width=3)
for y in range(90,H,137): d.ellipse([x0-9,y-9,x0+9,y+9],outline=ACC,width=3)
d.text((x0+16,40),'Re(s) = ½',font=ImageFont.truetype(F%'Regular',26,index=2),fill=(70,110,90))
L=80;y=120
d.text((L,y),'千路 · 实时编译',font=f(34),fill=ACC);y+=80
for line in ['一份黎曼猜想的','机器证明，','编得过吗？']:
    d.text((L,y),line,font=f(92,True),fill=INK);y+=122
y+=26
for line in ['数学家 Levent Alpöge 11 月 20 日宣布：','他和 Claude 证明了黎曼猜想，','并在 Lean 里写成了 1737 万行代码。','我们正在一台 192 核的服务器上从头编译。']:
    d.text((L,y),line,font=f(38),fill=MUTE);y+=58
y+=40
stats=[('175,187','个文件'),('1737 万','行 Lean'),('3 条','允许的公理')]
cw=(W-2*L-170)//3
for i,(a,b) in enumerate(stats):
    xx=L+i*(cw+10)
    d.text((xx,y),a,font=f(54,True),fill=ACC2); d.text((xx,y+72),b,font=f(30),fill=MUTE)
y+=150
d.line([(L,y),(W-L-150,y)],fill=LINE,width=2);y+=40
# 二维码
qr=qrcode.QRCode(border=2,box_size=10,error_correction=qrcode.constants.ERROR_CORRECT_M);qr.add_data(URL);qr.make(fit=True)
q=qr.make_image(fill_color=(21,22,20),back_color=(236,235,230)).convert('RGB').resize((340,340),Image.NEAREST)
im.paste(q,(L,y))
tx=L+380
d.text((tx,y+20),'扫码看进度',font=f(48,True),fill=INK)
for k,line in enumerate(['每分钟更新：编了多少、','花了多少钱；','编完后公布公理检查','和内核重放的结果。']):
    d.text((tx,y+100+k*52),line,font=f(34),fill=MUTE)
y+=375
d.text((L,y),'#print axioms riemannHypothesis',font=mono,fill=ACC)
d.text((L,y+50),'cloud.infero.net/pages/rh-8a933a16a0',font=f(28),fill=MUTE)
im.save('/home/ubuntu/qianlu/clones/lean_rh/card/card.png',optimize=True)
