import bpy
from vraag import *
from vraag.construct.turtle import *
from vraag.utils import *
import numpy as np

V("Cube").remove()
root = V.construct()


def fractal(start=None, level=1):
    f = 1/3
    α = 60
    if start is None:
        a = TurtlePoint()
    else:
        a = start.copy()
    yield a
    if level > 0:
        yield from fractal(a.scale(f), level-1)
    b = a.translate(f*right)
    yield b
    c = b.rotate(down, α)
    if level > 0:
        yield from fractal(c.scale(f), level-1)
    c = c.translate(f*right)
    yield c
    d = c.rotate(up, α*2)
    
    if level > 0:
        yield from fractal(d.scale(f), level-1)
    d = d.translate(f*right)
    yield d
    e = d.rotate(down, α)
    if level > 0:
        yield from fractal(e.scale(f), level-1)

def to_2d(iterator):
    for t in iterator:
        x,y,z,_ = t.location
        yield x,y

side = TurtlePoint().rotate(down,60)
points =[]
for i in range(3):
    points += list(to_2d(fractal(side,level=5)))
    side = side.translate(right).rotate(up, 60*2)

points = np.array(points)
points[:,0]-= 0.5
points[:,1]-= points[:,1].max() / 3
koch_flake = root.rotate(right,90).scale(5).prism(points, height=0.1)

V(koch_flake).export_stl("koch_flake.stl")

eada4bb7e04e115360e193037f0b64a2f3ae6dd3
<mask token>


def fractal(start=None, level=1):
    f = 1 / 3
    α = 60
    if start is None:
        a = TurtlePoint()
    else:
        a = start.copy()
    yield a
    if level > 0:
        yield from fractal(a.scale(f), level - 1)
    b = a.translate(f * right)
    yield b
    c = b.rotate(down, α)
    if level > 0:
        yield from fractal(c.scale(f), level - 1)
    c = c.translate(f * right)
    yield c
    d = c.rotate(up, α * 2)
    if level > 0:
        yield from fractal(d.scale(f), level - 1)
    d = d.translate(f * right)
    yield d
    e = d.rotate(down, α)
    if level > 0:
        yield from fractal(e.scale(f), level - 1)


def to_2d(iterator):
    for t in iterator:
        x, y, z, _ = t.location
        yield x, y


<mask token>

<mask token>
V('Cube').remove()
<mask token>


def fractal(start=None, level=1):
    f = 1 / 3
    α = 60
    if start is None:
        a = TurtlePoint()
    else:
        a = start.copy()
    yield a
    if level > 0:
        yield from fractal(a.scale(f), level - 1)
    b = a.translate(f * right)
    yield b
    c = b.rotate(down, α)
    if level > 0:
        yield from fractal(c.scale(f), level - 1)
    c = c.translate(f * right)
    yield c
    d = c.rotate(up, α * 2)
    if level > 0:
        yield from fractal(d.scale(f), level - 1)
    d = d.translate(f * right)
    yield d
    e = d.rotate(down, α)
    if level > 0:
        yield from fractal(e.scale(f), level - 1)


def to_2d(iterator):
    for t in iterator:
        x, y, z, _ = t.location
        yield x, y


<mask token>
for i in range(3):
    points += list(to_2d(fractal(side, level=5)))
    side = side.translate(right).rotate(up, 60 * 2)
<mask token>
points[:, 0] -= 0.5
points[:, 1] -= points[:, 1].max() / 3
<mask token>
V(koch_flake).export_stl('koch_flake.stl')

<mask token>
V('Cube').remove()
root = V.construct()


def fractal(start=None, level=1):
    f = 1 / 3
    α = 60
    if start is None:
        a = TurtlePoint()
    else:
        a = start.copy()
    yield a
    if level > 0:
        yield from fractal(a.scale(f), level - 1)
    b = a.translate(f * right)
    yield b
    c = b.rotate(down, α)
    if level > 0:
        yield from fractal(c.scale(f), level - 1)
    c = c.translate(f * right)
    yield c
    d = c.rotate(up, α * 2)
    if level > 0:
        yield from fractal(d.scale(f), level - 1)
    d = d.translate(f * right)
    yield d
    e = d.rotate(down, α)
    if level > 0:
        yield from fractal(e.scale(f), level - 1)


def to_2d(iterator):
    for t in iterator:
        x, y, z, _ = t.location
        yield x, y


side = TurtlePoint().rotate(down, 60)
points = []
for i in range(3):
    points += list(to_2d(fractal(side, level=5)))
    side = side.translate(right).rotate(up, 60 * 2)
points = np.array(points)
points[:, 0] -= 0.5
points[:, 1] -= points[:, 1].max() / 3
koch_flake = root.rotate(right, 90).scale(5).prism(points, height=0.1)
V(koch_flake).export_stl('koch_flake.stl')

import bpy
from vraag import *
from vraag.construct.turtle import *
from vraag.utils import *
import numpy as np
V('Cube').remove()
root = V.construct()


def fractal(start=None, level=1):
    f = 1 / 3
    α = 60
    if start is None:
        a = TurtlePoint()
    else:
        a = start.copy()
    yield a
    if level > 0:
        yield from fractal(a.scale(f), level - 1)
    b = a.translate(f * right)
    yield b
    c = b.rotate(down, α)
    if level > 0:
        yield from fractal(c.scale(f), level - 1)
    c = c.translate(f * right)
    yield c
    d = c.rotate(up, α * 2)
    if level > 0:
        yield from fractal(d.scale(f), level - 1)
    d = d.translate(f * right)
    yield d
    e = d.rotate(down, α)
    if level > 0:
        yield from fractal(e.scale(f), level - 1)


def to_2d(iterator):
    for t in iterator:
        x, y, z, _ = t.location
        yield x, y


side = TurtlePoint().rotate(down, 60)
points = []
for i in range(3):
    points += list(to_2d(fractal(side, level=5)))
    side = side.translate(right).rotate(up, 60 * 2)
points = np.array(points)
points[:, 0] -= 0.5
points[:, 1] -= points[:, 1].max() / 3
koch_flake = root.rotate(right, 90).scale(5).prism(points, height=0.1)
V(koch_flake).export_stl('koch_flake.stl')

import bpy
from vraag import *
from vraag.construct.turtle import *
from vraag.utils import *
import numpy as np

V("Cube").remove()
root = V.construct()


def fractal(start=None, level=1):
    f = 1/3
    α = 60
    if start is None:
        a = TurtlePoint()
    else:
        a = start.copy()
    yield a
    if level > 0:
        yield from fractal(a.scale(f), level-1)
    b = a.translate(f*right)
    yield b
    c = b.rotate(down, α)
    if level > 0:
        yield from fractal(c.scale(f), level-1)
    c = c.translate(f*right)
    yield c
    d = c.rotate(up, α*2)
    
    if level > 0:
        yield from fractal(d.scale(f), level-1)
    d = d.translate(f*right)
    yield d
    e = d.rotate(down, α)
    if level > 0:
        yield from fractal(e.scale(f), level-1)

def to_2d(iterator):
    for t in iterator:
        x,y,z,_ = t.location
        yield x,y

side = TurtlePoint().rotate(down,60)
points =[]
for i in range(3):
    points += list(to_2d(fractal(side,level=5)))
    side = side.translate(right).rotate(up, 60*2)

points = np.array(points)
points[:,0]-= 0.5
points[:,1]-= points[:,1].max() / 3
koch_flake = root.rotate(right,90).scale(5).prism(points, height=0.1)

V(koch_flake).export_stl("koch_flake.stl")
