-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy paththreewidget.py
More file actions
92 lines (74 loc) · 1.91 KB
/
Copy paththreewidget.py
File metadata and controls
92 lines (74 loc) · 1.91 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "marimo",
# "wigglystuff",
# ]
# ///
import marimo
__generated_with = "0.19.11"
app = marimo.App(width="medium")
with app.setup:
import marimo as mo
import random
from wigglystuff import ThreeWidget
@app.cell
def _():
random.seed(42)
data = []
for _ in range(900):
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
hex_value = f"#{r:02x}{g:02x}{b:02x}"
data.append(
{
"x": r / 255.0,
"y": g / 255.0,
"z": b / 255.0,
"color": hex_value,
"size": random.uniform(0.08, 0.2),
}
)
three = ThreeWidget(
data=data,
width=640,
height=420,
# show_grid=True,
# show_axes=True,
# axis_labels=["R", "G", "B"],
)
widget = mo.ui.anywidget(three)
return data, three, widget
@app.cell
def _(reset, shuffle):
btn_reset = mo.ui.button(on_click=reset, label="reset")
btn_shuffle = mo.ui.button(on_click=shuffle, label="make some noise")
[btn_reset, btn_shuffle]
return
@app.cell
def _(widget):
widget
return
@app.cell(hide_code=True)
def _(data, three):
def shuffle(_):
updates = []
for _point in three.data:
updates.append(
{
"x": _point["x"] + (random.random()-0.5)*0.1,
"y": _point["y"] + (random.random()-0.5)*0.3,
"z": _point["z"] + (random.random()-0.5)*0.1,
}
)
three.update_points(updates, animate=True, duration_ms=650)
def reset(_):
three.update_points(data, animate=True, duration_ms=650)
return reset, shuffle
@app.cell
def _(widget):
widget.start_rotate(speed=10.0)
return
if __name__ == "__main__":
app.run()