Skip to content

Instantly share code, notes, and snippets.

View softpunch's full-sized avatar

Ryan softpunch

View GitHub Profile
@softpunch
softpunch / webAudioWrap.js
Created July 2, 2017 03:11
Web Audio boilerplate, variables, and functions
//
// convenient variables and functions to schedule and control Web Audio;
// also useful for controlling other systems using Web Audio's utilities
//
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext();
var baseFreq = 440; // A4, Midi Note #69
var baseTempo = 120; // BPM
var audioOut = audioContext.destination;
@softpunch
softpunch / webMidiWrap.js
Last active July 29, 2017 00:48
WebMIDI vars & functions (WIP)
//
// useful WebMIDI variables and functions
//
//
// Chrome only; no iOS; does *not* incorporate shims
//
// Initialize WebMidi; create dropdown selector for output port
@softpunch
softpunch / timingTempo.css
Last active June 21, 2017 02:52
CSS Variable Timing Units Based on BPM
:root {
--bpm: 120;
/* n4 = quarter note; t4 = quarter-note triplet; m4 = four measures */
--n4: calc(60s / var(--bpm));
--n1: calc(var(--n4) * 4);
--n2: calc(var(--n4) * 2);
--n8: calc(var(--n4) / 2);
--n16: calc(var(--n4) / 4);
@softpunch
softpunch / colorVars.css
Last active June 14, 2022 06:44
CSS Variables For Color Manipulation
/* ----
css custom properties to manipulate color
MIT - 2017 - Soft Punch
https://gist.github.com/softpunch/
set initial "main" color via HSL values.
automatically calculate harmonies and variations of that color with pure css.
harmonies are determined solely by hue.
@softpunch
softpunch / modifyColor.js
Created June 20, 2017 08:28
Lighten, Darken, or Otherwise Modify Colors
// grok'd from TinyColor
// https://bgrins.github.io/TinyColor/
toString: function(format) {
var formatSet = !!format;
format = format || this._format;
var formattedString = false;
_applyModification: function(fn, args) {
@softpunch
softpunch / colorMidi.js
Created June 20, 2017 08:14
Generate Colors from MIDI Notes
// grok'd from MIDI.js
// https://github.com/mudcube/MIDI.js
/*
----------------------------------------------------------
MIDI.Synesthesia : 0.3.1 : 2012-01-06
----------------------------------------------------------
Peacock: “Instruments to perform color-music: Two centuries of technological experimentation,” Leonardo, 21 (1988), 397-406.
Gerstner: Karl Gerstner, The Forms of Color 1986
Klein: Colour-Music: The art of light, London: Crosby Lockwood and Son, 1927.
@softpunch
softpunch / goldenRatio.js
Last active July 3, 2017 19:19
Generate Random Colors Using Golden Ratio
// PSEUDO CODE
// via Herman Tulleken
// http://devmag.org.za/2012/07/29/how-to-choose-colours-procedurally-algorithms/
offset = Random.NextFloat();
for (int i = 0; i < n; i++)
color[i] = gradient.GetColor(offset + (0.618033988749895f * i) % 1);
@softpunch
softpunch / jitterColors.js
Last active July 3, 2017 19:19
Generate Jittered Array of Colors
// PSEUDO CODE
// via Herman Tulleken
// http://devmag.org.za/2012/07/29/how-to-choose-colours-procedurally-algorithms/
maxJitter = 0.5; // any value between 0 and 1
for(int i = 0; i < n; i++)
color[i] = gradient.GetColor(
(i + 0.5 + (2 * Random.NextFloat() - 1) * maxJitter) * intervalSize);
@softpunch
softpunch / colorConvert.js
Last active July 3, 2017 19:20
Color Space Conversions
// grok'd from TinyColor.js
// https://bgrins.github.io/TinyColor/docs/tinycolor.html
//
function rgbToHsl(r, g, b) {
r = bound01(r, 255);
g = bound01(g, 255);
@softpunch
softpunch / arr-stat.js
Created April 28, 2017 07:08 — forked from Daniel-Hug/arr-stat.js
JavaScript statistical functions for arrays: max, min, range, midrange, sum, mean / average, median, modes, variance, standard deviation, mean absolute deviation, z scores
var arr = {
max: function(array) {
return Math.max.apply(null, array);
},
min: function(array) {
return Math.min.apply(null, array);
},
range: function(array) {