def __init__(self, vertices=None, faces=None, color=(0.5, 0.5, 1, 1), **kwargs): visuals.Visual.__init__(self, vcode=shading_vertex_template, fcode=shading_fragment_template, gcode=shading_geometry_template, **kwargs) self.set_gl_state('translucent', depth_test=True, cull_face=False) self.shading = 'smooth' self._draw_mode = 'lines_adjacency' # Define buffers self.vv = None self._vertices = gloo.VertexBuffer(np.zeros((0, 3), dtype=np.float32)) self._faces = gloo.IndexBuffer() self._color = clr.Color(color) # Init self._bounds = None # Note we do not call subclass set_data -- often the signatures # do no match. CuttingPathVisual.set_data(self, vertices=vertices, faces=faces) self.freeze()
def add_vertical_ruler(self, x: float) -> scene.visuals.InfiniteLine: """Add a single light grey vertical line at position 'x' on the canvas.""" return scene.visuals.InfiniteLine( pos=float(x), color=color.Color("#ddd", alpha=0.8).rgba, parent=self.view.scene, vertical=True, )
def add_horizontal_band(self, y0: float, y1: float) -> scene.visuals.Polygon: """ Add a horizontal band (rectangle) covering 'y0' to 'y1' on the canvas. """ _, size = self.shape_ coords = [(0, y0), (0, y1), (size, y1), (size, y0)] return scene.visuals.Polygon(coords, color=color.Color('#ddd', alpha=0.1), parent=self.view.scene)
def add_horizontal_ruler(self, y: float) -> scene.visuals.InfiniteLine: """Add a single light grey horizontal line at 'y' on the canvas.""" return scene.visuals.InfiniteLine( pos=float(y), color=color.Color("#ddd", alpha=0.8).rgba, parent=self.view.scene, vertical=False, )
def focus_change(self, r): if self.zone is not None: self.zone.parent = None self.zone = None coords = [ (r - 0.2, self.etraces.max() + 1), (r - 0.2, self.etraces.min() - 1), (r + 0.2, self.etraces.min() - 1), (r + 0.2, self.etraces.max() + 1), ] self.zone = scene.visuals.Polygon( coords, color=color.Color("grey", alpha=0.7), parent=self.plot_.view.scene ) self.plot_.view.camera.set_range( x=(r - 20, r + 20), y=(self.etraces.min(), self.etraces.max()), z=(0, 0) )
class plot: bg_clr = "#222" # dark background color # bg_clr = "#fff" # clear highlighted = color.Color("#41CCB4") others = highlighted.darker(0.5) def __init__(self, parent=None): self.canvas = scene.SceneCanvas( size=(1280, 900), keys="interactive", bgcolor=plot.bg_clr, parent=parent, ) self.grid = self.canvas.central_widget.add_grid(spacing=0) self.view = self.grid.add_view(row=0, col=1, camera="panzoom") self.colormap = color.get_colormap('husl')[np.linspace(0., 1., 24)] self.n = 0 self.lines = {} self.x_axis = scene.AxisWidget(orientation="bottom", text_color="#ddd") self.y_axis = scene.AxisWidget(orientation="left", text_color="#ddd") self.x_axis.stretch = (1, 0.05) self.y_axis.stretch = (0.05, 1) self.grid.add_widget(self.x_axis, row=1, col=1) self.grid.add_widget(self.y_axis, row=0, col=0) self.x_axis.link_view(self.view) self.y_axis.link_view(self.view) self.canvas.show() if parent is None: self.canvas.app.run() def add_curve(self, curve, index): self.n += 1 self.lines[index] = scene.LinePlot(curve, color=self.colormap[self.n], parent=self.view.scene) # self.view.camera.set_range(x=(0, curve.shape[0]), y=(curve.min(), curve.max())) def remove_curve(self, index): self.n -= 1 self.lines[index].parent = None self.lines[index] = None self.lines.pop(index)
def focus_change(self, r): if self.zone is not None: self.zone.parent = None self.zone = None coords = [ (r - 0.2, self.etraces.max() + 1), (r - 0.2, self.etraces.min() - 1), (r + 0.2, self.etraces.min() - 1), (r + 0.2, self.etraces.max() + 1), ] self.zone = scene.visuals.Polygon(coords, color=color.Color("#ccc", alpha=0.7), parent=self.plot_.view.scene) y_range = self.etraces.max() - self.etraces.min() y_fct = 3 y_padding = y_range / y_fct self.plot_.view.camera.set_range(x=(r - 5, r + 5), y=(self.etraces.min() - y_padding, self.etraces.max() + y_padding), z=(0, 0))
'xmax': 20000, 'ymin': 0, 'ymax': 1.0, 'labelx': 'frequency (Hz)', 'labely': 'amplitude (dB)' }) lightColor = scene.visuals.Rectangle(center=(PLOT_SIZE * 2.5 + MARGIN_X * 3, PLOT_SIZE * 1.5 + MARGIN_Y * 2), color='#a7b8d3', height=PLOT_SIZE, width=PLOT_SIZE, parent=window.scene) #buffer = RingBuffer(capacity = BUFFER_SIZE, dtype = numpy.int16) ledColor = color.Color() ledColor.hsv = (0.0, 1.0, 1.0) hue = 0.0 value = 1.0 saturation = 1.0 globalSpeed = 1.0 class SoundProcessor: def __init__(self): pass def calculateRMS(self, samples, start, length): averageSquared = 0 for i in range(0, length): sampleSquared = pow(samples[start + i], 2.0)
# # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # # # Copyright 2019 Victor Servant, Ledger SAS import numpy as np from vispy import scene from vispy import color # Starting from https://gist.github.com/yhql/70c3e59019cb73ec83870e946166b95f # bg_clr = "#222" # dark background color bg_clr = "#000" # dark background color highlighted = color.Color("#41CCB4") others = highlighted.darker(0.5) class plot: """ Fast plot of many large traces as a single object, using vispy. """ def __init__(self, icurves, highlight=None, clrmap="husl", colors=None, parent=None): """ :param icurves: input curve or list of curves