Skip to content

Instantly share code, notes, and snippets.

@asnt
asnt / vispy-issue_2090-framebuffer_capture_alpha.py
Last active June 22, 2021 18:05
Try to indentify an equivalence between `canvas.render()` and `gloo.wrappers.read_pixels()`.
from vispy import scene
from vispy.scene.visuals import Plane
from vispy.visuals import transforms
a = .5
colors = [
(.25, .25, .25, 1),
(0, 0, 1, a),
(0, 1, 0, a),
import numpy as np
import vispy
from vispy import geometry
from vispy import scene
canvas = scene.SceneCanvas(keys='interactive', bgcolor='white',
size=(800, 600), show=True)
view = canvas.central_widget.add_view()
import numpy as np
import vispy
from vispy import scene
canvas = scene.SceneCanvas(keys='interactive', bgcolor='white',
size=(800, 600), show=True)
view = canvas.central_widget.add_view()
view.camera = 'arcball'
@asnt
asnt / vispy-issue_1984-solution.py
Last active February 16, 2021 17:59
Render a mesh with different texture maps (i.e. materials) on different regions using vispy
"""Render a mesh with different texture maps (i.e. materials) on different
regions using vispy.
Tested on vispy at commit c4f7ef42.
"""
import argparse
import pathlib
import numpy as np
@asnt
asnt / wavefront.py
Created August 1, 2019 20:25
Basic wavefront obj loader
import logging
import os.path
import numpy as np
from PIL import Image
logger = logging.getLogger(__name__)
"""Basic mesh viewer using vispy."""
import argparse
from vispy import app, scene
from vispy.io import read_mesh, load_data_file
from vispy.scene.visuals import Mesh
parser = argparse.ArgumentParser()
@asnt
asnt / ply2obj.sh
Created January 27, 2019 14:33
Convert a dir of ply to obj
#!/bin/bash
# Convert ply files in a directory to obj in parallel.
#
# Requires: gnu parallel, assimp
dir=$1
plys=( $(ls $dir/*.ply) )
objs=( "${plys[@]/.ply/.obj}" )
@asnt
asnt / half_marthon_time_vs_speed.py
Created June 8, 2018 13:27
Finish time of half marathon vs average time
import matplotlib.pyplot as plt
import numpy as np
speed0 = 10
speed1 = 20
n_speeds = (speed1 - speed0) * 10
speed = np.linspace(speed0, speed1, n_speeds)
duration = 21 / (speed / 60)