Skip to content

Instantly share code, notes, and snippets.

@tophtucker
tophtucker / README.md
Last active October 9, 2015 08:11
Nearest neighbor

nearestNeighbor lets you find the closest neighbor to a given point in a two-dimensional space. Demo: click around up there.

It uses d3's voronoi geometry, but it convenient for more abstract uses where you might not want to draw anything onscreen at all. All it really adds is an algorithm from StackOverflow for finding which polygon generated by the voronoi geometry contains the point. And then it just brute-forces it. It's idiotic. At this point you might as well just brute-force distances to every neighboring point, right? But maybe I can improve it to be non-worthless. "If the polygons form a planar graph with each edge labelled with its two polygon neighbors, then one simple way is to run a semi-infinite ray up from the point until it hits its first edge. Then the relevant containing polygon is one of that edge's neighbors." OK rpi.edu, I don't know how to cast a ray until it hits i

@tophtucker
tophtucker / index.html
Last active October 9, 2015 08:12
Lenticular
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" type="text/css" href="main.css"/>
<body>
@tophtucker
tophtucker / index.html
Last active October 9, 2015 08:15
Lenticular IV
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" type="text/css" href="main.css"/>
<body>
@tophtucker
tophtucker / index.html
Last active October 9, 2015 08:16
Lenticular V
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" type="text/css" href="main.css"/>
<body>
@tophtucker
tophtucker / index.html
Last active October 9, 2015 08:17
Lenticular VI
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" type="text/css" href="main.css"/>
<body>
@tophtucker
tophtucker / README.md
Last active October 9, 2015 08:23
How LIBOR works

Every day, 16 banks say how much it might cost them to borrow in various currencies, for various lengths of time. The four highest and four lowest figures are discarded, and the average of the remaining eight become that day’s Libor. In this toy model of how Libor works, you have total control over how one bank sets its rates, and some random partial influence on other banks, who will tend to follow you. Move your mouse along the axis to set your rate. Read the full story

@tophtucker
tophtucker / README.md
Created October 24, 2015 22:52
Lenticular VII

For devices with accelerometers

@tophtucker
tophtucker / index.html
Last active October 29, 2015 00:25
Text annotations (list)
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" type="text/css" href="main.css"/>
<body class="text-annotation">
@tophtucker
tophtucker / d3-jetpack.js
Last active November 2, 2015 22:48
Timecoder
(function() {
function jetpack(d3) {
d3.selection.prototype.translate = function(xy) {
return this.attr('transform', function(d,i) {
return 'translate('+[typeof xy == 'function' ? xy(d,i) : xy]+')';
});
};
d3.transition.prototype.translate = function(xy) {
@tophtucker
tophtucker / README.md
Created December 1, 2015 02:59
Streaky Text III

Crappy ripoff of FizzyText (seen here, source here, my attempted explanation here).

Improvements:

  • Particles pick up the background color from the underlying canvas, which is hidden here
  • I like when the particles draw the letterforms without just fillTexting as a crutch
  • Refactored improvedNoise.js a bit to return a noise generator, so you can get different seeds or whatever, instead of just a single global noise() function. But that's not really being used yet here...