Skip to content

Instantly share code, notes, and snippets.

@hughsk
hughsk / index.html
Last active September 9, 2017 21:16
Adafruit +p5.js Turn Controls :)
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
const unindex = require('unindex-mesh')
const normals = require('face-normals')
const glsl = require('glslify')
const regl = require('regl')({ extensions: ['ANGLE_instanced_arrays'] })
const cube = unindex(require('primitive-cube')())
const camera = require('regl-camera')(regl)
const { translations, scales } = generateSplitGrid()
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 / 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
@hughsk
hughsk / ctx.js
Created February 16, 2014 22:39 — forked from NHQ/ctx.js
// the base module
module.exports = function(canvas){
if('string' == typeof canvas) canvas = dcoument.getElementById(canvas)
touchdown.start(canvas)
var ctx = window.ctx = canvas.getContext('2d')
var pen = basic(ctx)
ctx.translate(0.5, 0.5)
ctx.lineWidth = 10
ctx.globalCompositeOperation = 'destination-over';
@hughsk
hughsk / index.js
Created September 4, 2013 10:42
requirebin sketch
// This version is unminified
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')
@hughsk
hughsk / index.js
Created September 3, 2013 11:55
requirebin sketch
var render = require('ndarray-text')
var zeros = require('zeros')
var cave = require('cave-automata-2d')
var pre = document.createElement('pre')
// Create an empty ndarray,
// 60 units wide and
// 18 units high
var array = zeros([60, 18])
@hughsk
hughsk / index.js
Created September 3, 2013 11:46
requirebin sketch
var render = require('ndarray-canvas')
var zeros = require('zeros')
var cave = require('cave-automata-2d')
var fill = require('ndarray-fill')
var canvas = document.createElement('canvas')
// Create an empty ndarray,
// 60 units wide and
// 18 units high
var array = zeros([500, 300])
@hughsk
hughsk / index.js
Created September 1, 2013 23:37
requirebin sketch
var observer = require('continuous-observer')
var topdown = require('topdown-physics')
var cave = require('cave-automata-2d')
var fill = require('ndarray-fill')
var aabb = require('aabb-2d')
var zero = require('zeros')
var raf = require('raf')
var canvas = document.createElement('canvas')
var ctx = canvas.getContext('2d')