Skip to content

Instantly share code, notes, and snippets.

View av01d's full-sized avatar

Arjan Haverkamp av01d

View GitHub Profile
@av01d
av01d / ColorSteps.js
Last active February 27, 2024 15:42
Javascript calculate color steps (gradient) between two colors
const ColorSteps = (() => {
/**
* Convert any color string to an [r,g,b,a] array.
* @author Arjan Haverkamp (arjan-at-avoid-dot-org)
* @param {string} color Any color. F.e.: 'red', '#f0f', '#ff00ff', 'rgb(x,y,x)', 'rgba(r,g,b,a)', 'hsl(180, 50%, 50%)'
* @returns {array} [r,g,b,a] array. Caution: returns [0,0,0,0] for invalid color.
* @see https://gist.github.com/av01d/8f068dd43447b475dec4aad0a6107288
*/
const colorValues = color => {
@av01d
av01d / keypress.js
Created March 29, 2024 09:51
Javascript keypress handler
const commands = {
'ctrl+z' => History.undo,
'ctrl+y' => History.redo,
'escape': () => { alert('esc'); }
};
$(window).on('keydown', event => {
let label = '';
if (event.ctrlKey) { label += 'ctrl+'; }
if (event.altKey) { label += 'alt+'; }