def test_bezier(self):
        lot = objects.Animation()
        sl = lot.add_layer(objects.ShapeLayer())

        shape = sl.add_shape(objects.Path())
        sl.add_shape(objects.Fill(Color(0, .25, 1)))
        shape.shape.value.closed = True
        shape.shape.value.add_point(NVector(256, 0))
        shape.shape.value.add_point(NVector(256+128, 256), NVector(0, 0), NVector(64, 128))
        shape.shape.value.add_smooth_point(NVector(256, 512), NVector(128, 0))
        shape.shape.value.add_point(NVector(256-128, 256), NVector(-64, 128), NVector(0, 0))

        sif = builder.to_sif(lot)
        self.assertEqual(len(sif.layers), 1)
        self.assertIsInstance(sif.layers[0], api.GroupLayer)

        grp = sif.layers[0]
        self.assertEqual(len(grp.layers), 1)
        self.assertIsInstance(grp.layers[0], api.RegionLayer)
        self.assertTrue(grp.active)

        rgl = grp.layers[0]
        self.assertEqual(len(rgl.bline.points), 4)
        self.assert_nvector_equal(rgl.color.value, sif.make_color(0, .25, 1))
        self.assertTrue(rgl.active)
        self.assertTrue(rgl.bline.loop)

        for i in range(len(rgl.bline.points)):
            sp = rgl.bline.points[i]
            lp = shape.shape.value.vertices[i] - NVector(256, 256)
            self.assert_nvector_equal(
                sp.point.value, lp,
                msg="Point %s mismatch %s != %s" % (i, sp.point.value, lp)
            )

            lt1 = shape.shape.value.in_tangents[i] * -3
            self.assert_nvector_equal(
                sp.t1.value, lt1,
                msg="In Tangent %s mismatch %s != %s" % (i, sp.t1.value, lt1)
            )

            lt2 = shape.shape.value.out_tangents[i] * 3
            self.assert_nvector_equal(
                sp.t2.value, lt2,
                msg="Out Tangent %s mismatch %s != %s" % (i, sp.t2.value, lt2)
            )
Exemple #2
0
g.add_shape(objects.Fill(Color(0, 0, 0)))

g = layer.insert_shape(0, objects.Group())
eye2 = g.add_shape(objects.Ellipse())
eye2.size.value = Size(20, 20)
eye2.position.value = Point3D(256 + 50, 256 - 50, -100)
g.add_shape(objects.Fill(Color(0, 0, 0)))

g = layer.insert_shape(0, objects.Group())
nose = g.add_shape(objects.Ellipse())
nose.size.value = Size(64, 64)
nose.position.value = Point3D(256, 256 + 10, -150)
g.add_shape(objects.Fill(Color(1, 0, 0)))

g = layer.insert_shape(0, objects.Group())
mouth = g.add_shape(objects.Path())
bez = mouth.shape.value
bez.add_smooth_point(Point3D(256 - 80, 256 + 30, -80), Point3D(0, 0, 0))
bez.add_smooth_point(Point3D(256, 256 + 70, -100), -Point3D(50, 0, 0))
bez.add_smooth_point(Point3D(256 + 80, 256 + 30, -80), Point3D(0, 0, 0))
g.add_shape(objects.Stroke(Color(1, 0, 0), 2))

# Animate the circles using depth rotation
dr = anutils.DepthRotationDisplacer(Point3D(256, 256, 0), 0, 30, 10,
                                    Point3D(0, 4, 1), 0, 30)
dr.animate_point(eye1.position)
dr.animate_point(eye2.position)
dr.animate_point(nose.position)
dr.animate_bezier(mouth.shape)

dr = anutils.DepthRotationDisplacer(Point3D(256, 256, 0), 30, 90, 10,
Exemple #3
0
import sys
import os
sys.path.insert(
    0,
    os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
                 "lib"))
from lottie.utils import script
from lottie import objects
from lottie.utils import animation as anutils
from lottie import Point, Color

an = objects.Animation(180)

layer = objects.ShapeLayer()
an.add_layer(layer)

group = layer.add_shape(objects.Group())
bez = group.add_shape(objects.Path())
bez.shape.value.add_point(Point(256, 128), Point(0, 0), Point(64, 64))
bez.shape.value.add_smooth_point(Point(256, 256 + 120), Point(32, -32))
bez.shape.value.add_point(Point(256, 256), Point(-64, -64), Point(-64, 64))
bez.shape.value.add_point(Point(128, 256 + 120), Point(64, 64), Point(0, 0))
group.add_shape(objects.Stroke(Color(1, 0, 0), 10))

group = layer.add_shape(objects.Group())
sh = anutils.generate_path_segment(bez.shape.value, 0, 180, 60, 180, 60, True)
group.add_shape(sh)
group.add_shape(objects.Stroke(Color(0, 1, 0), 20))

script.script_main(an)
Exemple #4
0
layer = objects.ShapeLayer()
an.add_layer(layer)

heart = objects.Bezier()
heart.add_point(Point(50, 20), Point(50, -20), Point(-50, -20))
heart.add_smooth_point(Point(0, 50), Point(-5, -10))
heart.add_smooth_point(Point(50, 100), Point(-10, 0))
heart.add_smooth_point(Point(100, 50), Point(-5, 10))
heart.closed = True
antiheart = (objects.Bezier().add_smooth_point(Point(50, 0), Point(
    10, 0)).add_smooth_point(Point(0, 50), Point(0, -20)).add_point(
        Point(50, 80), Point(-50, 20),
        Point(50, 20)).add_smooth_point(Point(100, 50), Point(0, 20)).close())

g1 = layer.add_shape(objects.Group())
g1.transform.position.value = Point(100, 200)
shape = g1.add_shape(objects.Path())
shape.shape.value = heart

g2 = layer.add_shape(objects.Group())
g2.transform.position.value = Point(300, 200)
animated = g2.add_shape(objects.Path())
animated.shape.add_keyframe(0, heart)
animated.shape.add_keyframe(30, antiheart)
animated.shape.add_keyframe(59, heart)

fill = layer.add_shape(objects.Fill(color.from_uint8(255, 0, 0)))
stroke = layer.add_shape(objects.Stroke(Color(0, 0, 0), 5))

script.script_main(an)
Exemple #5
0
    p2 = Point(
        math.sin(2 * t * math.pi * 2) / 2 + 1,
        -math.cos(t * math.pi * 2) / 2 + 1) * 256
    b2.position.add_keyframe(i, p2)


def chain_bezier(chain):
    b = objects.Bezier()
    for seg in chain.joints:
        b.add_point(seg)
    return b


g = layer.add_shape(objects.Group())
s = g.add_shape(objects.Path())
g.add_shape(objects.Stroke(Color(1, 0, 0), 5))

chain = ik.Chain(Point(0, 0))
chain.add_joint(Point(50, 0))
chain.add_joint(Point(150, 0))
chain.add_joint(Point(350, 0))
chain.add_joint(Point(400, 0))
#chain.add_joint(Point(500, 0))

octmaster = ik.Chain(Point(512, 512), True)
octmaster.add_joint(Point(450, 450))
octmaster.add_joint(Point(400, 400))
octmaster.add_joint(Point(450, 450))
octmaster.add_joint(Point(512, 512))
Exemple #6
0
star = objects.Star()
star.inner_radius.value = 40
star.outer_radius.value = 100
star.position.value = Point(256, 256)
star.name = "big start"
group.add_shape(star)

star = objects.Star()
star.inner_radius.value = 20
star.outer_radius.value = 50
star.position.value = Point(256, 256)
star.name = "small start"
group.add_shape(star)

obj = objects.Path()
obj.shape.value.add_point(Point(10, 10))
obj.shape.value.add_point(Point(500, 10))
group.add_shape(obj)

trim = layer.add_shape(objects.Trim())
#trim.offset.value = 350
trim.offset.add_keyframe(0, 0)
trim.offset.add_keyframe(last_frame, 360)
trim.start.value = 0
trim.end.value = 50
#trim.multiple = objects.TrimMultipleShapes.Individually

stroke = group.add_shape(objects.Stroke(Color(1, 1, 0), 10))

script.script_main(an)
    def test_animated_bezier(self):
        lot = objects.Animation()
        sl = lot.add_layer(objects.ShapeLayer())

        shape = sl.add_shape(objects.Path())
        sl.add_shape(objects.Fill(Color(0, .25, 1)))

        bez = objects.Bezier()
        bez.closed = True
        bez.add_point(NVector(256, 0))
        bez.add_point(NVector(256+128, 256), NVector(0, 0), NVector(64, 128))
        bez.add_smooth_point(NVector(256, 512), NVector(128, 0))
        bez.add_point(NVector(256-128, 256), NVector(-64, 128), NVector(0, 0))

        new_bez = bez.clone()
        new_bez.vertices[2] = NVector(256, 256+128)
        new_bez.in_tangents[2] = NVector(64, 64)
        new_bez.out_tangents[2] = NVector(-64, 64)

        shape.shape.add_keyframe(0, bez)
        shape.shape.add_keyframe(30, new_bez)
        shape.shape.add_keyframe(60, bez)

        sif = builder.to_sif(lot)
        self.assertEqual(len(sif.layers), 1)
        self.assertIsInstance(sif.layers[0], api.GroupLayer)

        grp = sif.layers[0]
        self.assertEqual(len(grp.layers), 1)
        self.assertIsInstance(grp.layers[0], api.RegionLayer)
        self.assertTrue(grp.active)

        rgl = grp.layers[0]
        self.assertEqual(len(rgl.bline.points), 4)
        self.assert_nvector_equal(rgl.color.value, sif.make_color(0, .25, 1))
        self.assertTrue(rgl.active)
        self.assertTrue(rgl.bline.loop)

        for i in range(4):
            sp = rgl.bline.points[i]
            lp = bez.vertices[i] - NVector(256, 256)
            lt1 = bez.in_tangents[i] * -3
            lt2 = bez.out_tangents[i] * 3

            new_lp = new_bez.vertices[i] - NVector(256, 256)
            new_lt1 = new_bez.in_tangents[i] * -3
            new_lt2 = new_bez.out_tangents[i] * 3

            self.assertEqual(sp.point.keyframes[0].time, api.FrameTime.frame(0))
            self.assert_nvector_equal(sp.point.keyframes[0].value, lp)
            self.assert_nvector_equal(sp.t1.keyframes[0].value, lt1)
            self.assert_nvector_equal(sp.t2.keyframes[0].value, lt2)

            self.assertEqual(sp.point.keyframes[1].time, api.FrameTime.frame(30))
            self.assert_nvector_equal(sp.point.keyframes[1].value, new_lp)
            self.assert_nvector_equal(sp.t1.keyframes[1].value, new_lt1)
            self.assert_nvector_equal(sp.t2.keyframes[1].value, new_lt2)

            self.assertEqual(sp.point.keyframes[2].time, api.FrameTime.frame(60))
            self.assert_nvector_equal(sp.point.keyframes[2].value, lp)
            self.assert_nvector_equal(sp.t1.keyframes[2].value, lt1)
            self.assert_nvector_equal(sp.t2.keyframes[2].value, lt2)
Exemple #8
0
    (easing.Sigmoid(1 / 10), Color(0, 0, 1 / 10)),
]
height = 512 / len(easings)
width = height

for i in range(len(easings)):
    group = layer.add_shape(objects.Group())

    rectgroup = group.add_shape(objects.Group())
    rect = rectgroup.add_shape(objects.Rect())
    rect.size.value = Size(width, height)
    y = i * height + height / 2
    group.transform.position.add_keyframe(0, Point(width / 2, y),
                                          easings[i][0])
    group.transform.position.add_keyframe(90, Point(512 - width / 2, y),
                                          easings[i][0])
    group.transform.position.add_keyframe(180, Point(width / 2, y),
                                          easings[i][0])
    rectgroup.add_shape(objects.Fill(easings[i][1]))

    bezgroup = group.insert_shape(0, objects.Group())
    bez = group.transform.position.keyframes[0].bezier()
    bezgroup.transform.scale.value = Size(100 * width, -100 * height)
    bezgroup.transform.position.value = Point(-width / 2, width / 2)
    bezgroup.add_shape(objects.Path()).shape.value = bez
    sc = Color(0, 0, 0) if easings[i][1].length == math.sqrt(3) else Color(
        1, 1, 1)
    bezgroup.add_shape(objects.Stroke(sc, 0.1))

script.script_main(an)
from lottie import Point, Color

an = objects.Animation(60)

layer = objects.ShapeLayer()
an.add_layer(layer)

heart = objects.Bezier()
heart.add_point(Point(50, 20), Point(50, -20), Point(-50, -20))
heart.add_smooth_point(Point(0, 50), Point(-5, -10))
heart.add_smooth_point(Point(50, 100), Point(-10, 0))
heart.add_smooth_point(Point(100, 50), Point(-5, 10))
heart.closed = True

g1 = layer.add_shape(objects.Group())
shape = g1.add_shape(objects.Path())
shape.shape.value = heart
fill = layer.add_shape(objects.Fill(Color(1, 0, 0)))
stroke = layer.add_shape(objects.Stroke(Color(0, 0, 0), 5))

g2 = layer.add_shape(objects.Group())
bb = shape.bounding_box()
shapeb = g2.add_shape(objects.Path())
shapeb.shape.value.add_point(Point(bb.x1, bb.y1))
shapeb.shape.value.add_point(Point(bb.x2, bb.y1))
shapeb.shape.value.add_point(Point(bb.x2, bb.y2))
shapeb.shape.value.add_point(Point(bb.x1, bb.y2))
fill = layer.add_shape(objects.Fill([1, 1, 0]))

env = anutils.EnvelopeDeformation(Point(bb.x1, bb.y1), Point(bb.x2, bb.y2))
Exemple #10
0
an = objects.Animation(59)

layer = objects.ShapeLayer()
an.add_layer(layer)


bezier = objects.Bezier()
radius = 128
angle = -math.pi / 2
for i in range(5+1):
    bezier.add_point(PolarVector(radius, angle))
    angle += 2 * math.pi * 2 / 5
bezier.closed = True
bezier.reverse()

g = layer.add_shape(objects.Group())
g.transform.position.value = Point(radius, radius)
g.add_shape(objects.Path(bezier))
fill = g.add_shape(objects.Fill(color.from_uint8(255, 0, 100)))
fill.fill_rule = objects.FillRule.NonZero

g = layer.add_shape(objects.Group())
g.transform.position.value = Point(512-radius, 512-radius)
g.add_shape(objects.Path(bezier))
fill = g.add_shape(objects.Fill(color.from_uint8(255, 100, 0)))
fill.fill_rule = objects.FillRule.EvenOdd

script.script_main(an)

Exemple #11
0
layer = objects.ShapeLayer()
an.add_layer(layer)
g = layer.add_shape(objects.Group())

sine_displacer = anutils.SineDisplacer(300, 50, 0, 60, 10, 1, 45)
# Keep the left side fixed
displacer = anutils.DisplacerDampener(sine_displacer, lambda p: p.x / 128 if p.x < 128 else 1)

for i in range(0, 512+1, 16):
    b = g.add_shape(objects.Ellipse())
    b.size.value = Point(16, 16)
    b.position.value = Point(i, 100)
    displacer.animate_point(b.position)


bez = g.add_shape(objects.Path())
bez.shape.value.add_smooth_point(Point(256, 200), Point(50, 0))
bez.shape.value.add_smooth_point(Point(156, 300), Point(0, -50))
bez.shape.value.add_smooth_point(Point(256, 400), Point(-50, 0))
bez.shape.value.add_smooth_point(Point(356, 300), Point(0, 50))
bez.shape.value.close()
bez.shape.value.split_self_chunks(8)
displacer.animate_bezier(bez.shape)

g.add_shape(objects.Fill(Color(1, 1, 0)))


g = layer.add_shape(objects.Group())
bez = g.add_shape(objects.Path())
g.add_shape(objects.Stroke(Color(1, 0, 0), 5))
g.add_shape(objects.Fill(Color(0, 0, 1)))
                                      in_tan=NVector(0, -tl))
layer.transform.position.add_keyframe(last_frame / 4 * 2,
                                      Point(462, 256),
                                      out_tan=NVector(0, +tl),
                                      in_tan=NVector(+tl, 0))
layer.transform.position.add_keyframe(last_frame / 4 * 3,
                                      Point(256, 462),
                                      out_tan=NVector(-tl, 0),
                                      in_tan=NVector(0, +tl))
layer.transform.position.add_keyframe(last_frame / 4 * 4,
                                      Point(+50, 256),
                                      out_tan=NVector(0, -tl),
                                      in_tan=NVector(-tl, 0))

layer1 = objects.ShapeLayer()
an.add_layer(layer1)
layer1.add_shape(group)
layer1.add_shape(objects.Fill(Color(1, 0, 0)))
layer1.transform = layer.transform

bg = an.add_layer(objects.ShapeLayer())
track = bg.add_shape(objects.Path()).shape.value
track.closed = True
track.add_point(Point(+50, 256), NVector(0, +tl), NVector(0, -tl))
track.add_point(Point(256, +50), NVector(-tl, 0), NVector(+tl, 0))
track.add_point(Point(462, 256), NVector(0, -tl), NVector(0, +tl))
track.add_point(Point(256, 462), NVector(+tl, 0), NVector(-tl, 0))
bg.add_shape(objects.Stroke(Color(0, 0, 1), 50))

script.script_main(an)