Created
December 11, 2021 21:02
-
-
Save jul/1b85cbda2bad1b97bb13b72d96222d75 to your computer and use it in GitHub Desktop.
préparer un jeu de la vie en base triangulaire (les carrés sucent)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PySimpleGUI as sg | |
### uitliser ipython -i argv[0] pour être en interactif et faire joujou | |
can = sg.Canvas(size=(400,600)) | |
win = sg.Window("titre",[[can,],],finalize=True) | |
c = can.TKCanvas | |
from time import sleep | |
SZ=50 | |
ORD=1 | |
def save(canvas, name="save"): | |
global ORD | |
with open("%s-%04d.ps"% (name, ORD), "w") as f: | |
ORD+=1 | |
f.write(canvas.postscript()) | |
def tr(x,y, up=1,**kw): | |
""" créer un triangle équilatéral inutile! centré en x,y avec une homothétie / | |
symmétrie sur l'axe des y (up / down) exprimée en coordonnées | |
unitaire de suffisamment gros pour voir (histoire de pouvoir grossir | |
diminuer le réseau sans changer le code)""" | |
hs=0.8666 | |
x0,y0=x,y | |
x,y=x*SZ+SZ,y*hs*SZ+SZ | |
# triangle compliqué à dessiner | |
i=c.create_polygon( | |
x+up*SZ/2, y+up*(SZ*hs/3), | |
x-up*SZ/2, y+up*(SZ*hs/3), | |
x, y-up*(SZ*2*hs/3), | |
fill=kw.get("fill"),outline=kw.get("outline","white"),) | |
# fin du truc qui sert à rien pour faire beau | |
# et le truc qui nous intéresse qui paraît polio | |
r=SZ/2.5 | |
c.create_oval(x-r,y-r,x+r,y+r, | |
fill=kw.get("state","red"), outline="white", tags="%d-%d" % (x0,y0)) | |
sleep(.01) | |
c.update() | |
save(c) | |
return i | |
for x in range(0,10,2): | |
for y in range(10): | |
tr( | |
x/2-1/2*(y%2), | |
y-[2/3,1/3][x%2], | |
[-1,1][(x)% 2], | |
fill="white", | |
state = "red" if 2 < x <= 6 and 2 < y < 6 or (x,y)==(2,4) else "blue", | |
outline="black") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment