from random import * from kandinsky import set_pixel from math import sqrt r3 = sqrt(3) / 2 def randomPoint(): r1 = random() r2 = random() if (r1 + r2 > 1): r1 = 1 - r1 r2 = 1 - r2 x = r2 + .5 * r1 y = r3 * r1 return (x, y) def dansDisque(xy): (x,y) = xy if x*x + y*y < .25: return True if (x-1)**2 + y*y < .25: return True if (x-.5)**2 + (y-r3)**2 < .25: return True return False '''for _ in range(10000): (x,y) = randomPoint() set_pixel(int(220 * x), int(220 * y), (0, 0, 0)) ''' nb_simul = 100000 total = 0 for _ in range(nb_simul): if dansDisque(randomPoint()): total += 1 print(total / nb_simul)