numpy - Animation of circles on python -
i trying circles appear 1 one in random locations on plot, interval of 1 second. if circles overlap, overlapping circles need added clusters , change colours depending on cluster belong to, or if touch left or right side of 'box'. new python , therefore struggling project. clusters need continue growing until there 5 circles in cluster. therefore, struggling create function continue create circles until condition met.
here code have written far
import numpy.random nr import scipy sp import pylab plt import itertools matplotlib.animation import funcanimation radius = 0.05 number_of_disks = 10 coordinates = nr.uniform(size=(number_of_disks, 2)) print coordinates plt.close('all') fig = plt.figure() ax = plt.gca() #plot of disks coordinate in coordinates: ax.set_aspect('equal', adjustable='box') circle = plt.circle((coordinate[0], coordinate[1]), radius, alpha = 0.4, color='b') ax.add_artist(circle) plt.show() disks = [] overlapping_disks = [] disks_at_edge = [] clusters = {} def touch_sides(disk, radius): row in range(0, number_of_disks): x = coordinates[row, 0] y = coordinates[row, 1] left = true if x<= radius else false right = true if x>=1-radius else false disks.append({'x': x, 'y': y, 'left': left, 'right': right, 'cluster': 0}) def disk_overlap(disk, disk_after, radius): disk, disk_after in itertools.combinations(coordinates,2): if sp.sqrt(sp.power(disk[0]-disk_after[0],2)+sp.power(disk[1]-disk_after[1],2)) < 2*radius: overlapping_disks.append((disk, disk_after))
Comments
Post a Comment