Skip to content

Instantly share code, notes, and snippets.

View paulkaplan's full-sized avatar

Paul Kaplan paulkaplan

View GitHub Profile
@paulkaplan
paulkaplan / gist:3036353
Created July 2, 2012 23:24 — forked from olistik/gist:2627011
Ubuntu 12.04 setup (rbenv, janus, postgres)

Basic pre-requisites

  • Some utilities:
sudo apt-get install vim tmux git
  • Copy/paste from the command line:
sudo apt-get install xclip
class STL
class Writer
attr_accessor :tris, :size
def initialize tris
@tris = tris
@size = tris.length*50 + 80 + 4
end
def write_stl_header f
80.times {|n| f << [0].pack("C") } #uint8
@paulkaplan
paulkaplan / Scene.rb
Created January 29, 2013 06:50
Scene writer for POVRay, with a simple ruby API
class Scene
attr_accessor :lights, :objects, :camera
def initialize
@lights = []
@objects = []
end
def add_light light
@lights.push light
end
@paulkaplan
paulkaplan / index.js
Created February 24, 2013 03:59
voxel.js game
var createEngine = require('voxel-engine')
var game = createEngine({
generate: function(x, y, z) {
if (x*x + y*y + z*z > 20*20) return 0;
return Math.floor(Math.random() * 4) + 1;
},
texturePath: './',
materials: [ 'dirt', 'grass', 'crate', 'brick' ]
});
game.appendTo('#container');
@paulkaplan
paulkaplan / index.js
Created February 24, 2013 04:07
voxel.js game
var createGame = require('voxel-engine')
function sphereWorld(x, y, z) {
// return the index of the material you want to show up
// 0 is air
if (x*x + y*y + z*z > 15*15) return 0
return 3
}
var game = createGame({
@paulkaplan
paulkaplan / index.js
Created February 24, 2013 04:11
voxel.js game
var createGame = require('voxel-engine')
function sphereWorld(x, y, z) {
// return the index of the material you want to show up
// 0 is air
if (x*x + y*y + z*z > 15*15) return 0
return 3
}
var game = createGame({
@paulkaplan
paulkaplan / colorTempToRGB.js
Last active March 4, 2024 10:29
Color Temperature to RGB
// From http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
// Start with a temperature, in Kelvin, somewhere between 1000 and 40000. (Other values may work,
// but I can't make any promises about the quality of the algorithm's estimates above 40000 K.)
function colorTemperatureToRGB(kelvin){
var temp = kelvin / 100;
@paulkaplan
paulkaplan / shapeKeysToJSON.py
Last active November 16, 2017 21:40
Blender Shape Keys to JSON
#http://stackoverflow.com/questions/7553726/blender-how-to-export-shape-keys-using-python
#and three js blender exporter
import bpy
import json
# monkeypatch the json encoder to truncate floats
# http://stackoverflow.com/questions/1447287/format-floats-with-standard-json-module
from json import encoder
encoder.FLOAT_REPR = lambda o: format(o, '.15g')
@paulkaplan
paulkaplan / gist:5770247
Last active October 12, 2021 01:43
Orbit Controls with momentum and damping for THREE.js
/**
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
*
* customized for momentum (zoom and phi/delta) by paulkaplan
*/
THREE.OrbitControls = function ( object, domElement ) {
@paulkaplan
paulkaplan / measureSort.js
Last active December 19, 2015 11:49
jQuery plugin to sort a list of measurements
(function($){
$.fn.sortByMeasurement = function(child_type){
var element = this;
if(!child_type) child_type = "li";
var SINGLE_REGEX = /\s*(\d*)?([\.\/])?(\d*)\s*([a-zA-z]*)/;