def make_crown(circle, n): """ Create a list of circle. :param circle: The first circle wich contain all the other :type circle: circle :param n: The number of circles you want to put inside the first circle :type n: int :return: A list of circles, the last circle is the inner circle, all the other are the crown :rtype: list """ radius = __find_radius(circle, n) points = __find_points(cir.get_center(circle), n, radius) return [circle, cir.make_circle(cir.get_center(circle), radius[1]) ] + [cir.make_circle(i, radius[0]) for i in points]
def small_soddy(c1, c2, c3): """ Return only the small :param c1: :type c1: circle :param c2: :type c2: circle :param c3: :type c3: circle :return: The small circle :rtype: circle """ k1, k2, k3, k4 = descartes_curvature(c1, c2, c3) Tcenter = descartes_center( k1, k2, k3, k4, cir.get_center(c1), cir.get_center(c2), cir.get_center(c3)) ## The tuple wich contain all the center k4 = (math.fabs(k4[0]), math.fabs(k4[1])) sm_circle, gr_circle = [], [] margin = 1e-8 if 1 / k4[0] < 1 / k4[1]: rad_sm_cir = 1 / k4[0] else: rad_sm_cir = 1 / k4[1] for c in Tcenter: small_counter = 0 for circle in [c1, c2, c3]: radius_circle = cir.get_radius(circle) dist_center = pt.dist(c, cir.get_center(circle)) if math.fabs(dist_center - (radius_circle + rad_sm_cir)) < margin \ or math.fabs(dist_center - (radius_circle - rad_sm_cir)) < margin : small_counter += 1 if small_counter == 3: sm_circle.append(c) return cir.make_circle(sm_circle[0], rad_sm_cir)
def soddy(c1, c2, c3): """ :param c1: :type c1: circle :param c2: :type c2: circle :param c3: :type c3: circle :return: A list of length 2 wich contain the great circle in first and the small circle :rtype: list """ k1, k2, k3, k4 = descartes_curvature(c1, c2, c3) Tcenter = descartes_center( k1, k2, k3, k4, cir.get_center(c1), cir.get_center(c2), cir.get_center(c3)) ## The tuple wich contain all the center k4 = (math.fabs(k4[0]), math.fabs(k4[1])) sm_circle, gr_circle = [], [] margin = 1e-5 if 1 / k4[0] < 1 / k4[1]: rad_sm_cir, rad_gr_cir = 1 / k4[0], 1 / k4[ 1] ## radius small, great circle (28.71, 399.99) else: rad_gr_cir, rad_sm_cir = 1 / k4[0], 1 / k4[1] for c in Tcenter: small_counter, great_counter = 0, 0 for circle in [c1, c2, c3]: radius_circle = cir.get_radius(circle) dist_center = pt.dist(c, cir.get_center(circle)) if math.fabs(dist_center - (rad_sm_cir + radius_circle)) < margin: small_counter += 1 ## Si un cercle est tangent au cercle candidat-solution if math.fabs(dist_center - (rad_gr_cir - radius_circle)) < margin\ or math.fabs(dist_center - (rad_gr_cir + radius_circle)) < margin: great_counter += 1 if small_counter == 3: sm_circle.append( c ) ## Si les trois cercles sont tangent au cercle candidat-solution alors on ajoute sont centre a la liste if great_counter == 3: gr_circle.append(c) return [ cir.make_circle(sm_circle[0], rad_sm_cir), cir.make_circle(gr_circle[0], rad_gr_cir) ]
def crown(x, y, radius, nb_circle=5): """ Draw a circle of center `x, y` and radius `radius` and the crown inside. :param x: abs :type x: int :param y: ord :type y: int :param radius: - :type radius: int :Action: Draw a crown of circles inside the center of center `x, y` and radius `radius`. """ center = pt.make_point(x, y) circle = cir.make_circle(center, radius) draw_circle(circle) Ldraw_circle(make_crown(circle, nb_circle))
def final(x, y, radius, apo_depth=5, crown_depth=1, nb_circle=3): """ :param x: The center of first circle :type x: int :param y: The center of first circle :type y: int :param radius: The radius of the first circle :type radius: int :param depth: The depth of the fractal :type depth: int :param nb_circle: The number of circle in the crown :type nb_circle: int :Action: Draw the Apollonius Badern. :UC: radius, depth, nb_circle must be positive integers. """ global Gcrowndepth global Gnb_circle if Gnb_circle == 0: nb_circle = random.randint(3, 10) crown_depth = random.randint(0, 2) apo_depth = random.randint(0, 2) else: nb_circle = Gnb_circle if crown_depth != 0 and radius > 1: center = pt.make_point(x, y) circle = cir.make_circle(center, radius) Lcrowns = make_crown(circle, nb_circle) apollonius(Lcrowns, apo_depth) draw_circle(Lcrowns[0]) Lcrowns = Lcrowns[1:] while Lcrowns != [] and radius > 1: if Gcrown_depth == crown_depth and len(Lcrowns) % 100 == 0: print(len( Lcrowns)) ## Donne une idée de l'avancement du programme c = Lcrowns[0] x1 = pt.get_abs(cir.get_center(c)) y1 = pt.get_ord(cir.get_center(c)) draw_circle(c) final(x1, y1, cir.get_radius(c), apo_depth, crown_depth - 1, nb_circle) Lcrowns = Lcrowns[1:]
def fractal_crowns(x, y, radius, depth=5, nb_circle=0): """ Creates a circle of center `x, y` and radius `radius` and the crown inside. If you let the default value on `nb_circle` the number of circle in every depth of the fractal will be random. :param x: abs :type x: int :param y: ord :type y: int :param radius: - :type radius: int :param depth: (Default value : 5) The depth of the fractal :type depth: int :param nb_circle: (Default value : Random) The number of circles the crown contain :type nb_circle: int :Action: Draw the fractal `crown` of circles inside the center of center `x, y` and radius `radius`. :UC: radius, depth, nb_circle must be positive integers. """ assert type(depth) == type( nb_circle) == int, "depth and nb_circle must be integers" assert radius > 0 and depth > 0 and nb_circle > 0, "radius, depth and nb_circle must be positive" nb_circle2 = 0 if nb_circle == 0: nb_circle = random.randint(0, depth) + 3 nb_circle2 = 1 if depth != 0: center = pt.make_point(x, y) circle = cir.make_circle(center, radius) draw_circle(circle) Lcrowns = make_crown(circle, nb_circle) Ldraw_circle(Lcrowns) for c in Lcrowns: point = cir.get_center(c) x, y = pt.get_abs(point), pt.get_ord(point) if nb_circle2: nb_circle = 0 fractal_crowns(x, y, cir.get_radius(c), depth - 1, nb_circle)