Beispiel #1
0
from math import sin, pi, cos
from example_util import get_filename
from glc import Gif
from glc.utils import rad
from glc.color import Color, sinebow

with Gif(get_filename(__file__), color_count=128) as a:
    a.set_bg_color(Color("black")).set_duration(5).set_size(300, 500)
    l = a.render_list
    res = 300
    phase_shift = rad(40)
    c = [
        sinebow(i / 2, 0.3, 0.3, 0.3, 0, 1 * phase_shift, 2 * phase_shift)
        for i in range(res)
    ]
    for y in range(res - 1, 0, -4):
        l.rect(x=a.w * 0.5,
               y=y + 100,
               w=100 + cos(y / res * 2 * pi) * 50,
               h=100 + sin(y / res * 2 * pi) * 50,
               fill=c[y],
               stroke=Color("0x30000000"),
               line_width=4,
               scale_y=0.5,
               rotation=[0, 360],
               phase=y / res * 0.1)

    a.save()
Beispiel #2
0
from example_util import get_filename
from glc import Gif
from glc.color import Color, hue_split


with Gif(get_filename(__file__)) as a:
    l = a.set_duration(7).set_ease("elastic").set_size(300, 400).render_list

    blu = Color("0xFF3774A3")
    yel = Color("0xFFDFAD20").desaturate(10).lighten(5)

    c = l.container(x=a.w * 0.5, y=a.h * 0.5, rotation=[-180, 0], scale_x=[0.5, 1.5, 1], scale_y=[0.5, 1.5, 1])

    l.roundrect(x=0, y=0, w=140, h=120, line_width=10, radius=35, fill=yel, stroke="white", translation_x=40, translation_y=0, parent=c)

    l.roundrect(x=0, y=0, w=120, h=120, line_width=10, radius=35, fill=blu, stroke="white", translation_x=0, translation_y=-60, parent=c)

    l.roundrect(x=0, y=0, w=140, h=120, line_width=10, radius=30, fill=blu, stroke="white", translation_x=-40, parent=c)

    l.rect(x=0, y=0, translation_x=-14, translation_y=-30, w=100, h=50, stroke=False, fill=blu, parent=c)

    l.roundrect(x=0, y=0, w=120, h=120, line_width=10, radius=35, fill=yel, stroke="white", translation_x=0, translation_y=60, parent=c)

    l.rect(x=0, y=0, translation_x=30, translation_y=30, w=100, h=50, stroke=False, fill=yel, parent=c)

    l.circle(x=0, y=0, radius=[0, 10], translation_x=-30, translation_y=-90, fill="white", stroke=False, parent=c, phase=0.02).set_ease("elastic")

    l.circle(x=0, y=0, radius=[0, 10], translation_x=30, translation_y=90, fill="white", stroke=False, parent=c).set_ease("elastic")

    l.ray(x=0, y=0, translation_x=-10, translation_y=60, line_width=10, length=80, stroke="white", parent=c)
Beispiel #3
0
from example_util import get_filename
from glc import Gif
from glc.color import split_complementaries, Color


with Gif(get_filename(__file__), color_count=8) as a:
    col, col2, col3 = split_complementaries(Color("mustard"), 140)

    l = a.set_bg_color(col).set_size(400, 400).set_fps(24).set_duration(4).set_loop().set_ease("linear").render_list
    r, lw = a.w // 40, 3
    for x in range(r * 2, a.w - r, r * 2):
        for y in range(r * 2, a.h - r, r * 2):
            c = l.container(x=x, y=y, rotation=[0, 360], phase=(x + y) / a.w)
            l.oval(x=0, y=0, rx=r, ry=r * 0.5, stroke=False, fill=col3, parent=c)
            l.oval(x=0, y=0, rx=r, ry=r * 0.5, stroke="white", fill=False, start=0, end=180, line_width=lw, parent=c)
            l.oval(x=0, y=0, rx=r, ry=r * 0.5, stroke=Color(col3).darken(20), fill=False, start=180, end=360, line_width=lw, parent=c)

    a.save()
Beispiel #4
0
from example_util import get_filename
from glc.utils import remap
from glc import Gif


with Gif(get_filename(__file__)) as a:
    l = a.render_list
    w, h = a.w, a.h
    r = 20

    iv = "linear quadratic cubic quartic quintic sine bounce circular exponential back elastic".split()
    length = len(iv)

    for i in range(length):
        l.circle(
            x=remap(i + 1, 1, length, r, w - r),
            y=[500 * 0.5 - 100, 500 * 0.5 + 100],
            radius=r
        ).ease = iv[i]

    a.save()
Beispiel #5
0
from example_util import get_filename
from glc import Gif


with Gif(get_filename(__file__), emoji_path="../../dev/72x72/") as a:
    a.set_ease("linear").set_loop(False).set_duration(5).set_size(400, 100).set_bg_color("0xff000000")
    l = a.render_list
    t = l.text(
        x=a.w * 0.5, y=a.h * 0.5,
        family="Arial",
        size=50,
        text="test 👍 test 👍👍 👍",
        translation_y=0,
        fill="0xffffdea0"
    )

    ex = t.get_extents(a.context)
    tw = ex["text_width"]

    # the proper way to put the text at the edge of the canvas is:
    # animation width / 2 + text width / 2
    # for the other way around, invert the signs, so
    # -animation width / 2 - text width / 2

    t.set_prop(
        translation_x=[a.w * 0.5 + tw * 0.5, -a.w * 0.5 - tw * 0.5]
    )

    a.save()
from math import cos, sin, pi
from example_util import get_filename
from glc import Gif


def draw(l, surf, ctx, t):
    xpos = cos(t * 2 * pi) * 100 + surf.get_width() * 0.5
    ypos = sin(t * 2 * pi) * 100 + surf.get_height() * 0.5
    w, h = 100, 100

    ctx.set_source_rgb(0, 0, 0)
    ctx.translate(xpos, ypos)
    ctx.translate(-w * 0.5, -h * 0.5)
    ctx.rectangle(0, 0, w, w)
    ctx.fill()


with Gif(get_filename(__file__), after_render=draw) as a:
    a.save()
Beispiel #7
0
from example_util import get_filename
from glc import Gif

with Gif(get_filename(__file__), emoji_path="../../dev/72x72/") as a:
    a.set_size(600, 200).set_bg_color(0xff36393e)
    l = a.render_list
    l.text(family="Comic Sans MS",
           x=a.w * 0.5,
           y=a.h * 0.5,
           text="this is just a single image \N{OK HAND SIGN}",
           fill=0xffffffff,
           size=40)

    with open(a.filename, 'wb') as f:
        f.write(a.save_with_imageio([a.render_at(0.0)]))