MCPcopy Index your code
hub / github.com/reactive-python/reactpy / Scene

Function Scene

docs/source/reference/_examples/character_movement/main.py:34–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32
33@component
34def Scene():
35 position, set_position = use_state(Position(100, 100, 0))
36
37 return html.div(
38 {"style": {"width": "225px"}},
39 html.div(
40 {
41 "style": {
42 "width": "200px",
43 "height": "200px",
44 "background_color": "slategray",
45 }
46 },
47 image(
48 "png",
49 CHARACTER_IMAGE,
50 {
51 "style": {
52 "position": "relative",
53 "left": f"{position.x}px",
54 "top": f"{position.y}.px",
55 "transform": f"rotate({position.angle}deg) scale(2, 2)",
56 }
57 },
58 ),
59 ),
60 html.button(
61 {"on_click": lambda e: set_position(translate(x=-10))}, "Move Left"
62 ),
63 html.button(
64 {"on_click": lambda e: set_position(translate(x=10))}, "Move Right"
65 ),
66 html.button({"on_click": lambda e: set_position(translate(y=-10))}, "Move Up"),
67 html.button({"on_click": lambda e: set_position(translate(y=10))}, "Move Down"),
68 html.button({"on_click": lambda e: set_position(rotate(-30))}, "Rotate Left"),
69 html.button({"on_click": lambda e: set_position(rotate(30))}, "Rotate Right"),
70 )
71
72
73run(Scene)

Callers

nothing calls this directly

Calls 5

use_stateFunction · 0.90
imageFunction · 0.90
PositionClass · 0.85
translateFunction · 0.85
rotateFunction · 0.85

Tested by

no test coverage detected