Skip to content

Instantly share code, notes, and snippets.

@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]])
@zalo
zalo / 3DHeadOrientation.py
Last active November 26, 2024 10:43
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'))):
@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 / 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 / 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;