Skip to content

Instantly share code, notes, and snippets.

View rolyatmax's full-sized avatar

Taylor Baldwin rolyatmax

View GitHub Profile
@rolyatmax
rolyatmax / hooks.html
Last active October 5, 2021 20:05
An simple hooks implementation
<html>
<head>
<title>Hooks implementation</title>
</head>
<body>
<script>
const React = createApplication()
React.render(function MyComponent () {
const [greeting, setGreeting] = React.useState('hello')
const path = require('path')
const fetch = require('node-fetch')
const ProtoBuf = require('protobufjs')
const API_KEY = require('./api-key')
const API_URL = 'https://api-endpoint.mta.info/Dataservice/mtagtfsfeeds/nyct%2F'
const FEED_IDS = [
'gtfs-ace',
@rolyatmax
rolyatmax / decodeBuildingData.js
Created July 22, 2020 14:06
Example logic for encoding indexed triangle data and logic for decoding it in the browser
/*
Binary Data format:
// buildingID int32
// Vertex Offset vec3<int32>
// Vertex ByteSize uint8 (1 or 2 - representing the number of bytes used for the vertex X, Y, & Z)
// Vertex Count uint16
// vertex1 X uint8 or uint16 depending on Vertex ByteSize
// vertex1 Y
// vertex1 Z
// vertex2 X
@rolyatmax
rolyatmax / binary-data-in-browser.js
Created July 21, 2020 14:47
Here are some ideas for getting file sizes and loading times down when loading data in JS
/*
Here are some ideas for how you might get file sizes and load times down when working
with large datasets in the browser.
*/
// 1. Create the TypedArrays you pass to THREE's BufferGeometry on the server and write the binary output to a file:
// in Node
const vertices = new Float32Array([ 0, 0, 0, 1, 1, 1, 1, 0 ])
process.stdout.write(Buffer.from(vertices.buffer))
@rolyatmax
rolyatmax / clip-mesh-with-plane.js
Last active October 29, 2019 15:43
logic for clipping a mesh of triangles with a given plane and capping the newly-formed meshes
const vec3 = require('gl-vec3')
const convexHull = require('convex-hull')
const earcut = require('earcut')
const normal = require('get-plane-normal')
function clipMeshWithPlane (triangles, planeNormal, pointOnPlane) {
const mesh1 = []
const mesh2 = []
const newPoints = []
for (const points of triangles) {
@rolyatmax
rolyatmax / glsl-noise-fns.glsl
Last active October 10, 2019 19:55
GLSL noise fns
// <www.shadertoy.com/view/XsX3zB>
// by Nikita Miropolskiy
/* discontinuous pseudorandom uniformly distributed in [-0.5, +0.5]^3 */
vec3 random3(vec3 c) {
float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));
vec3 r;
r.z = fract(512.0*j);
j *= .125;
r.x = fract(512.0*j);
const { Deck } = require('@deck.gl/core')
const fit = require('canvas-fit')
const mapboxgl = require('mapbox-gl')
module.exports = function setupDeck (mapboxToken, center, zoom, bearing, pitch, mapStyle = 'dark', container = window) {
mapboxgl.accessToken = mapboxToken
const parentElement = container === window ? document.body : container
const mapContainer = parentElement.appendChild(document.createElement('div'))
mapContainer.style.width = '100vw'
@rolyatmax
rolyatmax / README.md
Last active December 15, 2021 03:46
Point Cloud with REGL

Point Cloud with REGL

A small little demo that uses REGL to display point cloud data.

To run:

npm install
npm start
/*
Usage:
const regl = createRegl()
const data = [{position: [2, 5]}, {position: [3, 6]}, {position: [4, 1]}]
const {tick, getStateTexture, getStateIndexes} = createStateTransitioner(regl, data)
// call tick({isBrushing, brushRadius, brushPosition}) on every frame to update the animating values
// call getStateTexture() to retrieve the latest animating values, stored in a texture
// call getStateIndexes() to get a list of vec2 indexes into the animating values texture

Keybase proof

I hereby claim:

  • I am rolyatmax on github.
  • I am taylorbaldwin (https://keybase.io/taylorbaldwin) on keybase.
  • I have a public key whose fingerprint is CE47 D1B8 F780 6573 314C 68FE C193 4BA8 2C85 BD34

To claim this, I am signing this object: