Пример #1
0
from pynodegl_utils.misc import scene
from pynodegl_utils.toolbox.colors import COLORS

import pynodegl as ngl


@scene(
    txt=scene.Text(),
    fg_color=scene.Color(),
    bg_color=scene.Color(),
    box_corner=scene.Vector(n=3, minv=(-1, -1, -1), maxv=(1, 1, 1)),
    box_width=scene.Vector(n=3, minv=(-10, -10, -10), maxv=(10, 10, 10)),
    box_height=scene.Vector(n=3, minv=(-10, -10, -10), maxv=(10, 10, 10)),
    padding=scene.Range(range=[0, 100]),
    font_scale=scene.Range(range=[0, 15], unit_base=100),
    valign=scene.List(choices=("top", "center", "bottom")),
    halign=scene.List(choices=("left", "center", "right")),
)
def text(
    cfg,
    txt="the quick brown fox\njumps over the lazy dog",
    fg_color=COLORS.cgreen,
    bg_color=(0.3, 0.3, 0.3),
    box_corner=(-1 + 0.25, -1 + 0.25, 0),
    box_width=(1.5, 0, 0),
    box_height=(0, 1.5, 0),
    padding=2,
    font_scale=1.3,
    valign="center",
    halign="center",
):
Пример #2
0
                             box_corner=(ax, ay + field_hpos * field_h, 0),
                             box_width=(aw / 2., 0, 0),
                             box_height=(0, field_h, 0),
                             fg_color=list(field['color']) + [1],
                             halign='left',
                             aspect_ratio=cfg.aspect_ratio)
        text_group.add_children(text_node)

    quad = ngl.Quad((ax + aw / 2., ay, 0), (aw / 2., 0, 0), (0, ah - title_h, 0))
    render = get_render(cfg, quad, fields, block_definition, color_definition, block_fields, color_fields, layout)

    return ngl.Group(children=(title_node, text_group, render))


@scene(seed=scene.Range(range=[0, 100]),
       layout=scene.List(choices=LAYOUTS),
       color_tint=scene.Bool())
def debug_block(cfg, seed=0, layout=LAYOUTS[0], color_tint=True):
    cfg.duration = ANIM_DURATION
    cfg.aspect_ratio = (1, 1)

    spec = _get_data_spec(layout)

    fields_info, block_fields, color_fields, block_definition, color_definition = get_random_block_info(spec, seed, layout, color_tint=color_tint)

    fields_single   = [f for f in fields_info if f['category'] == 'single']
    fields_array    = [f for f in fields_info if f['category'] == 'array']
    fields_animated = [f for f in fields_info if f['category'].startswith('animated')]
    field_specs = (
        (fields_single,   (-1/3., -1, 2/3., 2.), 'Single fields'),
        (fields_array,    ( 1/3.,  0, 2/3., 1.), 'Arrays'),
Пример #3
0
import pynodegl as ngl
from pynodegl_utils.misc import scene
from pynodegl_utils.toolbox.colors import COLORS


@scene(
    txt=scene.Text(),
    fg_color=scene.Color(),
    bg_color=scene.Color(),
    box_corner=scene.Vector(n=3, minv=(-1, -1, -1), maxv=(1, 1, 1)),
    box_width=scene.Vector(n=3, minv=(-10, -10, -10), maxv=(10, 10, 10)),
    box_height=scene.Vector(n=3, minv=(-10, -10, -10), maxv=(10, 10, 10)),
    padding=scene.Range(range=[0, 100]),
    font_scale=scene.Range(range=[0, 15], unit_base=100),
    valign=scene.List(choices=('top', 'center', 'bottom')),
    halign=scene.List(choices=('left', 'center', 'right')),
)
def text(cfg,
         txt='the quick brown fox\njumps over the lazy dog',
         fg_color=COLORS['cgreen'],
         bg_color=(0.3, 0.3, 0.3, 1.0),
         box_corner=(-1+.25, -1+.25, 0),
         box_width=(1.5, 0, 0),
         box_height=(0, 1.5, 0),
         padding=2,
         font_scale=1.3,
         valign='center',
         halign='center',
):
    return ngl.Text(txt,
Пример #4
0
def _get_easing_nodes(cfg, color_program):
    ag = AutoGrid(_easing_list)
    cfg.aspect_ratio = (ag.nb_cols, ag.nb_rows)
    easing_h = 1. / ag.nb_rows
    easing_w = 1. / ag.nb_cols
    for easing, easing_id, col, row in ag:
        easing_name, zoom = easing
        easing_node = _get_easing_node(cfg, easing_name, zoom, color_program)
        easing_node = ngl.Scale(easing_node, factors=[easing_w, easing_h, 0])
        x = easing_w * (-ag.nb_cols + 1 + 2 * col)
        y = easing_h * (ag.nb_rows - 1 - 2 * row)
        easing_node = ngl.Translate(easing_node, vector=(x, y, 0))
        yield easing_node


@scene(easing_id=scene.List(choices=['*'] + _easing_names))
def easings(cfg, easing_id='*'):
    '''Display all the easings (primitive for animation / motion design) at once'''
    random.seed(0)

    cfg.duration = 2.

    vert_data = cfg.get_vert('color')
    frag_data = cfg.get_frag('color')
    color_program = ngl.Program(vertex=vert_data,
                                fragment=frag_data,
                                label='color')
    full_block = _block(2,
                        2,
                        color_program,
                        color=ngl.UniformVec4(value=(.3, .3, .3, 1)))
Пример #5
0
    if points:
        debug_points = {f"P{i}": p[:2] for i, p in enumerate(points)}
        objects.append(get_debug_points(cfg, debug_points))

    if controls:
        debug_controls = {f"C{i}": p[:2] for i, p in enumerate(controls)}
        objects.append(get_debug_points(cfg, debug_controls,
                                        color=COLORS.cyan))

    objects.append(moving_shape)

    return ngl.Group(children=objects)


@scene(easing=scene.List(choices=["linear", "back_in_out"]))
def simple_bezier(cfg, easing="linear"):
    cfg.duration = 2
    # fmt: off
    points = (
        (-0.7, 0.0, 0.0),
        (0.8, 0.1, 0.0),
    )
    controls = (
        (-0.2, -0.3, 0.0),
        (0.2, 0.8, 0.0),
    )
    # fmt: on

    keyframes = (
        ngl.PathKeyMove(to=points[0]),
        active_noise=ngl.NoiseFloat(octaves=1),
        active_probability=ngl.UniformFloat(0.4),  # glitch 40% of the time
        uv_noise_0=ngl.NoiseVec2(amplitude=0.05, frequency=freq,
                                 seed=1000 + 0),
        uv_noise_1=ngl.NoiseVec2(amplitude=0.05,
                                 frequency=freq,
                                 seed=1000 + 0x7FFF),
        uv_noise_2=ngl.NoiseVec2(amplitude=0.05,
                                 frequency=freq,
                                 seed=1000 + 0xFFFF),
    )
    return render


@scene(
    mode=scene.List(("ramp", "radial")),
    c0=scene.Color(),
    c1=scene.Color(),
)
def gradient_eval(cfg, mode="ramp", c0=(1, 0.5, 0.5), c1=(0.5, 1, 0.5)):
    """Animate a gradient and objects using CPU evaluation"""

    pos_res = dict(t=ngl.Time())
    pos0_x = ngl.EvalFloat("sin( 0.307*t - 0.190)", resources=pos_res)
    pos0_y = ngl.EvalFloat("sin( 0.703*t - 0.957)", resources=pos_res)
    pos1_x = ngl.EvalFloat("sin(-0.236*t + 0.218)", resources=pos_res)
    pos1_y = ngl.EvalFloat("sin(-0.851*t - 0.904)", resources=pos_res)

    trf0 = ngl.EvalVec3("x", "y", "0", resources=dict(x=pos0_x, y=pos0_y))
    trf1 = ngl.EvalVec3("x", "y", "0", resources=dict(x=pos1_x, y=pos1_y))