in the main loop i call the sleep() function but when i execute my code, it just wait 300 times 0.01 seconds and it then displays the last frame for i=299.
from tkinter import *
from time import *
#Those are functions a friend gave me in order to darw stuff pixel by pixel
tk=Tk()
tk.attributes('-fullscreen',True)
canvas=Canvas(tk, width=1366, height=768, background='#fff')
canvas.pack()
colors=[[(255, 255, 255) for i in range(223)] for i in range(321)]
def color(a,b,c):
if a<10:
va='0'+str(a)
else:
va=hex(a%256).replace('0x','')
if b<10:
vb='0'+str(b)
else:
vb=hex(b%256).replace('0x','')
if c<10:
vc='0'+str(c)
else:
vc=hex(c%256).replace('0x','')
return '#%s'%(va+vb+vc)
def colr(lis):
a=lis[0]
b=lis[1]
c=lis[2]
if a%256<10:
va='0'+str(a%256)
else:
va=hex(a%256).replace('0x','')
if b%256<10:
vb='0'+str(b%256)
else:
vb=hex(b%256).replace('0x','')
if c%256<10:
vc='0'+str(c%256)
else:
vc=hex(c%256).replace('0x','')
return '#%s'%(va+vb+vc)
def fill_rect(a,b,c,d,e):
a=a+683
b=-b+384
if type(e)==str:
canvas.create_rectangle(a+2,b+2,c+a+2,d+b+2,fill=e,outline='')
else:
canvas.create_rectangle(a+2,b+2,c+a+2,d+b+2,fill=colr(e),outline='')
#modifie la valeur de la couleur au pixel x,y
for x in range(c):
for y in range(d):
if (a+x)>=0 and (a+x)<=320 and (b+y)>=0 and (b+y)<=222:
colors[a+x][b+y]=e
def set_pixel(a,b,e):
fill_rect(a,b,1,1,e)
def get_pixel(x,y):
if x>=0 and x<=320 and y>=0 and y<=222:
return colors[x][y]
else:
return (0,0,0)
#This is where my code starts
def draw_line(xa,ya,xb,yb):
canvas.create_line(round(xa)+683,-round(ya)+384,round(xb)+683,-round(yb)+384, fill="black", width=1)
#The increment are just so the landmark is at the center of the screen
focal_length=100
def dproj(xa,ya,za,xb,yb,zb):
draw_line(focal_length*xa/za,focal_length*ya/za,focal_length*xb/zb,focal_length*yb/zb)
#Vertex table of the cube
a=[-1,-1,1]
b=[1,-1,1]
c=[1,1,1]
d=[-1,1,1]
e=[-1,-1,3]
f=[1,-1,3]
g=[1,1,3]
h=[-1,1,3]
for i in range(300):
canvas.delete("all")
focal_length=i
#Edges table
dproj(a[0],a[1],a[2],b[0],b[1],b[2])
dproj(a[0],a[1],a[2],d[0],d[1],d[2])
dproj(a[0],a[1],a[2],e[0],e[1],e[2])
dproj(c[0],c[1],c[2],b[0],b[1],b[2])
dproj(c[0],c[1],c[2],d[0],d[1],d[2])
dproj(c[0],c[1],c[2],g[0],g[1],g[2])
dproj(f[0],f[1],f[2],b[0],b[1],b[2])
dproj(f[0],f[1],f[2],e[0],e[1],e[2])
dproj(f[0],f[1],f[2],g[0],g[1],g[2])
dproj(h[0],h[1],h[2],d[0],d[1],d[2])
dproj(h[0],h[1],h[2],e[0],e[1],e[2])
dproj(h[0],h[1],h[2],g[0],g[1],g[2])
sleep(0.01)
i wanted to make some kind of 3D render of a cube with the focal lenght slowly changing to make kind of a zoom in effect.
I also tried sys.stdout.flush()
but same issue although maybe this only applies for prints in terminal.