Пример #1
0
def system():
    """initialize and iterate the system as appropriate"""
    l_sys = LSystem(axiom=[
        LSymbol("!", {"w": 0.2}),
        LSymbol("F", {"l": 0.6}),
        LSymbol("Q", {
            "w": 0.2,
            "bw": 0.05,
            "l": 0.5,
            "bl": 0.4
        })
    ],
                    rules={
                        "Q": q_prod,
                        "A": a_prod
                    },
                    tropism=Vector([0, 0, 0]),
                    thickness=0.5,
                    bendiness=0.5,
                    leaf_shape=2,
                    leaf_scale=0.15,
                    leaf_scale_x=0.3,
                    leaf_bend=0)
    l_sys.iterate_n(15)
    return l_sys
Пример #2
0
def q_prod(sym):
    """Production rule for Q"""
    ret = []
    prev_ang = 0
    for _ in range(int(random() * 2 + 3)):
        ang = random() * 10 + 30
        ret.extend([
            LSymbol("/", {"a": prev_ang + 75 + random() * 10}),
            LSymbol("&", {"a": ang}),
            LSymbol("!", {"w": sym.parameters["w"] * 0.2}),
            LSymbol("["),
            LSymbol(
                "A", {
                    "w": sym.parameters["w"] * 0.3,
                    "l": 1.5 * sqrt(sym.parameters["w"]) *
                    (random() * 0.2 + 0.9)
                }),
            LSymbol("]"),
            LSymbol("!", {"w": sym.parameters["w"]}),
            LSymbol("^", {"a": ang}),
            LSymbol("F", {"l": sym.parameters["l"]})
        ])
    ret.append(
        LSymbol(
            "Q", {
                "w": max(0, sym.parameters["w"] - __base_width__ / 14),
                "l": sym.parameters["l"]
            }))
    return ret
Пример #3
0
def system():
    """initialize and iterate the system as appropriate"""
    axiom = []
    con = int(__base_length__ / 0.1)
    s = random() * 0.2 + 0.9
    for ind in range(con):
        axiom.append(LSymbol("!", {"w": s * (__base_width__ + ((con - ind) / con) ** 6 * 0.2)}))
        axiom.append(LSymbol("F", {"l": s * 0.1}))
    axiom.append(LSymbol("Q", {"w": s * __base_width__, "l": s * 0.1}))
    l_sys = LSystem(axiom=axiom,
                    rules={"Q": q_prod, "A": a_prod},
                    tropism=Vector([0, 0, 0.2]),
                    thickness=0.5,
                    bendiness=0,
                    leaf_shape=3,
                    leaf_scale=0.17,
                    leaf_bend=0.2)
    l_sys.iterate_n(12)
    return l_sys
Пример #4
0
def system():
    """initialize and iterate the system as appropriate"""
    l_sys = LSystem(axiom=[
        LSymbol("!", {"w": 0.2}),
        LSymbol("/", {"a": random() * 360}),
        LSymbol("Q", {"t": 0})
    ],
                    rules={
                        "Q": q_prod,
                        "A": a_prod
                    },
                    tropism=Vector([0, 0, -1]),
                    thickness=0.2,
                    bendiness=0,
                    leaf_shape=10,
                    leaf_scale=1,
                    leaf_scale_x=0.1,
                    leaf_bend=0)
    l_sys.iterate_n(100)
    return l_sys
Пример #5
0
def system():
    """initialize and iterate the system as appropriate"""
    l_sys = LSystem(axiom=[
        LSymbol("!", {"w": __base_width__}),
        LSymbol("/", {"a": 45}),
        LSymbol("Q", {
            "w": __base_width__,
            "l": 0.5
        })
    ],
                    rules={
                        "Q": q_prod,
                        "A": a_prod
                    },
                    tropism=Vector([0, 0, 0]),
                    thickness=0.5,
                    bendiness=0,
                    leaf_shape=0,
                    leaf_scale=0.3,
                    leaf_bend=0.7)
    l_sys.iterate_n(15)
    return l_sys
Пример #6
0
def a_prod(_):
    """Production rule for A"""
    res = []
    num = int(random() * 5 + 30)
    for ind in range(num):
        d_ang = (num - 1 - ind) * (80 / num)
        res.extend([
            LSymbol("!", {"w": 0.1 - ind * 0.1 / 15}),
            LSymbol("F", {"l": 0.1}),
            LSymbol(
                "L", {
                    "r_ang": 50 * (random() * 0.4 + 0.8),
                    "d_ang": d_ang * (random() * 0.4 + 0.8)
                }),
            LSymbol(
                "L", {
                    "r_ang": -50 * (random() * 0.4 + 0.8),
                    "d_ang": d_ang * (random() * 0.4 + 0.8)
                }),
            LSymbol("&", {"a": 1})
        ])
    return res
Пример #7
0
def system():
    """initialize and iterate the system as appropriate"""
    l_sys = LSystem(axiom=[
        LSymbol("!", {"w": 0.7}),
        LSymbol("F", {"l": 0.5}),
        LSymbol("/", {"a": 45}),
        LSymbol("A", {
            "w": 0.4,
            "l": 2
        })
    ],
                    rules={
                        "A": a_prod,
                        "F": f_prod
                    },
                    tropism=Vector([0, 0, -1]),
                    thickness=0.5,
                    bendiness=2,
                    leaf_shape=5,
                    leaf_scale=0.2,
                    leaf_bend=0.2)
    l_sys.iterate_n(9)
    return l_sys
Пример #8
0
def a_prod(sym):
    """Production rule for A"""
    ret = []
    n = int(random() * 5 + 22.5)
    w_d = sym.parameters["w"] / (n - 1)
    prev_rot = 0
    for ind in range(n):
        wid = sym.parameters["w"] - ind * w_d
        ang = random() * 10 + 25
        ret.extend([
            LSymbol("!", {"w": wid}),
            LSymbol("F", {"l": sym.parameters["l"] / 3}),
            LSymbol("/", {"a": prev_rot + 140}),
            LSymbol("&", {"a": ang}),
            LSymbol("!", {"w": wid * 0.3}),
            LSymbol("["),
            LSymbol(
                "F", {
                    "l": 0.75 * sqrt(n - ind) * sym.parameters["l"] / 3,
                    "leaves": 25,
                    "leaf_d_ang": 40,
                    "leaf_r_ang": 140
                }),
            LSymbol("^", {"a": 20}),
            LSymbol(
                "F", {
                    "l": 0.75 * sqrt(n - ind) * sym.parameters["l"] / 3,
                    "leaves": 25,
                    "leaf_d_ang": 40,
                    "leaf_r_ang": 140
                }),
            LSymbol("%"),
            LSymbol("]"),
            LSymbol("!", {"w": wid}),
            LSymbol("^", {"a": ang}),
            LSymbol("\\", {"a": prev_rot + 140}),
            LSymbol("^", {"a": 1.2})
        ])
        prev_rot += 140
    return ret
Пример #9
0
def q_prod(sym):
    """Production rule for Q"""
    prop_off = sym.parameters["t"] / __t_max__
    if prop_off < 1:
        res = [
            LSymbol("!", {"w": 0.85 + 0.15 * sin(sym.parameters["t"])}),
            LSymbol("^", {"a": random() - 0.65})
        ]
        if prop_off > __p_max__:
            d_ang = 1 / (1 - __p_max__) * (1 - prop_off) * 110 + 15
            res.extend([LSymbol("!", {"w": 0.1})])
            for ind in range(int(random() * 2 + 5)):
                r_ang = sym.parameters["t"] * 10 + ind * (random() * 50 + 40)
                e_d_ang = d_ang * (random() * 0.4 + 0.8)
                res.extend([
                    LSymbol("/", {"a": r_ang}),
                    LSymbol("&", {"a": e_d_ang}),
                    LSymbol("["),
                    LSymbol("A"),
                    LSymbol("]"),
                    LSymbol("^", {"a": e_d_ang}),
                    LSymbol("\\", {"a": r_ang})
                ], )
            res.append(LSymbol("F", {"l": 0.05}))
        else:
            res.append(LSymbol("F", {"l": 0.15}))
        res.append(LSymbol("Q", {"t": sym.parameters["t"] + __d_t__}))
    else:
        res = [LSymbol("!", {"w": 0}), LSymbol("F", {"l": 0.15})]
    return res
Пример #10
0
def a_prod(sym):
    """Production rule for A"""
    rand = random() / (0.24 * sym.parameters["l"]**2.5)
    if sym.parameters["l"] == 2:
        rand += 0.5
    if rand < 0.4:
        return [
            LSymbol("["),
            LSymbol("F", {"l": sym.parameters["l"] / 2}),
            LSymbol("!", {"w": sym.parameters["w"]}),
            LSymbol("&", {"a": branch_ang()}),
            LSymbol(
                "F", {
                    "l": sym.parameters["l"] / 2,
                    "leaves": __n_leaves__,
                    "leaf_d_ang": 40,
                    "leaf_r_ang": 140
                }),
            LSymbol(
                "A", {
                    "w": sym.parameters["w"] - __width_d__,
                    "l": sym.parameters["l"] - __len_d__
                }),
            LSymbol("]")
        ]
    elif rand < 0.8:
        return [
            LSymbol("["),
            LSymbol("F", {"l": sym.parameters["l"] / 2}),
            LSymbol("!", {"w": sym.parameters["w"]}),
            LSymbol("&", {"a": branch_ang()}),
            LSymbol("/", {"a": 90}),
            LSymbol(
                "F", {
                    "l": sym.parameters["l"] / 2,
                    "leaves": __n_leaves__,
                    "leaf_d_ang": 40,
                    "leaf_r_ang": 140
                }),
            LSymbol(
                "A", {
                    "w": sym.parameters["w"] - __width_d__,
                    "l": sym.parameters["l"] - __len_d__
                }),
            LSymbol("]"),
            LSymbol("["),
            LSymbol("!", {"w": sym.parameters["w"]}),
            LSymbol("^", {"a": branch_ang()}),
            LSymbol("\\", {"a": 90}),
            LSymbol(
                "F", {
                    "l": sym.parameters["l"] / 2,
                    "leaves": __n_leaves__,
                    "leaf_d_ang": 40,
                    "leaf_r_ang": 140
                }),
            LSymbol(
                "A", {
                    "w": sym.parameters["w"] - __width_d__,
                    "l": sym.parameters["l"] - __len_d__
                }),
            LSymbol("]")
        ]
    else:
        return [
            LSymbol("["),
            LSymbol("F", {"l": sym.parameters["l"] / 2}),
            LSymbol("!", {"w": sym.parameters["w"]}),
            LSymbol("&", {"a": branch_ang()}),
            LSymbol(
                "F", {
                    "l": sym.parameters["l"] / 2,
                    "leaves": __n_leaves__,
                    "leaf_d_ang": 40,
                    "leaf_r_ang": 140
                }),
            LSymbol(
                "A", {
                    "w": sym.parameters["w"] - __width_d__,
                    "l": sym.parameters["l"] - __len_d__
                }),
            LSymbol("]"),
            LSymbol("/", {"a": d1_ang()}),
            LSymbol("["),
            LSymbol("!", {"w": sym.parameters["w"]}),
            LSymbol("&", {"a": branch_ang()}),
            LSymbol(
                "F", {
                    "l": sym.parameters["l"] / 2,
                    "leaves": __n_leaves__,
                    "leaf_d_ang": 40,
                    "leaf_r_ang": 140
                }),
            LSymbol(
                "A", {
                    "w": sym.parameters["w"] - __width_d__,
                    "l": sym.parameters["l"] - __len_d__
                }),
            LSymbol("]"),
            LSymbol("/", {"a": d2_ang()}),
            LSymbol("["),
            LSymbol("!", {"w": sym.parameters["w"]}),
            LSymbol("&", {"a": branch_ang()}),
            LSymbol(
                "F", {
                    "l": sym.parameters["l"] / 2,
                    "leaves": __n_leaves__,
                    "leaf_d_ang": 40,
                    "leaf_r_ang": 140
                }),
            LSymbol(
                "A", {
                    "w": sym.parameters["w"] - __width_d__,
                    "l": sym.parameters["l"] - __len_d__
                }),
            LSymbol("]")
        ]
Пример #11
0
def f_prod(sym):
    """Production rule for F"""
    return [LSymbol("F", {"l": sym.parameters["l"], "leaves": 0})]
Пример #12
0
def a_prod(sym):
    """Production rule for A"""
    ret = []
    w_d = sym.parameters["w"] / 14
    prev_rot = 0
    n = int(random() * 3 + 15.5)
    for ind in range(n):
        wid = sym.parameters["w"] - ind * w_d
        l_count = int((sqrt(n - ind) + 2) * 4 * sym.parameters["l"])
        ret.extend([LSymbol("!", {"w": wid}),
                    LSymbol("F", {"l": sym.parameters["l"] / 3}),
                    LSymbol("/", {"a": prev_rot + 140}),
                    LSymbol("&", {"a": 60}),
                    LSymbol("!", {"w": wid * 0.4}),
                    LSymbol("["),
                    LSymbol("F", {"l": sqrt(n - ind) * sym.parameters["l"] / 3,
                                  "leaves": l_count,
                                  "leaf_d_ang": 40,
                                  "leaf_r_ang": 140}),
                    LSymbol("^", {"a": random() * 30 + 30}),
                    LSymbol("F", {"l": sqrt(n - ind) * sym.parameters["l"] / 4,
                                  "leaves": l_count,
                                  "leaf_d_ang": 40,
                                  "leaf_r_ang": 140}),
                    LSymbol("%"),
                    LSymbol("]"),
                    LSymbol("!", {"w": wid}),
                    LSymbol("^", {"a": 60}),
                    LSymbol("\\", {"a": prev_rot + 140}),
                    LSymbol("+", {"a": -5 + random() * 10}),
                    LSymbol("^", {"a": -7.5 + random() * 15})])
        prev_rot += 140
    ret.append(LSymbol("F", {"l": sym.parameters["l"] / 2}))
    return ret
Пример #13
0
def q_prod(sym):
    """Production rule for Q"""
    ret = []
    prev_ang = 0
    n = int(random() * 2 + 7)
    for ind in range(8):
        offset = 1 - (__base_width__ - sym.parameters["w"]) / __base_width__
        offset += ind / 8 / 12
        dang = 30 + 85 * offset
        if offset <= 0.7:
            b_len = 0.4 + 0.6 * offset / 0.7
        else:
            b_len = 0.4 + 0.6 * (1.0 - offset) / 0.3
        ret.extend([LSymbol("/", {"a": prev_ang + 75 + random() * 10}),
                    LSymbol("&", {"a": dang}),
                    LSymbol("!", {"w": sym.parameters["w"] * 0.08 * b_len}),
                    LSymbol("["),
                    LSymbol("F", {"l": sym.parameters["w"] / 2}),
                    LSymbol("A", {"w": 0.08 * b_len,
                                  "l": 0.6 * b_len}),
                    LSymbol("]"),
                    LSymbol("!", {"w": sym.parameters["w"]}),
                    LSymbol("^", {"a": dang}),
                    LSymbol("F", {"l": sym.parameters["l"]})])
    ret.append(LSymbol("Q", {"w": max(0, sym.parameters["w"] - __base_width__ / 11),
                             "l": sym.parameters["l"]}))
    return ret
Пример #14
0
def a_prod(sym):
    """Production rule for A"""
    if random() < sym.parameters["l"]:
        ang = random() * __sec_branch_ang_v__ + __sec_branch_ang__
        return [
            LSymbol("!", {"w": sym.parameters["w"]}),
            LSymbol("^", {"a": random() * 15 - 5}),
            LSymbol(
                "F", {
                    "l": sym.parameters["l"],
                    "leaves": int(sym.parameters["l"] * __n_leaves__),
                    "leaf_d_ang": 40,
                    "leaf_r_ang": 140
                }),
            LSymbol("-", {"a": ang / 2}),
            LSymbol("["),
            LSymbol(
                "A", {
                    "l": sym.parameters["l"] * __length_r__,
                    "w": sym.parameters["w"] * __width_r__
                }),
            LSymbol("]"),
            LSymbol("+", {"a": ang}),
            LSymbol("["),
            LSymbol(
                "A", {
                    "l": sym.parameters["l"] * __length_r__,
                    "w": sym.parameters["w"] * __width_r__
                }),
            LSymbol("]"),
            LSymbol("-", {"a": ang / 2}),
            LSymbol(
                "A", {
                    "l": sym.parameters["l"] * __length_r__,
                    "w": sym.parameters["w"] * __width_r__
                })
        ]
    else:
        return [
            LSymbol("!", {"w": sym.parameters["w"]}),
            LSymbol("^", {"a": random() * 15 - 5}),
            LSymbol(
                "F", {
                    "l": sym.parameters["l"],
                    "leaves": int(sym.parameters["l"] * __n_leaves__),
                    "leaf_d_ang": 40,
                    "leaf_r_ang": 140
                }),
            LSymbol(
                "A", {
                    "l": sym.parameters["l"] * __length_r__,
                    "w": sym.parameters["w"] * __width_r__
                })
        ]
Пример #15
0
def q_prod(sym):
    """Production rule for Q"""
    ret = [
        LSymbol("!", {"w": sym.parameters["w"]}),
        LSymbol("&", {"a": 90}),
        LSymbol("+", {"a": random() * 360}),
        LSymbol("!", {"w": sym.parameters["bw"]})
    ]
    b_count = int(random() * 2) + 5
    for _ in range(b_count):
        rand = random() * 130 / b_count
        ret.extend([
            LSymbol("+", {"a": rand}),
            LSymbol("["),
            LSymbol(
                "^", {
                    "a":
                    5 / max(sym.parameters["bl"] * sym.parameters["bl"], 0.05)
                    - 30 * (random() * 0.2 + 0.9)
                }),
            LSymbol("A", {
                "l": sym.parameters["bl"],
                "w": sym.parameters["bw"]
            }),
            LSymbol("]"),
            LSymbol("+", {"a": (360 / b_count) - rand})
        ])
    ret.extend([
        LSymbol("!", {"w": sym.parameters["w"]}),
        LSymbol("$"),
        LSymbol(
            "F", {
                "l": sym.parameters["l"],
                "leaves": int(sym.parameters["l"] * __n_leaves__ / 3),
                "leaf_d_ang": 20,
                "leaf_r_ang": 140
            }),
        LSymbol(
            "Q", {
                "w": sym.parameters["w"] - 0.2 / 15,
                "l": sym.parameters["l"] * 0.95,
                "bw": sym.parameters["bw"] * __width_r__,
                "bl": sym.parameters["bl"] * __branch_length_r__
            }),
        LSymbol("%")
    ])
    return ret