from math import * from kandinsky import * from turtle import * p=5 for c in range(0, 320, 8): for l in range(0, 222, 8): for i in (0,36): set_pixel(c + (i % 8), l + (i // 8), (0, 0, 0)) hideturtle() pensize(5) penup() goto(-150,13) pendown() goto(0,-62) goto(150,13) def remplir(coul, *u): (ax,ay),(bx,by),(cx,cy),(dx,dy)=u[0] for col in range(min(ax,bx,cx,dx), max(ax,bx,cx,dx)+1): for lig in range(min(ay,by,cy,dy), max(ay,by,cy,dy)+1): if 0 <= col <= 320 and 0 <= lig <= 222: xa,xb,xc,xd = ax-col,bx-col,cx-col,dx-col ya,yb,yc,yd = ay-lig,by-lig,cy-lig,dy-lig d1,d2,d3,d4 = xa*yb-ya*xb,xb*yc-yb*xc,xc*yd-yc*xd,xd*ya-yd*xa u,v,w,t = d1>=0,d2>=0,d3>=0,d4>=0 if u == v == w == t: set_pixel(col,222 - lig,coul) def light(z,g): return ((max(0,min(255,g-4*z)),)*3) def cube(x, y, z, p, c = -1,h=1): x2,y2,z2 = x,y,z-p/h if c != -1: face(x,y,z,((p,0,0),(0,0,-p/h),(-p,0,0)),light(z,80)) face(x,y,z,((0,-p,0),(0,0,-p/h),(0,p,0)),light(z,120)) else: c = 220 * ((x//p + y//p)%2) face(x2,y2,z2,((p,0,0),(0,-p,0),(-p,0,0)),light(z,c)) def face(x,y,z,dd,coul): coord = (pos2D(x,y,z),) for d in dd: x,y,z = x+d[0],y+d[1],z+d[2] coord += (pos2D(x, y, z),) remplir(coul, coord) def pos2D(x,y,z): x2=(x+20)/40 y2=(y+20)/40 z2=(z+20)/50 xe = int(120*(x2+y2)-110) ye = int(155+60*(x2-y2-2*z2)) return xe,ye for x in range(10): for y in range(10,0,-1): cube(p*y,p*x,0, p,h=2) if (y<5 or y>6) and ((x+y)% 2 == 0):cube(p*y,p*x,-4,p/1.7, 20+170 * (y < 5),h=0.85) draw_string("SHALL WE PLAY A GAME ?", 50,190,(255,)*3,(0,)*3)