Skip to content

Instantly share code, notes, and snippets.

View Martin-Pitt's full-sized avatar

Martin "Nexii" Pitt Martin-Pitt

View GitHub Profile
@Martin-Pitt
Martin-Pitt / pan-zoom-touch-and-trackpad.js
Last active December 22, 2023 02:16
Panning and Pinch-Zoom gesture handler for both touchscreens and trackpads; Works really well on a MacBook trackpad
// Target state
var tx = 0;
var ty = 0;
var scale = 1;
function visualiseTargetState() {
box.style.transform = `translate(${tx}px, ${ty}px) scale(${scale})`;
}
module.exports = {
config: {
fontSize: 16,
fontFamily: '"Fira Code", Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace',
cursorColor: 'hsla(215, 100%, 90%, 1)',
cursorShape: 'BEAM',
foregroundColor: 'white',
backgroundColor: 'hsla(0, 0%, 0%, 0)',
borderColor: 'hsl(215, 20%, 20%)',
css: `
@Martin-Pitt
Martin-Pitt / render-bestagons.js
Created July 21, 2023 19:24
How to render clip-path hexagons (bestagons), this function creates the clip-path polygon function values for you, with vmax so it always acts like background cover algorithm
const RowStep = 14.39
const ColumnStep = RowStep * 5/6; // 37.5;
const HexMax = ColumnStep * 4/3;
const HexMin = ColumnStep * 2/3;
const Rows = Math.ceil(100 / RowStep);
const Columns = Math.ceil(100 / ColumnStep);
function renderBestagons(t = 1) {
let polygons = [];
let r = Rows;
@Martin-Pitt
Martin-Pitt / capture.mjs
Created October 29, 2023 11:59
Codepen screen recording
import { promises as fs } from 'fs';
import path from 'path';
import puppeteer from 'puppeteer';
import { PuppeteerScreenRecorder } from 'puppeteer-screen-recorder';
const viewport = {
width: 512,
height: 512,
deviceScaleFactor: 1,
// isMobile: true,
@Martin-Pitt
Martin-Pitt / interpolation.js
Created February 15, 2024 01:16
Rescale Interpolation
/*
More interesting interpolation functions to make life easier.
Rescale is a function which can interpolate a value between two different ranges.
Say you have a number which represents the position of a slider.
The slider has a start and end as well.
You want the slider to control a box between two locations.
So you could do the following: