This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on Fisher–Yates shuffle ( https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle ) | |
// and Shuffling an Array in JavaScript ( https://www.kirupa.com/html5/shuffling_array_js.htm ) | |
// returns a new array shuffled | |
Array.prototype.shuffle = function() { | |
let tmpArray = [ ... this ]; // create a copy of original array | |
for( let i = tmpArray.length - 1; i; i -- ) { | |
let randomIndex = ~~( Math.random() * ( i + 1 ) ); | |
[ tmpArray[ i ], tmpArray[ randomIndex ] ] = [ tmpArray[ randomIndex ], tmpArray[ i ] ]; // swap | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/questions/10865025/merge-flatten-an-array-of-arrays-in-javascript/39000004#39000004 | |
const flatten = function(arr, result = []) { | |
for (let i = 0, length = arr.length; i < length; i++) { | |
const value = arr[i]; | |
if (Array.isArray(value)) { | |
flatten(value, result); | |
} else { | |
result.push(value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gif.worker.js 0.2.0 - https://github.com/jnordberg/gif.js | |
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){var NeuQuant=require("./TypedNeuQuant.js");var LZWEncoder=require("./LZWEncoder.js");function ByteArray(){this.page=-1;this.pages=[];this.newPage()}ByteArray.pageSize=4096;ByteArray.charMap={};for(var i=0;i<256;i++)ByteArray.charMap[i]=String.fromCharCode(i);ByteArray.prototype.newPage=function(){this.pages[++this.page]=new Uint8Array(ByteArray.pageSize);this.cursor=0};ByteArray.prototype.getData=function(){var rv="";for(var p=0;p<this.pages.length;p++){for(var i=0;i<ByteArray.p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>Hello WebMIDI</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body> | |
<script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch( 'https://gist.githubusercontent.com/MAKIO135/0f0c45136069ee6e7366afef684f3373/raw/89e9b1600f2ff9331ddc9f12a9f58500d9ad09ae/pi.json' ) | |
.then( resp => resp.json() ) | |
.then( json => { | |
let pi = json.pi | |
let i = 0; | |
setInterval( function run(){ | |
console.clear() | |
console.log( + pi.charAt( i ) ) | |
i++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.count = function( n ) { | |
return this.filter( d => d === n ).length; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvasSketch = require('canvas-sketch') | |
const p5 = require('p5') | |
const LPD8 = require('akai-lpd8') | |
new p5() | |
const settings = { | |
dimensions: [600, 600], | |
p5: true, | |
animate: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/23971798 | |
window.addEventListener('click', () => { | |
toggleFullScreen() | |
}) | |
function isFullScreen() { | |
return (document.fullScreenElement && document.fullScreenElement !== null) | |
|| document.mozFullScreen | |
|| document.webkitIsFullScreen | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hexToRgb = hex => { | |
hex = parseInt(hex[0] != '#' ? hex : hex.substring(1), 16) | |
return [ | |
hex >> 16 & 255, | |
hex >> 8 & 255, | |
hex & 255 | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HexGrid { | |
constructor(firstX, firstY, sizeX, sizeY, hexSize, type) { | |
// type can be either 'flat' or 'pointy' | |
type = type === 'flat' || type === 'pointy' ? type : 'flat' | |
this.width = sizeX | |
this.height = sizeY | |
let h = Math.sqrt(3) * hexSize | |
let w = 2 * hexSize | |
if(type === 'pointy') [w, h] = [h, w] // swap |