compression/mini update of https://my.numworks.com/python/schraf/autopong
from kandinsky import fill_rect as F from random import* from time import* br=[] class b: def __init__(s,x,y,coul):s.x,s.y,s.coul,s.vx,s.vy=x,y,coul,4,4 def dB(s): for c in(-1,0,1): x=s.x//16+c if 20>x>=0: for r in(-1,0,1): y=s.y//16+r if 14>y>=0:F(x*16,y*16,16,16,br[x][y]) F(s.x,s.y,16,16,s.coul) def a(s): s.x+=s.vx;s.y+=s.vy if(0<s.x<304)^1:s.vx*=-1 if(0<s.y<208)^1:s.vy*=-1 def c(s): for d in range(20): for r in range(14): cB=br[d][r];x,y=d*16,r*16 if x+8>s.x>x-8 and y+8>s.y>y-8 and cB==s.coul:br[d][r]='purple'if cB=='orange'else'orange';s.vx*=-1 b1=b(180,4*randint(1,50),'purple') b2=b(32,4*randint(1,50),'orange') for d in range(20): br.append([]) for r in range(14):br[d].append('purple'if d<10 else'orange');F(d*16,r*16,16,16,br[d][r]) while 1: b1.dB();b2.dB() b1.c();b2.c() b1.a();b2.a() sleep(.01)