Skip to content

Instantly share code, notes, and snippets.

View GrantCuster's full-sized avatar

grant GrantCuster

View GitHub Profile
@GrantCuster
GrantCuster / README.md
Last active January 10, 2023 08:55
Three.js with D3-style Pan and Zoom

This example recreates the zoom and pan behavior from the Pan and Zoom II D3 example. I'm using Three.js in a 2D data-visualization project because I'm hoping its WebGL render can handle more points than canvas. I had a hard time finding an example that zoomed and panned like I'm used to, so I made this.

This stack overflow answer by WesleyJones and the getCurrentScale function from anvaka's three.map.controls code was essential to me actually getting this working.

The scroll zoom is currently inverted compared to the D3 example, I'd like to match it but apparently there's some easing happening in the D3 scroll behavior that slows things down as you zoom in. That makes it feel weird if I just invert the zoom.

If you have suggestions on how to make this better, message me on [Twitter](htt

@GrantCuster
GrantCuster / index.html
Last active September 28, 2017 02:27
Three.js mouse-directed zoom
<!DOCTYPE html>
<meta charset="utf-8">
<canvas width="960" height="500"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/87/three.min.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var canvas = d3.select("canvas"),
context = canvas.node().getContext("2d"),
width = canvas.property("width"),
@GrantCuster
GrantCuster / .block
Created March 20, 2017 22:33 — forked from pbeshai/.block
Animate thousands of points with canvas and D3
license: mit
height: 620
border: no
#!/usr/bin/python3
import numpy as np
import os
import ujson
from pprint import pprint as pp
from aylienapiclient import textapi
import time
aylien_client = textapi.Client(<id>, <key>)