Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
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

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Wouldn't the "writeToBody()" function create an infinite loop? :P

Very nicely done though Der... I really need to look into the abilities of parseInt more... specially the bases.

Aaron

Aaron Avatar
Bad Wolf

****
Dedicated Studio Member

859


November 2006
The function only reiterates when variable i is less than the character length of myText. :P


Last Edit: Aug 8, 2006 16:11:08 GMT by Aaron

newBookmarkLockedFalling