async def serve(q: Q): hilbert_curve = make_hilbert_curve(300, q.args.depth or 5) if not q.client.initialized: q.page['curve'] = ui.graphics_card( box='1 1 4 6', view_box='0 0 300 300', width='100%', height='100%', scene=g.scene(hilbert_curve=g.path( d=hilbert_curve, fill='none', stroke='#333')), ) q.page['form'] = ui.form_card( box='1 7 4 1', items=[ ui.slider(name='depth', label='Play with this Hilbert curve!', min=1, max=6, value=5, trigger=True), ], ) q.client.initialized = True else: g.draw(q.page['curve'].scene.hilbert_curve, d=hilbert_curve) await q.page.save()
def update_grid(page, grid_state, n_rows, n_cols, background): scene = page['game'].scene for row in range(n_rows): for col in range(n_cols): if grid_state[(row, col)] == 1: g.draw(scene[f'cell_{row}_{col}'], fill='black') else: g.draw(scene[f'cell_{row}_{col}'], fill=background) page.save()
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', stroke_width='1px'), ), ) page.save() def rotate(deg): return f'rotate({deg} 50 50)' scene = page['example'].scene while True: time.sleep(1) now = datetime.datetime.now() g.draw(scene.hour, transform=rotate(30 * (now.hour % 12) + now.minute / 2)) g.draw(scene.min, transform=rotate(6 * now.minute)) g.draw(scene.sec, transform=rotate(6 * now.second)) page.save()