Skip to content

Instantly share code, notes, and snippets.

View gntlechaos's full-sized avatar
🤠

gentlechaos gntlechaos

🤠
View GitHub Profile
@gntlechaos
gntlechaos / MapMinMaxValue.js
Created April 23, 2020 15:34
Re-maps a number from one range to another.
//This function acts like java Processing's map()
function mapMinMax(value,oldMin,oldMax,newMin, newMax) {
return (newMax-newMin)*(value-oldMin)/(oldMax-oldMin)+newMin;
}
@gntlechaos
gntlechaos / shadeIt.min.js
Last active April 25, 2020 03:20
Function shadeIt(hex,percent) that recieves a hex string (ex: "#ffffff") and a percentage (ex: "0.2") and return a hex string of the color shaded by that percentage. Two external libraries were included and modified https://gist.github.com/mjackson/5311256 and w3color.js ver.1.18 by w3schools.com
function shadeIt(e,t){(s=rgbToHsv((s=new w3color(e,"")).red,s.green,s.blue)).v=s.v-t;var s=hsvToRgb(s);return(s=new w3color(s)).toHexString()}function w3SetColorsByAttribute(){var e,t,s;for(e=document.getElementsByTagName("*"),t=0;t<e.length;t++)(s=e[t].getAttribute("data-w3-color"))&&(e[t].style.backgroundColor=w3color(s).toRgbString())}function rgbToHsv(e,t,s){e/=255,t/=255,s/=255;var r,a,n=Math.max(e,t,s),i=Math.min(e,t,s),h=n,l=n-i;if(a=0==n?0:l/n,n==i)r=0;else{switch(n){case e:r=(t-s)/l+(t<s?6:0);break;case t:r=(s-e)/l+2;break;case s:r=(e-t)/l+4}r/=6}return{h:r,s:a,v:h}}function hsvToRgb(e){var t,s,r,a=e.h,n=e.s,i=e.v,h=Math.floor(6*a),l=6*a-h,o=i*(1-n),u=i*(1-l*n),f=i*(1-(1-l)*n);switch(h%6){case 0:t=i,s=f,r=o;break;case 1:t=u,s=i,r=o;break;case 2:t=o,s=i,r=f;break;case 3:t=o,s=u,r=i;break;case 4:t=f,s=o,r=i;break;case 5:t=i,s=o,r=u}return"rgb("+255*t+","+255*s+","+255*r+")"}!function(){function e(a,i){return this instanceof e?"object"==typeof a?a:(this.attachValues(function(e){var a,i,h,u,f,c,b,d,g,m,y
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.