-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathtriangle_js.py
34 lines (24 loc) · 1 KB
/
triangle_js.py
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
31
32
33
34
"""
Hypothetical example for a visualization to be converted to JS.
DOES NOT WORK YET. THIS IS MOSTLY TO GET AN IMPRESSION OF HOW IT COULD WORK.
This example uses Flexx to collect and compile the Python code to JS modules,
and provide a HTML5 canvas without having to write HTML.
"""
from flexx import flx
from wgpu.gui.flexx import WgpuCanvas # WgpuCanvas is a flx.Canvas subclass
import wgpu.backend.js # noqa: F401, Select JS backend
# Import the (async) function that we must call to run the visualization
import triangle
# todo: how to serialize the shaders? base64 or via a custom hook?
triangle.vertex_shader = "something that flexx can serialize"
triangle.fragment_shader = "something that flexx can serialize"
class Example(flx.Widget):
def init(self):
# All of this gets executed in JS
super().init()
with flx.HBox():
self.canvas = WgpuCanvas()
triangle.main(self.canvas)
if __name__ == "__main__":
m = flx.launch(Example, "chrome-browser")
flx.run()