Skip to content

Instantly share code, notes, and snippets.

@hughsk
hughsk / index.js
Created May 7, 2014 23:06
requirebin sketch
var clone = require('clone')
var uniq = require('uniq')
var raf = require('raf')
var xhr = require('xhr')
var s = 200
var t = 250
xhr({
uri: 'http://www.corsproxy.com/bl.ocks.org/mbostock/raw/4090846/world-110m.json'
, json: true
float sSphere(vec3 p, float time) {
return length(p) - 1.0 - noise(p, time) * 0.05;
}
vec3 calcNormal(vec3 p, float time) {
const float eps = 0.002;
const vec2 offset = vec2(1.0, -1.0);
return normalize(
offset.xyy * sSphere(p + offset.xyy * eps, time) +
@hughsk
hughsk / lessmark.js
Created October 28, 2011 07:36
Pick up compiled LESS code using a bookmarklet!
//Bookmarklet Code
$('head style').each(function() {if ($(this).attr('id') && $(this).attr('id').indexOf('less:') > -1) {var lesscode = $(document.createElement('div'));lesscode.html($(this).text().replace(/\/\*.*?\*\//g,' ').replace(/[ ]{2,100}/g,' '));lesscode.css('padding','20px').css('font-size','10px').css('background-color','#ddd').css('font-family','monospace');$('body:last-child').append(lesscode);} });
//Legible version
$('head style').each(function() {
if ($(this).attr('id') && $(this).attr('id').indexOf('less:') > -1) {
var lesscode = $(document.createElement('div'));
//Clean up a lot of comments and white space...
lesscode.html($(this).text().
@hughsk
hughsk / Boide.pde
Created December 27, 2011 08:40
Simple Boids example in Processing
class Boid {
PVector pos;
PVector spd;
PVector acc;
Boid() { this(random(0, width), random(0, height)); }
Boid(float x, float y) { this(x, y, random(0,1), random(0,1)); }
Boid(float x, float y, float xspd, float yspd) {
pos = new PVector(x, y);
@hughsk
hughsk / rmdirSyncForce.js
Created February 1, 2012 07:47
Synchronous `rmdir --recursive` for NodeJS.
// Thanks to [liangzan's gist](https://gist.github.com/807712)
rmdirSyncForce = function(path) {
var files, file, fileStats, i, filesLength;
if (path[path.length - 1] !== '/') {
path = path + '/';
}
files = fs.readdirSync(path);
filesLength = files.length;
var perlin = require('perlin').noise.perlin3
var fill = require('ndarray-fill')
var zeros = require('zeros')
var scale = 0.075
var threshold = 0.125
// Untested in 3D, but "theoretically" this should
// work. Using the equivalent 2d getter with the
// continuous-box2d demo works well.
@hughsk
hughsk / index.js
Created September 1, 2013 11:21
requirebin sketch
// Load up the `raf` module.
var raf = require('raf')
// Create the canvas, and add it
// to the page.
var canvas = document.createElement('canvas')
var ctx = canvas.getContext('2d')
var width = 500
var height = 300
@hughsk
hughsk / index.js
Created September 1, 2013 14:13
requirebin sketch
// Load up the `raf` module.
var raf = require('raf')
var controls = require('kb-controls-iframed')({
'W': 'up',
'A': 'left',
'S': 'down',
'D': 'right',
'<up>': 'up',
'<left>': 'left',
'<down>': 'down',
@hughsk
hughsk / index.js
Created September 1, 2013 22:44
requirebin sketch
var observer = require('continuous-observer')
var cave = require('cave-automata-2d')
var fill = require('ndarray-fill')
var zero = require('zeros')
var raf = require('raf')
var canvas = document.createElement('canvas')
var ctx = canvas.getContext('2d')
// Set up the controls, so that we can control