Skip to content

Instantly share code, notes, and snippets.

@zalo
zalo / MovingPlatform.cs
Last active April 5, 2023 06:38
Physics-Based Unity Player Controller
using UnityEngine;
public class MovingPlatform : MonoBehaviour {
public float timeInterval = 5f;
public AnimationCurve XMotion;
public AnimationCurve YMotion;
public AnimationCurve ZMotion;
public bool PingPong = true;
float platformTime;
@zalo
zalo / WacomMultiTouchProvider.cs
Last active June 27, 2019 04:39
A simple Unity Wacom Multitouch Data Provider that uses the WacomMTDN.dll from the Wacom Feel Multitouch Samples (linked in the comments)
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using UnityEngine;
using WacomMTDN;
// Simple Wacom Multitouch Unity Integration built from the Wacom's DotNet Example:
// https://developer-docs.wacom.com/display/DevDocs/Feel+Multi-touch+Sample+Code+Downloads
// WacomMTDN.dll can be found at: https://drive.google.com/file/d/1fvoRfIev28fKMvTrfF9IBZkAaWow5UJ4/view?usp=sharing
public class WacomMultiTouchProvider : MonoBehaviour {
@zalo
zalo / paperjsCSVGraphing.js
Created May 30, 2019 06:28
Loads the Iris Dataset .csv and graphs the distribution of its points in paper.js's Paperscript; eat your heart out, d3.js
// Run at http://sketch.paperjs.org
function graphData(data){
// Define the colors of the different species
let colors = {
'setosa': '#7fc97f',
'versicolor':'#beaed4',
'virginica':'#fdc086'
}
// Graph each datum
@zalo
zalo / 3DHeadOrientation.py
Last active August 16, 2022 06:30
This is an example using Adrian Bulat's face_alignment library and Python to draw the head's basis vectors
import numpy as np
import cv2
import face_alignment
# Initialize the face alignment tracker
fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._3D, flip_input=True, device="cuda")
# Start the webcam capture, exit with 'q'
cap = cv2.VideoCapture(0)
while(not (cv2.waitKey(1) & 0xFF == ord('q'))):
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]])
@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
@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
// 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 / 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;
@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