Skip to content

Instantly share code, notes, and snippets.

@timohausmann
timohausmann / gist:5003280
Created February 21, 2013 08:43
Javascript Math: get the distance between two points.
/**
* return the distance between two points.
*
* @param {number} x1 x position of first point
* @param {number} y1 y position of first point
* @param {number} x2 x position of second point
* @param {number} y2 y position of second point
* @return {number} distance between given points
*/
Math.getDistance = function( x1, y1, x2, y2 ) {
@timohausmann
timohausmann / theatre.ts
Created May 25, 2023 14:38
theatre.ts isStudioHidden
import type { IStudio } from '@theatre/studio';
export const theatre = { isInit: false };
export const studioHelper = {
isStudioHidden: (): boolean => {
if (process.env.NEXT_PUBLIC_VERCEL_ENV === 'production') {
return true;
} else if(theatre.isInit) {
const isHidden = (require('@theatre/studio').default as IStudio).ui.isHidden;
@timohausmann
timohausmann / how-to-use.ts
Last active April 5, 2023 16:45
💣 Extention for theatre.js Studio to clear the local state
import studio from '@theatre/studio';
import { studioResetExtention } from './studioResetExtention';
// just extend studio
studio.extend(studioResetExtention);
studio.initialize();
@timohausmann
timohausmann / Readme.MD
Last active December 2, 2022 13:51
useAlphaVideoTexture Hook for React Three Fiber

Playing transparent videos with alphachannel currently requires two file formats / codecs: webm (vp9) and mov (hvc1) for Safari.

This hook makes it easy to use two files as input and pick the right one. (Variation of useVideoTexture)

Usage (Vite example):

import { Billboard } from '@react-three/drei';
@timohausmann
timohausmann / facebook_graph_api_2.pde
Created January 20, 2014 19:32
Another Facebook Graph API Example for Processing
/**
* In this example, we will request your first name and your profile picture from Facebook.
* We will store the acquired information in these variables:
*/
String name;
int mutualfriends_amount;
int likes_amount;
/**
* You need an Access Token to perform requests to the Facebook Graph API.
@timohausmann
timohausmann / firebase-json-export-node.js
Last active June 17, 2021 10:32
Two simple scripts to quickly export and import any collection data as JSON with node.js firebase-admin
const fs = require('fs');
const path = require('path');
const admin = require('firebase-admin');
const collectionName = 'characters';
(async () => {
/**
* How to get your serviceAccountKey:
@timohausmann
timohausmann / gist:61d2455d6ae2b26d067d33c39ff20487
Created July 4, 2018 11:59
After Effects: Bounce Expression
amp = .1;
freq = 2.0;
decay = 6.0;
n = 0;
if(numKeys > 0) {
n = nearestKey(time).index;
if(key(n).time > time) {
n--;
}
@timohausmann
timohausmann / gist:4997956
Last active May 20, 2019 14:14
Javascript Math: get degree between two points
/**
* return the angle between two points.
*
* @param {number} x1 x position of first point
* @param {number} y1 y position of first point
* @param {number} x2 x position of second point
* @param {number} y2 y position of second point
* @return {number} angle between two points (in radian)
*/
Math.getAngle = function( x1, y1, x2, y2 ) {
@timohausmann
timohausmann / facebook_graph_api.pde
Last active March 20, 2019 23:05
Simple Facebook Graph API Example With Processing
/**
* In this example, we will request your first name and your profile picture from Facebook.
* We will store the acquired information in these variables:
*/
String my_name;
PImage my_photo;
/**
* You need an Access Token to perform requests to the Facebook Graph API.
* Access Tokens are only valid for a short period of time (1-2 hours).
@timohausmann
timohausmann / gist:6088488
Created July 26, 2013 12:27
javascript: xTransform
(function(a) { a.xTransform = function(b) { return { webkitTransform: b, mozTransform: b, transform: b }; } })(window);