from cstream import stdwar

from svgen import Point, Vector, SVG, Figure, Camera, Domain, Map, Surface, Animation

from math import radians, sin, cos, pi, hypot, sqrt

import sys
from tqdm import tqdm

from svgen.svglib.math import Transform

COLOR = "#3703b3"

if len(sys.argv) > 1 and sys.argv[1] == "-o":
    proj = Camera.ORTHOGRAPHIC
else:
    proj = Camera.PERSPECTIVE

def f(t = 0.0):
    def g(x, y):
        a = 25.0
        x = x / a
        y = y / a
        return -(a * sin(x + t) - a * cos(y + t))
    return g

w = 500
h = 500

n = 30

ani = Animation(delay=1000)

D = Domain((-250, 250), (250, -250))

TX = Transform.rotation(radians( 25), Vector.X)
TY = Transform.rotation(radians(-25), Vector.Y)
TZ = Transform.rotation(radians(-45), Vector.Z)

TS = Transform.scale(0.5)

kw = {"stroke": COLOR, "stroke-width": 2.5, "fill": "none"}

for i in tqdm(range(n)):
    M = Map(f((i / n) * 2.0 * pi), D)
    S = Surface(M)
    S.transform(TY)
    S.transform(TX)
    S.transform(TS)

    svg = SVG(w, h, proj=proj)
    svg.surf(S, m = 20, n = 20, **kw)

    ani.add_frame(svg)
else:
    ani.main(sys.argv)
from cstream import stdwar

from svgen import Point, Vector, SVG, Figure, Camera, Domain, Map, Surface, Animation

from math import radians, sin, cos, pi, hypot, sqrt

import sys
from tqdm import tqdm

from svgen.svglib.math import Transform

COLOR = "#3703b3"

if len(sys.argv) > 1 and sys.argv[1] == "-o":
    proj = Camera.ORTHOGRAPHIC
else:
    proj = Camera.PERSPECTIVE

def f(t = 0.0):
    def g(x, y):
        a = 25.0
        x = x / a
        y = y / a
        return -(a * sin(x + t) - a * cos(y + t))
    return g

w = 500
h = 500

n = 30

ani = Animation(delay=1000)

D = Domain((-250, 250), (250, -250))

TX = Transform.rotation(radians( 25), Vector.X)
TY = Transform.rotation(radians(-25), Vector.Y)
TZ = Transform.rotation(radians(-45), Vector.Z)

TS = Transform.scale(0.5)

kw = {"stroke": COLOR, "stroke-width": 2.5, "fill": "none"}

for i in tqdm(range(n)):
    M = Map(f((i / n) * 2.0 * pi), D)
    S = Surface(M)
    S.transform(TY)
    S.transform(TX)
    S.transform(TS)

    svg = SVG(w, h, proj=proj)
    svg.surf(S, m = 20, n = 20, **kw)

    ani.add_frame(svg)
else:
    ani.main(sys.argv)