Skip to content

Instantly share code, notes, and snippets.

@zalo
zalo / voronoi_decomposition.py
Last active December 16, 2023 00:20
New Convex Decomposition Technique using Weighted-Voronoi Diagrams aka Power Diagrams aka Laguerre Tessellations
import tess
import random
import trimesh
import manifold3d
import numpy as np
from time import perf_counter
rand_color = [random.random(), random.random(), random.random()]
def explode(convex_pieces, explode_amount = 1.5, debug_shapes = None):
global rand_color
@zalo
zalo / canonicalHomographyFlowScreen.py
Last active February 7, 2024 23:21
Webcam Lightgun Tracking Script and Leap2 Lightgun Tracking Scripts
import numpy as np
import cv2
import dxcam
import win32api
import threading
import time
#from line_profiler import LineProfiler
class webcamThread(threading.Thread):
def __init__(self):
#ifdef RENDER_SNIPPET
#include <vector>
#include "PxPhysicsAPI.h"
#include "../snippetrender/SnippetRender.h"
#include "../snippetrender/SnippetCamera.h"
using namespace physx;
@zalo
zalo / multitouch.py
Last active October 5, 2022 05:29
Python Windows Multitouch Interface
from ctypes import *
from ctypes.wintypes import *
# Constants
# For touchMask
TOUCH_MASK_NONE= 0x00000000 # Default
TOUCH_MASK_CONTACTAREA= 0x00000001
TOUCH_MASK_ORIENTATION= 0x00000002
TOUCH_MASK_PRESSURE= 0x00000004
TOUCH_MASK_ALL= 0x00000007
@zalo
zalo / Debug.js
Last active March 29, 2021 19:08
Small Debug Utility for viewing Mobile Console Errors
/** This class provides Debug Utilities. */
class Debug {
/** Reroute Console Errors to the Main Screen (for mobile)
* @param {Worker} worker */
constructor(worker) {
// Route Worker Errors Here
worker.registerCallback("error", this.fakeError.bind(this));
// Intercept Main Window Errors as well
@zalo
zalo / opencascade.d.ts
Created July 23, 2020 08:40
opencascade.js Typescript Autogenerated Definitions
export default opencascade; // Optional Line
declare function opencascade<T>(target?: T): Promise<T & typeof opencascade>;
declare module opencascade {
function destroy(obj: any): void;
function _malloc(size: number): number;
function _free(ptr: number): void;
const HEAP8: Int8Array;
const HEAP16: Int16Array;
const HEAP32: Int32Array;
const HEAPU8: Uint8Array;
// This is just an example script for converting hand motions to PWM Servo Angles 1-255
// Designed to be used with UnityModules - https://github.com/leapmotion/UnityModules
using Leap;
using Leap.Unity;
using UnityEngine;
public class HandAngleParser : MonoBehaviour {
private const int N_FINGERS = 5;
private const int N_ACTIVE_BONES = 2;
@zalo
zalo / LAPLASCIIAN.py
Last active April 29, 2020 20:14
A mildly complex program that will compare each chunk of an image's laplacian to all the ASCII characters for the best fit...
import numpy as np
import cv2
import pyperclip
from PIL import ImageFont, ImageDraw, Image
laplacian = False
density = 17
font_size_y = 18
blur = 5 # Must Be Odd
@zalo
zalo / turboCosineApproximation.py
Last active April 29, 2020 20:15
Approximate Google's new "Turbo" Pallette with Inigo Quilez's Cosine Palette Formula
# Fitting Google's "Turbo" Palette with a Cosine Approximation
# https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html
# Inspired by: https://observablehq.com/@mbostock/turbo
# Compare: https://i.imgur.com/5GW6Se2.png
# First import the usual suspects
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
import numpy as np
import cv2
import face_alignment
# Initialize the chip resolution
chipSize = 300
chipCorners = np.float32([[0,0],
[chipSize,0],
[0,chipSize],
[chipSize,chipSize]])