GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fastplotlib/tests/utils.py at streamplot · fastplotlib/fastplotlib

Expand file tree

/

utils.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
191 lines (153 loc) · 4.28 KB
/

utils.py

Copy path

File metadata and controls

191 lines (153 loc) · 4.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import numpy as np
import pygfx
def generate_slice_indices(kind: int):
n_elements = 10
a = np.arange(n_elements)
match kind:
case 0:
# simplest, just int
s = 2
indices = [2]
case 1:
# everything, [:]
s = slice(None, None, None)
indices = list(range(10))
case 2:
# positive continuous range, [1:5]
s = slice(1, 5, None)
indices = [1, 2, 3, 4]
case 3:
# positive stepped range, [2:8:2]
s = slice(2, 8, 2)
indices = [2, 4, 6]
case 4:
# negative continuous range, [-5:]
s = slice(-5, None, None)
indices = [5, 6, 7, 8, 9]
case 5:
# negative backwards, [-5::-1]
s = slice(-5, None, -1)
indices = [5, 4, 3, 2, 1, 0]
case 5:
# negative backwards stepped, [-5::-2]
s = slice(-5, None, -2)
indices = [5, 3, 1]
case 6:
# negative stepped forward[-5::2]
s = slice(-5, None, 2)
indices = [5, 7, 9]
case 7:
# both negative, [-8:-2]
s = slice(-8, -2, None)
indices = [2, 3, 4, 5, 6, 7]
case 8:
# both negative and stepped, [-8:2:2]
s = slice(-8, -2, 2)
indices = [2, 4, 6]
case 9:
# positive, negative, negative, [8:-9:-2]
s = slice(8, -9, -2)
indices = [8, 6, 4, 2]
case 10:
# only stepped forward, [::2]
s = slice(None, None, 2)
indices = [0, 2, 4, 6, 8]
case 11:
# only stepped backward, [::-3]
s = slice(None, None, -3)
indices = [9, 6, 3, 0]
case 12:
# list indices
s = [2, 5, 9]
indices = [2, 5, 9]
case 13:
# bool indices
s = a > 5
indices = [6, 7, 8, 9]
case 14:
# list indices with negatives
s = [1, 4, -2]
indices = [1, 4, 8]
case 15:
# array indices
s = np.array([1, 4, -7, 9])
indices = [1, 4, 3, 9]
others = [i for i in a if i not in indices]
offset, size = (min(indices), np.ptp(indices) + 1)
return {
"slice": s,
"indices": indices,
"others": others,
"offset": offset,
"size": size,
}
def generate_positions_spiral_data(inputs: str) -> np.ndarray:
"""
Generates a spiral/spring
Only 10 points so a very pointy spiral but easier to spot changes :D
"""
xs = np.linspace(0, 10 * np.pi, 10)
ys = np.sin(xs)
zs = np.cos(xs)
match inputs:
case "y":
data = ys
case "xy":
data = np.column_stack([xs, ys])
case "xyz":
data = np.column_stack([xs, ys, zs])
return data.astype(np.float32)
def generate_color_inputs(
name: str,
) -> list[str, np.ndarray, list, tuple] | list[str, np.ndarray]:
if name == "multi":
s = [
"r",
"g",
"b",
"cyan",
"magenta",
"green",
"yellow",
"white",
"purple",
"orange",
]
array = np.vstack([np.asarray(pygfx.Color(c)) for c in s])
return [s, array]
if name == "multi2":
# a second multi option
s = [
"g",
"r",
"cyan",
"magenta",
"b",
"black",
"white",
"purple",
"yellow",
"pink",
]
array = np.vstack([np.asarray(pygfx.Color(c)) for c in s])
return [s, array]
color = pygfx.Color(name)
s = name
a = np.array(color)
l = list(color)
t = tuple(color)
return [s, a, l, t]
MULTI_COLORS_TRUTH = np.array(
[
[1.0, 0.0, 0.0, 1.0],
[0.0, 1.0, 0.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[0.0, 1.0, 1.0, 1.0],
[1.0, 0.0, 1.0, 1.0],
[0.0, 0.501960813999176, 0.0, 1.0],
[1.0, 1.0, 0.0, 1.0],
[1.0, 1.0, 1.0, 1.0],
[0.501960813999176, 0.0, 0.501960813999176, 1.0],
[1.0, 0.6470588445663452, 0.0, 1.0],
]
)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.