from turtle import * from math import pi,sin,cos from random import random,randint from time import sleep from kandinsky import fill_rect # ecran blanc et toile grise fill_rect(0,0,320,222,(255,)*3) color((200,)*3) pensize(2) # on dessine la toile for r in range(2, 100, 10): penup() goto(r, 0) pendown() for i in range(1, 9): # Trace legerement aleatoire for j in range(10): x = r * cos(random()/10 + pi * 2 * (i - 1 + sin(j * pi / 20)) / 8) y = r * sin(pi * 2 * (i - 1 + sin(j * j * pi / 200)) / 8) goto(x, y) # les rayons setheading(i * 360 / 8) forward(10) backward(10) goto(0,0) penup() speed(4) # tortue color((0,0,0)) while True: (x,y) = position() # elle ne doit pas sortir de la toile if x * x + y * y > 90*90: setheading(heading()+180) else : setheading(randint(0,360)) # elle bouge forward(5) sleep(.5) # un insecte arrive sur la toile if random()<.25: x = int(70 * (2 * random() - 1)) y = int(70 * (2 * random() - 1)) fill_rect(160 + x, 110 + y, 3, 3, (255,0,0)) # la tortue va le manger goto(x, - y)