Skip to content

Instantly share code, notes, and snippets.

View zz85's full-sized avatar

Joshua Koo zz85

View GitHub Profile
@zz85
zz85 / signed_distance_fields.js
Created April 29, 2012 12:44
Javascript Signed Distance Fields Generation
/*
* signed distance fields generation in javascript
* uses the 8SSEDT algorithm for linear-time processing
*
* done in conjustion with the signed distance fields text experiment
*
* references:
* http://www.lems.brown.edu/vision/people/leymarie/Refs/CompVision/DT/DTpaper.pdf
* http://www.codersnotes.com/notes/signed-distance-fields
* http://guides4it.com/Mobile/iphone-3d-programming---crisper-text-with-distance-fields-(part-1)---generating-distance-fields-with-python.aspx
@zz85
zz85 / animals.proto
Created April 27, 2018 14:16
Java Protobuf Any vs Oneof
message Dog {
}
message Cat {
}
message Elephant {
@zz85
zz85 / mesh_simplify.html
Last active November 7, 2023 02:10
Fast Quadric Mesh Simplification JS port
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - modifier - Fast Quadric Mesh Simplification</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
font-family: Monospace;
background-color: #f0f0f0;
@zz85
zz85 / print.js
Last active June 10, 2023 19:16
Pretty Print JSON in Ascii Tree
// TODO add colors
sample = { a: { b: { c: 1, moo: [3,2,1] } }, z: 'zzzz' }
const asciitree = require('ascii-tree');
function pretty_json(v) {
console.log(JSON.stringify( v, 0, 2 ))
}
@zz85
zz85 / toon.js
Created March 11, 2014 23:30
Toon Pixel Shader (for Three.js Composer)
<script id="toon" type="frag/shader">
// Based on http://coding-experiments.blogspot.sg/2011/01/toon-pixel-shader.html
uniform float width;
uniform float height;
uniform sampler2D tDiffuse;
varying vec2 vUv;
#define HueLevCount 6
#define SatLevCount 7
@zz85
zz85 / undo.js
Last active July 26, 2022 20:18
Simple Undo / Redo System
// Simple Undo / Redo System
/*
* @author joshua koo / http://joshuakoo.com
*
* There are usually 2 different ways to handle undo / redo
* 1. you snapshot and store the states, so you can load them anytime
* 2. you store the deltas, actions, events or commands between save points.
*
* Method 1 is simplistic. But it works. It's a lot like git.
@zz85
zz85 / gist:1395215
Created November 26, 2011 07:13
Testing Creation of Simplex Noise Textures
function createNoiseTexture(width, height) {
var canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
var context = canvas.getContext('2d');
var image = context.createImageData( width, height );
var imageData = image.data;
@zz85
zz85 / pointInPolygon.js
Created October 3, 2011 00:16
Point in Polgon
// https://github.com/zz85/
// implements Point - in - Polygon
// described in "A Winding Number and Point-in-Polygon Algorithm"
// returns 0 if point is not in polygon
// returns n > 0 if contour winds around point in counter-clockwise manner n times
// returns n < 0 if contour winds around point in clockwise manner -n times
function pointInPolygon(point, contour) {
// Creates a copy of contour
var adjustedContour = [];
var i,il;
THREE.LetterZ = function () {
THREE.Geometry.call( this );
var scope = this;
vertices = [{"x":90.3,"y":0},{"x":0,"y":0},{"x":0,"y":-14.85},{"x":63.599999999999994,"y":-94.35},{"x":3,"y":-94.35},{"x":3,"y":-110.55},{"x":87.3,"y":-110.55},{"x":87.3,"y":-95.25},{"x":24,"y":-16.349999999999998},{"x":90.3,"y":-16.349999999999998}];
faces = [[9,0,1],[1,2,3],[3,4,5],[5,6,7],[8,9,1],[3,5,7],[7,8,1],[1,3,7]];
for (var i in vertices) {
@zz85
zz85 / THREE.Path.js & THREE.Shape.js
Created July 5, 2011 16:26
Prototype Path & Shape & Extrude Geometry Class
/**
* @author zz85 / http://www.lab4games.net/zz85/blog
* Creates free form path.
**/
THREE.Path = function (path) {
this.path = path || [];
};
var ACTIONS = {