|
Convert Hexadecimal to RGB Syntax: hexToRgb("#454545") or hexToRgb([45, 45, 45]) function hexToRgb(a) { if(typeof a == "string") a = a.match(/\w\w/g); return [ "0x" + a[0] - 0, "0x" + a[1] - 0, "0x" + a[2] - 0 ]; }
Convert Hue/Sat/Lum to Hexadecimal hue: 0-239, sat: 0-240, lum: 0-240Syntax: hslToHex(40, 143, 202) function hslToHex(a, b, c) { var d = 3, e = a / 40 >> 0, f = 0.025 * (a % 40), g = [ e % 5 < 2, e && e < 4, e > 2 ]; g[2 - (1 + e) % 3] -= (e & 1) * 2 * f - f; while(d --) { g[d] *= 255; g[d] -= (g[d] - 127) * (1 - b / 240); g[d] = (g[d] - (c > 120 ? 255 - g[d] : g[d]) * (1 - c / 120) + 0.5 >> 0).toString(16); } return g; }
Convert Hue/Sat/Lum to RGB hue: 0-239, sat: 0-240, lum: 0-240Syntax: hslToRgb(40, 143, 202) function hslToRgb(a, b, c) { var d = 3, e = a / 40 >> 0, f = 0.025 * (a % 40), g = [ e % 5 < 2, e && e < 4, e > 2 ]; g[2 - (1 + e) % 3] -= (e & 1) * 2 * f - f; while(d --) { g[d] *= 255; g[d] -= (g[d] - 127) * (1 - b / 240); g[d] = g[d] - (c > 120 ? 255 - g[d] : g[d]) * (1 - c / 120) + 0.5 >> 0; } return g; }
Convert RGB to Hexadecimal Syntax: rgbToHex([255, 0, 255]) or rgbToHex("rgb(255,0,255)") function rgbToHex(a) { if(typeof a == "string") { a = a.match(/\d+/g); a = [ a.split(",")[0] - 0, a.split(",")[1] - 0, a.split(",")[2] - 0 ]; } return [ (a[0] < 16 ? "0" : "") + a[0].toString(16), (a[1] < 16 ? "0" : "") + a[1].toString(16), (a[2] < 16 ? "0" : "") + a[2].toString(16) ]; } Notes: If you'd like to play around with the hue order in the HSL conversions, replace the first two lines (those preceding the for loop) with this: var d=3,g=[[[255,0,0],1,1],[[255,255,0],0,-1], [[0,255,0],2,1],[[0,255,255],1,-1],[[0,0,255],0,1], [[255,0,255],2,-1]][Math.floor(a/40)]; g[0][g[1]]+=Math.floor(6.375*(a%40))*g[2];g=g[0];And move the [[R,G,B],#,#] elements around as you please. Edit: Forgot to change a function name.
Last Edit: Aug 17, 2010 20:43:20 GMT by Aaron
|
|
|
|
The OS is definitely a good foothold. And you're always free to post any questions. =)
|
|
|
|
D: *gives it back* It's all used 'n' stuff, but it's 'k. I sowwy.
|
|
|
|
oh yes
Jul 28, 2010 9:17:19 GMT
Can't say the names are familiar, but welcome, mate. =) Hope you can make something of your time.
|
|
|
|
Hai, Alex. =D Post more! Or I shall bite j00.
*steals wrighty's kiss and runs away*
|
|
|
|
Probably Castlevania: AoS. But that would've been months back. P=
|
|
|
|
*inserts some comments about wanting to do this without loops and using a single replace() at some point*
|
|
|
|
Syntax: number_format( number, dec, float sep, thousands sep) function number_format(a, b, c, d) { return (a = (a + "").split("."))[0].replace(/\d(?=(.{3})+$)/g, "$&" + (d || ",")) + ((c || ".") + (a[1] || "") + Array(b = b || 0).join(0)).substr(0, b && b + 1); }Edit: Added useless dec parameter and replaced prototype with plain ol' function. Edit: Informed that when dec is 0 on a floating number, the decimal isn't removed. Fixededed. Edit: Updated to add 0s when dec is extended. Also had the thousands and float sep parameters swapped. Edit: Optimized a bit. =)
Last Edit: Aug 25, 2010 4:41:20 GMT by Aaron
|
|
|
|
Just an update to the previous snippet. Some performance enhancements and the ability to recognize unique boolean false values like 0, undefined, and null.
function correlate(a, b) { for(var x in b) { var c = a[x], d = b[x]; if(!c && !d && c === d) continue; if(c && d) { if(typeof c == typeof d) { if(typeof c == "object") { if(correlate(c, d)) continue; } else if(c.toString() == d.toString()) continue; } else if(d.constructor == RegExp && d.test(c.toString())) continue; } return false; } return true; }
|
|
|
|
Description: Object inherits all of reference Object's properties and methods.
Syntax: assign(Object, reference Object)
function assign(a, b) { for(var x in b) if(!a[x] || b[x].constructor != Object) a[x] = b[x]; else assign(a[x], b[x]); return a; }
|
|
|
|
Description: Adds "st," "nd," "rd," "th" suffixes to numbers.
Syntax: (152).suffix()
Number.prototype.suffix = function(a) { return this + [ "th", "st", "nd", "rd" ][((a = this % 10) < 4) * (Math.floor(this % 100 / 10) != 1) * a]; }
|
|
|
|
The ability to not lose a months worth of posts. They're already introducing a new back-up system, I believe. And had been at the time that the harddrive failure occurred (some forums that went down were restored with more recent data).
|
|
|
|
The Code Database is literally behind by one page in resources--discounting whatever was in Submissions at the time. There were only a couple recent requests, though, so that's fortunate. Still a shame to lose all the discussion/contest threads. Really puts everything back.
|
|
|
|
Oooohhh....the Resources/Requests boards are gonna bring me to tears...
|
|
|
|
As Chris said, we don't mean to discourage you. If you're committed to this idea, we'll do what we can to guide you through the experience.
Last Edit: Jun 30, 2010 21:36:36 GMT by Aaron
|
|
|