-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcanvas_simple.py
More file actions
30 lines (26 loc) · 1.11 KB
/
Copy pathcanvas_simple.py
File metadata and controls
30 lines (26 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import experiment as exp
from canvas import Canvas
class CanvasSimpleExperiment(exp.Experiment):
async def run(self):
# Create a new Canvas instance to communicate with a Canvas app with ID "my_canvas" and start listening for incoming messages.
self.canvas = Canvas("my_canvas")
# Wait until a connection is made. Methods under the aio fields are async functions that await until a response from the browser arrives.
await self.canvas.aio.connected()
self.log.info("Connected to canvas app")
# To add anything to the stage we first need to add a Layer to the stage.
await self.canvas.aio.add("stage", "Layer", id="main")
# Add a red circle to the layer. The id from the previous line is used to reference the layer.
await self.canvas.aio.add(
"main",
"Circle",
x=100,
y=100,
radius=80,
fill="red",
id="circle",
)
async def end(self):
# Clear the canvas
self.canvas.reset()
# Stop listening to canvas messages
self.canvas.release()