Пример #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()
Пример #2
0
from math import sqrt
from glc import Gif

with Gif("circle_example.gif", color_count=4) as a:
    a.set_duration(2)
    l = a.render_list
    r = a.w // 50
    cx, cy = a.w * 0.5, a.h * 0.5
    for x in range(r * 2, a.w - r, r * 2):
        for y in range(r * 2, a.h - r, r * 2):
            dx = x - cx
            dy = y - cy
            dist = sqrt(dx * dx + dy * dy)
            l.circle(x=x,
                     y=y,
                     radius=r,
                     phase=dist * 0.003,
                     line_width=2,
                     start=0,
                     end=[0, 360],
                     centered=True)
Пример #3
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()
Пример #4
0
from glc import Gif
from random import randint

with Gif("curve_path_example.gif", color_count=4) as a:
    a.set_duration(2)
    l = a.render_list
    step = a.h // 25
    path0, path1 = [], []
    for x in range(0, a.w, step):
        path0.append([x, randint(0, a.h)])
        path1.append([x, randint(0, a.h)])
    l.curve_path(points=[path0, path1])
Пример #5
0
from glc import Gif

with Gif("arrow_example.gif", color_count=4) as a:
    l = a.render_list
    n = 20
    w, h = a.w // n, a.h // n
    for x in range(w // 2, a.w, w):
        for y in range(h // 2, a.h, h):
            l.arrow(x=x,
                    y=y,
                    w=[w, w * 1.5],
                    h=[h, h * 1.5],
                    rotation=[0, 180],
                    phase=((x + 300) * y) / (a.w * a.h))
Пример #6
0
from glc import Gif
from glc.utils import lerp

with Gif("bezier_segment_example.gif", color_count=4) as a:
    a.set_duration(4)
    l = a.render_list
    start_x, start_y = -10, 10
    sw = 100
    s = 5
    end_y = a.h - start_y
    for i in range(a.w // s + 2):
        l.bezierseg(
            x0=start_x + (i * s), y0=start_y,
            x1=start_x + sw + (i * s), y1=lerp(0.3, start_y, end_y),
            x2=start_x - sw + (i * s), y2=lerp(0.6, start_y, end_y),
            x3=start_x + (i * s), y3=end_y,
            phase=i / (a.w // s),
            line_width=2
        )
Пример #7
0
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()
Пример #8
0
from glc import Gif
from math import pi

with Gif("arc_segment_example.gif", color_count=4) as a:
    l = a.render_list
    r = a.w // 30
    for x in range(r, a.w, r * 2):
        for y in range(r, a.h, r * 2):
            l.arcseg(x=x,
                     y=y,
                     radius=r,
                     start=0,
                     end=360,
                     arc=90,
                     line_width=10,
                     phase=(x * a.w + y) * pi * 0.03)
Пример #9
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)]))
Пример #10
0
from glc import Gif

with Gif("bezier_curve_example.gif", color_count=4) as a:
    a.set_duration(2)
    l = a.render_list
    ys, s, h = 10, 10, 200
    for i in range(a.h // s):
        c = [ys + (i * s) - h, ys + (i * s) + h]
        l.bezier(x0=0,
                 y0=a.h * 0.5,
                 x1=a.w * 0.3,
                 y1=c,
                 x2=a.w * 0.6,
                 y2=list(reversed(c)),
                 x3=a.w,
                 y3=a.h * 0.5,
                 phase=(i * 2) / (a.h // s),
                 line_width=2)