|
Don't know why I made this...boredom I guess...it's just a Color object that darkens/brightens the hex color you provide. var _valid = "0123456789ABCDEF"; function Color() { this.hexCode = arguments[0].toUpperCase(); this.hexContainer = []; var i = 0; while(this.hexContainer.length < this.hexCode.length) { this.hexContainer.push(parseInt(_valid.indexOf(this.hexCode.charAt(i)))); i ++; } } Color.prototype.convertHex = function() { var i = 0; while(i < this.hexContainer.length) { this.hexContainer = parseInt(_valid.indexOf(this.hexCode.charAt(i))); i ++; } } Color.prototype.brighten = function() { var i = 0; this.hexCode = ""; while(i < this.hexContainer.length) { this.hexCode += _valid.charAt((this.hexContainer + arguments[0] <= 15 ? this.hexContainer + arguments[0] : 15)); i ++; } this.convertHex(); return this.hexCode; } Color.prototype.darken = function() { var i = 0; this.hexCode = ""; while(i < this.hexContainer.length) { this.hexCode += _valid.charAt((this.hexContainer + arguments[0] >= 0 ? this.hexContainer - arguments[0] : 0)); i ++; } this.convertHex(); return this.hexCode; }
In use: var i = 0, myText = "Hello there!"; var myHex = new Color("001100"); function writeToBody() { if(i < myText.length) { document.write("<font color='#" + myHex.brighten(1) + "'>" + myText.charAt(i) + "</font>"); i ++; writeToBody(); } } writeToBody();
Last Edit: Aug 8, 2006 16:17:58 GMT by Aaron
|
|
|
|
Wouldn't the "writeToBody()" function create an infinite loop?  Very nicely done though Der... I really need to look into the abilities of parseInt more... specially the bases.
|
|
|
|
|
The function only reiterates when variable i is less than the character length of myText.
Last Edit: Aug 8, 2006 16:11:08 GMT by Aaron
|
|
|