Beispiel #1
0
def create_grid(n_rows, n_cols, fill, width, height, stroke, stroke_width):
    grid = {}
    for row in range(n_rows):
        for col in range(n_cols):
            grid[f'cell_{row}_{col}'] = g.rect(
                x=col * width,
                y=row * height,
                width=width,
                height=height,
                fill=fill,
                stroke=stroke,
                stroke_width=stroke_width,
            )
    return grid
Beispiel #2
0
ellipse = g.ellipse(cx=25, cy=25, rx=25, ry=20)
image = g.image(
    width=50,
    height=50,
    href=
    'https://www.python.org/static/community_logos/python-powered-h-140x182.png'
)
line = g.line(x1=0, y1=0, x2=50, y2=50)
path = g.path(d='M 0,0 L 50,50 L 50,0 L 0,50 z')
path2 = g.path(d=g.p().M(0, 0).L(50, 50).L(50, 0).L(
    0, 50).z().d())  # same effect as above, but programmable.
path3 = g.p().M(0, 0).L(50, 50).L(50, 0).L(
    0, 50).z().path()  # same effect as above, but a tad more concise.
polygon = g.polygon(points='0,0 50,50 50,0 0,50')
polyline = g.polyline(points='0,0 50,50 50,0 0,50')
rect = g.rect(x=0, y=0, width=50, height=50)
rounded_rect = g.rect(x=0, y=0, width=50, height=50, rx=10)
text = g.text(x=0, y=48, text='Z', font_size='4em')

# Collect 'em all
shapes = [
    arc, circle, ellipse, image, line, path, path2, path3, polygon, polyline,
    rect, rounded_rect, text
]

# Apply fill/stroke for each shape
for shape in shapes:
    shape.fill = 'none' if g.type_of(shape) == 'polyline' else 'crimson'
    shape.stroke = 'darkred'
    shape.stroke_width = 5
Beispiel #3
0
page['example'] = ui.graphics_card(
    box='1 1 2 3',
    view_box='0 0 100 100',
    width='100%',
    height='100%',
    stage=g.stage(face=g.circle(cx='50',
                                cy='50',
                                r='45',
                                fill='#111',
                                stroke_width='2px',
                                stroke='#f55'), ),
    scene=g.scene(
        hour=g.rect(x='47.5',
                    y='12.5',
                    width='5',
                    height='40',
                    rx='2.5',
                    fill='#333',
                    stroke='#555'),
        min=g.rect(x='48.5',
                   y='12.5',
                   width='3',
                   height='40',
                   rx='2',
                   fill='#333',
                   stroke='#555'),
        sec=g.line(x1='50',
                   y1='50',
                   x2='50',
                   y2='16',
                   stroke='#f55',