Skip to content

Instantly share code, notes, and snippets.

@yiwenl
yiwenl / JsGetBezierPoints
Created March 2, 2015 14:08
Get Bezier line from points
MathUtils = MathUtils || {};
MathUtils.level = function(i) {
if(i==0) return 1;
else return i*MathUtils.level(i-1);
}
MathUtils.binCoefficient = function(n, i) {
return MathUtils.level(n) / ( MathUtils.level(i) * MathUtils.level(n-i) );
@yiwenl
yiwenl / JsPrototypeGetterSetter
Created February 28, 2015 10:54
Getter / Setter for Javascript function prototype
p.__defineGetter__("test", function() {
return "testing testing";
});
p.__defineSetter__("test", function() {
// DO SOMETHING
});
@yiwenl
yiwenl / GLSL_getDepthColor
Created February 25, 2015 16:48
GLSL code for getting the colour of the depth
//float n = 5.0;
//float f = 800.0;
float getDepth(float z, float n, float f) {
return (2.0 * n) / (f + n - z*(f-n));
}
@yiwenl
yiwenl / JsBlobSaveJson
Last active September 25, 2023 18:35
Javascript using Blob to save json file
var saveJson = function(obj) {
var str = JSON.stringify(obj);
var data = encode( str );
var blob = new Blob( [ data ], {
type: 'application/octet-stream'
});
var url = URL.createObjectURL( blob );
var link = document.createElement( 'a' );