Petit programme qui dessine un point qui se déplace aléatoirement (il est pas terrible, mais j’avais bien aimé le faire). Il s’affiche rouge si il monte, noir si il descend, vert si il va vers la gauche et bleu vers la droite.
from ion import * from kandinsky import * from turtle import * from time import * from random import * def bob(min, max, min2, max2): color='pink' x=161 y=111 reset() hideturtle() set_pixel(x,y,'black') maxx=maxy=1 minx=miny=-1 while True: newx=randint(minx,maxx) newy=randint(miny,maxy) if newx == 0 or newy == 0: if newx != 0 and newy in [-1,0,1]: if newx < 0: maxx=max2 minx=min maxy=1 miny=-1 color='green' else: maxx=max minx=min2 maxy=1 miny=-1 color='blue' elif newx in [-1,0,1] and newy != 0: if newy < 0: maxy=max2 miny=min maxx=1 minx=-1 color='red' else: maxy=max miny=min2 maxx=1 minx=-1 color='black' else: pass x+=newx y+=newy sleep(0.001) print("\nnewx: ",newx," newy: ",newy,"\n minx: ",minx," maxx: ", maxx,"\n miny: ", miny," maxy: ",maxy) #set_pixel(x,y,color) fill_rect(x,y,2,2,color) bob(-3, 3, -1, 1)