コード例 #1
0
ファイル: web.py プロジェクト: jmaks/iing
def registration():
    if api.registration:
        username = request.forms.get("username")
        password = request.forms.get("password")
        if username and password:
            if points.check_username(username):
                return template("tpl/registration.tpl",
                                nodename=api.nodename,
                                dsc=api.nodedsc,
                                background=api.background,
                                alarm="Имя пользователя уже существует.")
            else:
                hsh, phash = points.make_point(username, password)
                points.save_point(phash, username, hsh)
                response.set_cookie("authstr",
                                    phash,
                                    path="/",
                                    max_age=3600000000)
                redirect("/")
        return template("tpl/registration.tpl",
                        nodename=api.nodename,
                        dsc=api.nodedsc,
                        background=api.background,
                        alarm=False)
    else:
        redirect("/")
コード例 #2
0
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))
コード例 #3
0
def __find_points(center, n, radius):
    """
    :param n: Number of circle
    :type n: int
    :param radius: The radius of the "crown" of circle and of the inner circle
    :type radius: tuple
    :return: A list wich contain the center of all the circle of the "crown"
    :rtype: list
    :UC: The radius of the inner circle must be the last of the tuple
    and len(radius) = 2
    """
    r, r1 = radius[1], radius[0]
    return [(pt.make_point(
        (r + r1) * math.cos(2 * i * math.pi / n) + pt.get_abs(center),
        (r + r1) * math.sin(2 * i * math.pi / n) + pt.get_ord(center)))
            for i in range(n)]
コード例 #4
0
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:]
コード例 #5
0
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)