Skip to content

Instantly share code, notes, and snippets.

@knightspore
Last active July 28, 2020 09:57
Show Gist options
  • Save knightspore/b3f69137d86dd19baa0b4c5cb4cf4d3a to your computer and use it in GitHub Desktop.
Save knightspore/b3f69137d86dd19baa0b4c5cb4cf4d3a to your computer and use it in GitHub Desktop.
This sript is for generating hex linear gradients at random with vanilla Javascript. Just create a blank index.html file and add a button with the id "colorButton" and start watching. When you see a gradient you like, check the console to grab its details (it's attached to the <body> element)
var lright = ['left', 'right'];
var updown = ['top', 'bottom'];
var colorButton = document.getElementById('colorButton');
colorButton.onmousedown = function () {
var gradA = "#" + ((1 << 24) * Math.random() | 0).toString(16);
var gradB = "#" + ((1 << 24) * Math.random() | 0).toString(16);
var random = Math.round(Math.random(2));
var random2 = Math.round(Math.random(2));
document.body.style.backgroundImage = '-moz-linear-gradient(to ' + updown[random] + ' ' + lright[random2] + ', ' + gradA + ', ' + gradB + ')'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment