473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Basic "shiny" link mouseover script produces non-fatal errors.

Hey everyone, as I have been by far pleased with some of the top helpers on this forum, I have decided to send another one your way.

Even though I am personally having minimal issues with this script I have developed, I am wondering if someone could fix my little bug with it.

This script runs perfectly fine, except once in a while, the color changing will "pause" because (according to Mozilla Firefox 3's error console) it is putting out invalid color codes. It only does a short burst of 8 invalid color codes (on average) and then gets back in a normal range.

I feel I'm missing something, maybe a fresh pair of eyes can spot it out.

Live Demo Here

Expand|Select|Wrap|Line Numbers
  1. // JavaScript Document
  2.  
  3. var shinylink = (false);
  4. var custom_ids = (0);
  5.  
  6. var maximum = (64); // This is the maximum any color value can reach.
  7. var minimum = (0); // This is the minimum any color value can reach.
  8.  
  9. var objects = (0);
  10. var active_object = (false);
  11. var active_color = (false);
  12.  
  13. var using_objects = new Array ();
  14. var restore_objects = new Array ();
  15. var object_references = new Array ();
  16.  
  17. function d2h(d)
  18.     {
  19.         var h = d.toString(16);
  20.         if(h.length == (1))
  21.             {
  22.                 h = "0"+h;
  23.             }
  24.         return (h);
  25.     }
  26. function h2d(h)
  27.     {
  28.         var d = parseInt(h, (16));
  29.         return (d);
  30.     }
  31. function split_color (color)
  32.     {
  33.         var acceptable = '0123456789abcdefABCDEF';
  34.         var string = '';
  35.  
  36.  
  37.         for (var i = (0); i < color.length; i++)
  38.             {
  39.                 if (acceptable.indexOf (color.charAt (i)) > (-1))
  40.                     {
  41.                         string += color.charAt (i);
  42.                     }
  43.             }
  44.  
  45.         var red = string.charAt (0) + string.charAt (1);
  46.         var green = string.charAt (2) + string.charAt (3);
  47.         var blue = string.charAt (4) + string.charAt (5);
  48.  
  49.         return (Array (h2d (red), h2d (green), h2d (blue)));
  50.     }
  51.  
  52. function shinylink_initiate (object, color)
  53.     {
  54.         if (window.shinylink == (false))
  55.             {
  56.                 var links = document.getElementsByTagName ('a');
  57.                 for (var i = (0); i < links.length; i++)
  58.                     {
  59.                         if (links[window.custom_ids++].id == '')
  60.                             {
  61.                                 links[i].id = 'shinylink_' + window.custom_ids;
  62.                             }
  63.                     }
  64.             }
  65.         if (object.id == '')
  66.             {
  67.                 object.id = 'shinylink_' + window.custom_ids++;
  68.             }
  69.         var number = window.objects++;
  70.         var color_array = split_color (color);
  71.  
  72.         if (typeof (window.using_objects[number]) == 'undefined')
  73.             {
  74.                 window.using_objects[number] = (false);
  75.                 window.object_references[number] = object.id;
  76.             }
  77.  
  78.         object.onmouseover = function ()
  79.             {
  80.                 shinylink_mouseover (number, color_array);
  81.             }
  82.         object.onmouseout = function ()
  83.             {
  84.                 shinylink_mouseout (number, color_array);
  85.             }
  86.  
  87.         window.shinylink = (true);
  88.  
  89.         shinylink_mouseover (number, color_array);
  90.     }
  91. function shinylink_mouseover (id, color)
  92.     {
  93.         window.active_object = id;
  94.         window.active_color = (false);
  95.  
  96.         shinylink_scan (id, color);
  97.     }
  98. function shinylink_mouseout (id, color)
  99.     {
  100.         if (window.active_object == id)
  101.             {
  102.                 window.active_object = (false);
  103.                 window.active_color = (false);
  104.             }
  105.  
  106.         shinylink_restore (id, color);
  107.     }
  108. function shinylink_scan (id, color)
  109.     {
  110.         var input_color = Array (
  111.             Math.round ((color[0] + (1)) / (4)),
  112.             Math.round ((color[1] + (1)) / (4)),
  113.             Math.round ((color[2] + (1)) / (4))
  114.         );
  115.  
  116.         if (window.active_object === id)
  117.             {
  118.                 var current = window.using_objects[id] != (false) ? window.using_objects[id] : input_color;
  119.  
  120.                 if ((current[0] == window.active_color[0] && current[1] == window.active_color[1] && current[2] == window.active_color[2]) || window.active_color == (false))
  121.                     {
  122.                         if (window.active_color == (false))
  123.                             {
  124.                                 window.active_color = new Array ();
  125.                             }
  126.  
  127.                         // Pick a random color.
  128.  
  129.                         // Pick which colors will change.
  130.                         var change_red = Math.round (Math.random ());
  131.                         var change_green = Math.round (Math.random ());
  132.                         var change_blue = Math.round (Math.random ());
  133.  
  134.                         if (change_red == (0) && change_green == (0) && change_blue == (0))
  135.                             {
  136.                                 var change_rgb = Math.round (Math.random () * (2));
  137.  
  138.                                 change_red = change_rgb == (0) ? (1) : (0);
  139.                                 change_green = change_rgb == (1) ? (1) : (0);
  140.                                 change_blue = change_rgb == (2) ? (1) : (0);
  141.                             }
  142.  
  143.                         if (change_red == (1))
  144.                             {
  145.                                 var direction_red = current[0] <= window.minimum ? (1) : current[0] >= window.maximum ? (0) : Math.round (Math.random ());
  146.  
  147.                                 var maximum_distance_red = direction_red == (0) ? current[0] : (window.maximum - current[0]);
  148.  
  149.                                 // Increase chances of picking the highest number possible.
  150.                                 // Decrease chances of picking the smallest number possible.
  151.                                 var random_distance_chance_red = (maximum_distance_red * maximum_distance_red);
  152.                                 var random_distance_pick_red = Math.round (Math.random () * random_distance_chance_red);
  153.  
  154.                                 var i_red = (1);
  155.                                 while (random_distance_pick_red >= (i_red * i_red))
  156.                                     {
  157.                                         i_red++;
  158.                                     }
  159.                                 var distance_red = (i_red - (1));
  160.  
  161.                                 window.active_color[0] = direction_red == (0) ? (current[0] - distance_red) : (current[0] + distance_red);
  162.                             }
  163.                         else
  164.                             {
  165.                                 window.active_color[0] = current[0];
  166.                             }
  167.  
  168.                         if (change_green == (1))
  169.                             {
  170.                                 var direction_green = current[1] <= window.minimum ? (1) : current[1] >= window.maximum ? (0) : Math.round (Math.random ());
  171.  
  172.                                 var maximum_distance_green = direction_green == (0) ? current[1] : (window.maximum - current[1]);
  173.  
  174.                                 // Increase chances of picking the highest number possible.
  175.                                 // Decrease chances of picking the smallest number possible.
  176.                                 var random_distance_chance_green = (maximum_distance_green * maximum_distance_green);
  177.                                 var random_distance_pick_green = Math.round (Math.random () * random_distance_chance_green);
  178.  
  179.                                 var i_green = (1);
  180.                                 while (random_distance_pick_green >= (i_green * i_green))
  181.                                     {
  182.                                         i_green++;
  183.                                     }
  184.                                 var distance_green = (i_green - (1));
  185.  
  186.                                 window.active_color[1] = direction_green == (0) ? (current[1] - distance_green) : (current[1] + distance_green);
  187.                             }
  188.                         else
  189.                             {
  190.                                 window.active_color[1] = current[1];
  191.                             }
  192.  
  193.                         if (change_blue == (1))
  194.                             {
  195.                                 var direction_blue = current[2] <= window.minimum ? (1) : current[2] >= window.maximum ? (0) : Math.round (Math.random ());
  196.  
  197.                                 var maximum_distance_blue = direction_blue == (0) ? current[2] : (window.maximum - current[2]);
  198.  
  199.                                 // Increase chances of picking the highest number possible.
  200.                                 // Decrease chances of picking the smallest number possible.
  201.                                 var random_distance_chance_blue = (maximum_distance_blue * maximum_distance_blue);
  202.                                 var random_distance_pick_blue = Math.round (Math.random () * random_distance_chance_blue);
  203.  
  204.                                 var i_blue = (1);
  205.                                 while (random_distance_pick_blue >= (i_blue * i_blue))
  206.                                     {
  207.                                         i_blue++;
  208.                                     }
  209.                                 var distance_blue = (i_blue - (1));
  210.  
  211.                                 window.active_color[2] = direction_blue == (0) ? (current[2] - distance_blue) : (current[2] + distance_blue);
  212.                             }
  213.                         else
  214.                             {
  215.                                 window.active_color[2] = current[2];
  216.                             }
  217.                     }
  218.  
  219.                 // Transition one color maximum per channel.
  220.                 var new_color = new Array ();
  221.                 var color_string = '#';
  222.                 for (var i = (0); i < window.active_color.length; i++)
  223.                     {
  224.                         new_color[i] = current[i] < window.active_color[i] ? (current[i] + (1)) : current[i] > window.active_color[i] ? (current[i] - (1)) : current[i];
  225.                         color_string += d2h (new_color[i] != (0) ? ((new_color[i] * (4)) - (1)) : (0));
  226.                     }
  227.  
  228.                 window.using_objects[id] = new_color;
  229.                 window.restore_objects[id] = Array (
  230.                     ((new_color[0] * (4)) - (1)),
  231.                     ((new_color[1] * (4)) - (1)),
  232.                     ((new_color[2] * (4)) - (1))
  233.                 );
  234.  
  235.                 document.getElementById(window.object_references[id]).style.color = color_string;
  236.  
  237.                 setTimeout ('shinylink_scan (' + id + ', ' + color + '); ', (5));
  238.             }
  239.     }
  240. function shinylink_restore (id, color)
  241.     {
  242.         var current = window.using_objects[id] != (false) ? window.restore_objects[id] : color;
  243.         if ((current[0] != color[0] || current[1] != color[1] || current[2] != color[2]) && window.active_object !== id)
  244.             {
  245.                 // Transition one color maximum per channel.
  246.                 var new_color = new Array ();
  247.                 var color_string = '#';
  248.                 for (var i = (0); i < color.length; i++)
  249.                     {
  250.                         new_color[i] = current[i] < color[i] ? (current[i] + (1)) : current[i] > color[i] ? (current[i] - (1)) : current[i];
  251.                         color_string += d2h (new_color[i]);
  252.                     }
  253.                 window.restore_objects[id] = new_color;
  254.                 window.using_objects[id] = Array (
  255.                     ((new_color[0] + (1)) / (4)),
  256.                     ((new_color[1] + (1)) / (4)),
  257.                     ((new_color[2] + (1)) / (4))
  258.                 );
  259.  
  260.                 document.getElementById(window.object_references[id]).style.color = color_string;
  261.  
  262.                 setTimeout ('shinylink_restore (' + id + ', Array (' + color[0] + ', ' + color[1] + ', ' + color[2] + ')); ', (5));
  263.             }
  264.     }
Aug 5 '08 #1
11 1812
I just realized I had an old thread going for this same script, but that was with a completely different beginner issue (I was still learning how to assign an object in the page an event function on the fly, which I accomplished in this), this is much more advanced, and complete version of the code, which is having one little issue that I think is related to some addition or multiplication that I forgot to apply to the numbers somewhere in the code. I thought I figured it out in my head last night while I was away from the computer, (and yet again) came back to it only to realize I didn't know what I was thinking about.

This is the original:
http://bytes.com/forum/thread748828.html
Aug 5 '08 #2
acoder
16,027 Expert Mod 8TB
I don't know if you've modified it since, but I don't see any errors.
Aug 5 '08 #3
There is no "error" I guess I should say, but the problem is that it comes up with an incorrect color code. I feel my math is off somewhere... It works, but just mouseover the link on the page, keep the JavaScript error console up (in Mozilla or Opera seem to have good ones), and just wait, eventually you will see a burst of invalid color codes produced by this script.

I guess they are more of warnings then errors, but I'm trying to rid my script of all bugs.

This is the slightly modified code I made after I finished the page demo I provided to you. I only really fixed the spelling errors in the names of the functions, and then stuck it in a .js file so I could easily use it on my forums.

Anyone willing to put a bit of effort into checking this out has my gratitude. :)

Oh, and acoder, thank you for your help in some of my previous questions.
Aug 5 '08 #4
acoder
16,027 Expert Mod 8TB
Can you post the warning/error messages that you see and which line no. it points to.
Aug 6 '08 #5
document.getElementById(window.object_references[id]).style.color = color_string;

On line 235.

It has nothing to do with that line having the actual error, the error is within the shinylink_scan function.

Because it is setting color_string to an invalid color code which again, is probably because I messed up on my addition somehow.

I'm just wondering if anyone here wants to take the time to sit down and really look at the function to point out where I may have a calculation that can cause the number that is converted into hex code to be over 255, or under 0.
Aug 8 '08 #6
I could put in a simple check system that reduces it to that maximum or minimum value, but I'd prefer the numbers come out correct in the first place.
Aug 8 '08 #7
acoder
16,027 Expert Mod 8TB
Have you tried using a debugger? A useful one is Firebug for Firefox.
Aug 8 '08 #8
FLEB
30
Not a solution, but a possible strategy: Instead of mucking around with hex conversions, it might just be simpler to have it give the object its color in "rgb(r,g,b)" format. It's (IIRC) cross-browser friendly, and the r,g, and b values are just decimals from 0 to 255.
Aug 8 '08 #9
Thanks for the tip, acoder, and FLEB. I didn't think about using the rgb CSS value initially since I have been so used to using #RRGGBB format.I will give it a try, see if they help me get the numbers I want.
Aug 9 '08 #10
I believe I have fixed it, but I'm not too sure, I will have to let it run for an excessive amount of time to test it completely, but for the most part, there are no random bursts of errors. :)

I modified 6 lines total:
I changed the assignment of window.restore_objects[id] on line 246, and window.using_objects[id] on line 366; compared to window.restore_objects[id] on line 229, and window.using_objects[id] on line 254 in the old one.

A completed preview lies here:
http://preview.moltx.name/shineylink/index.php5

Expand|Select|Wrap|Line Numbers
  1. // JavaScript Document
  2.  
  3. // Debugging.
  4. var shutdown = (false);
  5.  
  6. var shinylink = (false);
  7. var custom_ids = (0);
  8.  
  9. var maximum = (64); // This is the maximum any color value can reach.
  10. var minimum = (0); // This is the minimum any color value can reach.
  11.  
  12. var objects = (0);
  13. var active_object = (false);
  14. var active_color = (false);
  15.  
  16. var using_objects = new Array ();
  17. var restore_objects = new Array ();
  18. var object_references = new Array ();
  19.  
  20. function d2h(d)
  21.     {
  22.         if (window.shutdown) {return;}
  23.         var h = d.toString(16);
  24.         if(h.length == (1))
  25.             {
  26.                 h = "0"+h;
  27.             }
  28.         return (h);
  29.     }
  30. function h2d(h)
  31.     {
  32.         if (window.shutdown) {return;}
  33.         var d = parseInt(h, (16));
  34.         return (d);
  35.     }
  36. function split_color (color)
  37.     {
  38.         if (window.shutdown) {return;}
  39.         var acceptable = '0123456789abcdefABCDEF';
  40.         var string = '';
  41.  
  42.  
  43.         for (var i = (0); i < color.length; i++)
  44.             {
  45.                 if (acceptable.indexOf (color.charAt (i)) > (-1))
  46.                     {
  47.                         string += color.charAt (i);
  48.                     }
  49.             }
  50.  
  51.         var red = string.charAt (0) + string.charAt (1);
  52.         var green = string.charAt (2) + string.charAt (3);
  53.         var blue = string.charAt (4) + string.charAt (5);
  54.  
  55.         var color_array = new Array (
  56.             h2d (red),
  57.             h2d (green),
  58.             h2d (blue)
  59.         );
  60.  
  61.         return (color_array);
  62.     }
  63.  
  64. function shinylink_initiate (object, color)
  65.     {
  66.         if (window.shutdown) {return;}
  67.         if (window.shinylink == (false))
  68.             {
  69.                 var links = document.getElementsByTagName ('a');
  70.                 for (var i = (0); i < links.length; i++)
  71.                     {
  72.                         if (links[window.custom_ids++].id == '')
  73.                             {
  74.                                 links[i].id = 'shinylink_' + window.custom_ids;
  75.                             }
  76.                     }
  77.             }
  78.         if (object.id == '')
  79.             {
  80.                 object.id = 'shinylink_' + window.custom_ids++;
  81.             }
  82.         var number = window.objects++;
  83.         var color_array = split_color (color);
  84.  
  85.         if (typeof (window.using_objects[number]) == 'undefined')
  86.             {
  87.                 window.using_objects[number] = (false);
  88.                 window.object_references[number] = object.id;
  89.             }
  90.  
  91.         object.onmouseover = function ()
  92.             {
  93.                 shinylink_mouseover (number, color_array);
  94.             }
  95.         object.onmouseout = function ()
  96.             {
  97.                 shinylink_mouseout (number, color_array);
  98.             }
  99.  
  100.         window.shinylink = (true);
  101.  
  102.         shinylink_mouseover (number, color_array);
  103.     }
  104. function shinylink_mouseover (id, color)
  105.     {
  106.         if (window.shutdown) {return;}
  107.         window.active_object = id;
  108.         window.active_color = (false);
  109.  
  110.         shinylink_scan (id, color);
  111.     }
  112. function shinylink_mouseout (id, color)
  113.     {
  114.         if (window.shutdown) {return;}
  115.         if (window.active_object == id)
  116.             {
  117.                 window.active_object = (false);
  118.                 window.active_color = (false);
  119.             }
  120.  
  121.         shinylink_restore (id, color);
  122.     }
  123. function shinylink_scan (id, color)
  124.     {
  125.         if (window.shutdown) {return;}
  126.         var input_color = Array (
  127.             Math.round ((color[0] + (1)) / (4)),
  128.             Math.round ((color[1] + (1)) / (4)),
  129.             Math.round ((color[2] + (1)) / (4))
  130.         );
  131.  
  132.         if (window.active_object === id)
  133.             {
  134.                 var current = window.using_objects[id] != (false) ? window.using_objects[id] : input_color;
  135.  
  136.                 if ((current[0] == window.active_color[0] && current[1] == window.active_color[1] && current[2] == window.active_color[2]) || window.active_color == (false))
  137.                     {
  138.                         if (window.active_color == (false))
  139.                             {
  140.                                 window.active_color = new Array ();
  141.                             }
  142.  
  143.                         // Pick a random color.
  144.  
  145.                         // Pick which colors will change.
  146.                         var change_red = Math.round (Math.random ());
  147.                         var change_green = Math.round (Math.random ());
  148.                         var change_blue = Math.round (Math.random ());
  149.  
  150.                         if (change_red == (0) && change_green == (0) && change_blue == (0))
  151.                             {
  152.                                 var change_rgb = Math.round (Math.random () * (2));
  153.  
  154.                                 change_red = change_rgb == (0) ? (1) : (0);
  155.                                 change_green = change_rgb == (1) ? (1) : (0);
  156.                                 change_blue = change_rgb == (2) ? (1) : (0);
  157.                             }
  158.  
  159.                         if (change_red == (1))
  160.                             {
  161.                                 var direction_red = current[0] <= window.minimum ? (1) : current[0] >= window.maximum ? (0) : Math.round (Math.random ());
  162.  
  163.                                 var maximum_distance_red = direction_red == (0) ? current[0] : (window.maximum - current[0]);
  164.  
  165.                                 // Increase chances of picking the highest number possible.
  166.                                 // Decrease chances of picking the smallest number possible.
  167.                                 var random_distance_chance_red = (maximum_distance_red * maximum_distance_red);
  168.                                 var random_distance_pick_red = Math.round (Math.random () * random_distance_chance_red);
  169.  
  170.                                 var i_red = (1);
  171.                                 while (random_distance_pick_red >= (i_red * i_red))
  172.                                     {
  173.                                         i_red++;
  174.                                     }
  175.                                 var distance_red = (i_red - (1));
  176.  
  177.                                 window.active_color[0] = direction_red == (0) ? (current[0] - distance_red) : (current[0] + distance_red);
  178.                             }
  179.                         else
  180.                             {
  181.                                 window.active_color[0] = current[0];
  182.                             }
  183.  
  184.                         if (change_green == (1))
  185.                             {
  186.                                 var direction_green = current[1] <= window.minimum ? (1) : current[1] >= window.maximum ? (0) : Math.round (Math.random ());
  187.  
  188.                                 var maximum_distance_green = direction_green == (0) ? current[1] : (window.maximum - current[1]);
  189.  
  190.                                 // Increase chances of picking the highest number possible.
  191.                                 // Decrease chances of picking the smallest number possible.
  192.                                 var random_distance_chance_green = (maximum_distance_green * maximum_distance_green);
  193.                                 var random_distance_pick_green = Math.round (Math.random () * random_distance_chance_green);
  194.  
  195.                                 var i_green = (1);
  196.                                 while (random_distance_pick_green >= (i_green * i_green))
  197.                                     {
  198.                                         i_green++;
  199.                                     }
  200.                                 var distance_green = (i_green - (1));
  201.  
  202.                                 window.active_color[1] = direction_green == (0) ? (current[1] - distance_green) : (current[1] + distance_green);
  203.                             }
  204.                         else
  205.                             {
  206.                                 window.active_color[1] = current[1];
  207.                             }
  208.  
  209.                         if (change_blue == (1))
  210.                             {
  211.                                 var direction_blue = current[2] <= window.minimum ? (1) : current[2] >= window.maximum ? (0) : Math.round (Math.random ());
  212.  
  213.                                 var maximum_distance_blue = direction_blue == (0) ? current[2] : (window.maximum - current[2]);
  214.  
  215.                                 // Increase chances of picking the highest number possible.
  216.                                 // Decrease chances of picking the smallest number possible.
  217.                                 var random_distance_chance_blue = (maximum_distance_blue * maximum_distance_blue);
  218.                                 var random_distance_pick_blue = Math.round (Math.random () * random_distance_chance_blue);
  219.  
  220.                                 var i_blue = (1);
  221.                                 while (random_distance_pick_blue >= (i_blue * i_blue))
  222.                                     {
  223.                                         i_blue++;
  224.                                     }
  225.                                 var distance_blue = (i_blue - (1));
  226.  
  227.                                 window.active_color[2] = direction_blue == (0) ? (current[2] - distance_blue) : (current[2] + distance_blue);
  228.                             }
  229.                         else
  230.                             {
  231.                                 window.active_color[2] = current[2];
  232.                             }
  233.                     }
  234.  
  235.                 // Transition one color maximum per channel.
  236.                 var new_color = new Array ();
  237.                 var color_string = 'rgb(';
  238.                 for (var i = (0); i < window.active_color.length; i++)
  239.                     {
  240.                         new_color[i] = current[i] < window.active_color[i] ? (current[i] + (1)) : current[i] > window.active_color[i] ? (current[i] - (1)) : current[i];
  241.                         color_string += (new_color[i] != (0) ? ((new_color[i] * (4)) - (1)) : (0)) + (i != (2) ? ', ' : '');
  242.                     }
  243.                 color_string += ')';
  244.  
  245.                 window.using_objects[id] = new_color;
  246.                 window.restore_objects[id] = Array (
  247.                     new_color[0] != (0) ? ((new_color[0] * (4)) - (1)) : (0),
  248.                     new_color[1] != (0) ? ((new_color[1] * (4)) - (1)) : (0),
  249.                     new_color[2] != (0) ? ((new_color[2] * (4)) - (1)) : (0)
  250.                 );
  251.  
  252.                 // Debugging!
  253.                 if (window.restore_objects[id][0] > (255) || window.restore_objects[id][1] > (255) || window.restore_objects[id][2] > (255) ||
  254.                     window.restore_objects[id][0] < (0) || window.restore_objects[id][1] < (0) || window.restore_objects[id][2] < (0) ||
  255.                     window.active_color[0] > (64) || window.active_color[1] > (64) || window.active_color[2] > (64) ||
  256.                     window.active_color[0] < (0) || window.active_color[1] < (0) || window.active_color[2] < (0))
  257.                     {
  258.                         window.shutdown = (true);
  259.  
  260.                         // Dump every last single variable to view.
  261.                         // Window Variables:
  262.                         var string = 'window.shutdown = '+window.shutdown+'<br />';
  263.                         string += 'window.shinylink = '+window.shinylink+'<br />';
  264.                         string += 'window.maximum = '+window.maximum+'<br />';
  265.                         string += 'window.minimum = '+window.minimum+'<br />';
  266.                         string += 'window.objects = '+window.objects+'<br />';
  267.                         string += 'window.active_color = '+window.active_color+'<br />';
  268.                         string += 'window.active_color[0] = '+window.active_color[0]+'<br />';
  269.                         string += 'window.active_color[1] = '+window.active_color[1]+'<br />';
  270.                         string += 'window.active_color[2] = '+window.active_color[2]+'<br />';
  271.                         string += 'window.active_object = '+window.active_object+'<br />';
  272.                         string += 'window.using_objects = '+window.using_objects+'<br />';
  273.                         for (var i = (0); i < window.using_objects.length; i++)
  274.                             {
  275.                                 string += 'window.using_objects['+i+'] = '+window.using_objects[i]+'<br />';
  276.                                 string += 'window.using_objects['+i+'][0] = '+window.using_objects[i][0]+'<br />';
  277.                                 string += 'window.using_objects['+i+'][1] = '+window.using_objects[i][1]+'<br />';
  278.                                 string += 'window.using_objects['+i+'][2] = '+window.using_objects[i][2]+'<br />';
  279.                             }
  280.                         string += 'window.restore_objects = '+window.restore_objects+'<br />';
  281.                         for (var i = (0); i < window.restore_objects.length; i++)
  282.                             {
  283.                                 string += 'window.restore_objects['+i+'] = '+window.restore_objects[i]+'<br />';
  284.                                 string += 'window.restore_objects['+i+'][0] = '+window.restore_objects[i][0]+'<br />';
  285.                                 string += 'window.restore_objects['+i+'][1] = '+window.restore_objects[i][1]+'<br />';
  286.                                 string += 'window.restore_objects['+i+'][2] = '+window.restore_objects[i][2]+'<br />';
  287.                             }
  288.                         string += 'window.object_references = '+window.object_references+'<br />';
  289.                         for (var i = (0); i < window.object_references.length; i++)
  290.                             {
  291.                                 string += 'window.object_references['+i+'] = '+window.object_references[i]+'<br />';
  292.                             }
  293.  
  294.                         // Starting Variables:
  295.                         string += 'id = '+id+'<br />';
  296.                         string += 'color = '+color+'<br />';
  297.                         string += 'color[0] = '+color[0]+'<br />';
  298.                         string += 'color[1] = '+color[1]+'<br />';
  299.                         string += 'color[2] = '+color[2]+'<br />';
  300.  
  301.                         // Internal Variables:
  302.                         string += 'var input_color = '+input_color+'<br />';
  303.                         string += 'var input_color[0] = '+input_color[0]+'<br />';
  304.                         string += 'var input_color[1] = '+input_color[1]+'<br />';
  305.                         string += 'var input_color[2] = '+input_color[2]+'<br />';
  306.                         string += 'var current = '+current+'<br />';
  307.                         string += 'var current[0] = '+current[0]+'<br />';
  308.                         string += 'var current[1] = '+current[1]+'<br />';
  309.                         string += 'var current[2] = '+current[2]+'<br />';
  310.                         string += 'var change_red = '+change_red+'<br />';
  311.                         string += 'var change_green = '+change_green+'<br />';
  312.                         string += 'var change_blue = '+change_blue+'<br />';
  313.                         string += 'var change_rgb = '+change_rgb+'<br />';
  314.                         string += 'var direction_red = '+direction_red+'<br />';
  315.                         string += 'var maximum_distance_red = '+maximum_distance_red+'<br />';
  316.                         string += 'var random_distance_chance_red = '+random_distance_chance_red+'<br />';
  317.                         string += 'var random_distance_pick_red = '+random_distance_pick_red+'<br />';
  318.                         string += 'var i_red = '+i_red+'<br />';
  319.                         string += 'var distance_red = '+distance_red+'<br />';
  320.                         string += 'var direction_green = '+direction_green+'<br />';
  321.                         string += 'var maximum_distance_green = '+maximum_distance_green+'<br />';
  322.                         string += 'var random_distance_chance_green = '+random_distance_chance_green+'<br />';
  323.                         string += 'var random_distance_pick_green = '+random_distance_pick_green+'<br />';
  324.                         string += 'var i_green = '+i_green+'<br />';
  325.                         string += 'var distance_green = '+distance_green+'<br />';
  326.                         string += 'var direction_blue = '+direction_blue+'<br />';
  327.                         string += 'var maximum_distance_blue = '+maximum_distance_blue+'<br />';
  328.                         string += 'var random_distance_chance_blue = '+random_distance_chance_blue+'<br />';
  329.                         string += 'var random_distance_pick_blue = '+random_distance_pick_blue+'<br />';
  330.                         string += 'var i_blue = '+i_blue+'<br />';
  331.                         string += 'var distance_blue = '+distance_blue+'<br />';
  332.                         string += 'var new_color = '+new_color+'<br />';
  333.                         string += 'var new_color[0] = '+new_color[0]+'<br />';
  334.                         string += 'var new_color[1] = '+new_color[1]+'<br />';
  335.                         string += 'var new_color[2] = '+new_color[2]+'<br />';
  336.                         string += 'var color_string = '+color_string+'<br />';
  337.  
  338.                         document.open ();
  339.                         document.write (string);
  340.                         document.close ();
  341.                     }
  342.                 // End debugging.
  343.  
  344.                 document.getElementById(window.object_references[id]).style.color = color_string;
  345.  
  346.                 setTimeout ('shinylink_scan (' + id + ', ' + color + '); ', (5));
  347.             }
  348.     }
  349. function shinylink_restore (id, color)
  350.     {
  351.         if (window.shutdown) {return;}
  352.         var current = window.using_objects[id] != (false) ? window.restore_objects[id] : color;
  353.         if ((current[0] != color[0] || current[1] != color[1] || current[2] != color[2]) && window.active_object !== id)
  354.             {
  355.                 // Transition one color maximum per channel.
  356.                 var new_color = new Array ();
  357.                 var color_string = 'rgb(';
  358.                 for (var i = (0); i < color.length; i++)
  359.                     {
  360.                         new_color[i] = current[i] < color[i] ? (current[i] + (1)) : current[i] > color[i] ? (current[i] - (1)) : current[i];
  361.                         color_string += (new_color[i]) + (i != (2) ? ', ' : '');
  362.                     }
  363.                 color_string += ')';
  364.  
  365.                 window.restore_objects[id] = new_color;
  366.                 window.using_objects[id] = Array (
  367.                     Math.round ((new_color[0] + (1)) / (4)),
  368.                     Math.round ((new_color[1] + (1)) / (4)),
  369.                     Math.round ((new_color[2] + (1)) / (4))
  370.                 );
  371.  
  372.                 document.getElementById(window.object_references[id]).style.color = color_string;
  373.  
  374.                 setTimeout ('shinylink_restore (' + id + ', Array (' + color[0] + ', ' + color[1] + ', ' + color[2] + ')); ', (5));
  375.             }
  376.     }
Aug 9 '08 #11
Bah, okay, well, I fixed the issue with negative numbers, but not positive. Back to studying the code...
Aug 9 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: The Bicycling Guitarist | last post by:
I've used and loved the webmaster tools at Delorie.com for some years now. I just added some more text content to my home page, but in the web page "purifier" the text doesn't render as I thought...
68
by: Ted Nicols | last post by:
That's what I keep asking myself whenever develop in .NET. Is this a joke a farse or just a bad dream? ..NET is slow, actually slow is just a polite word I can use in a newsgroup. ..NET is...
3
by: Guido Wesdorp | last post by:
======================== Kupu 1.1 beta 1 released ======================== 22 May 2004 The Kupu Team is pround to announce the first beta release of Kupu 1.1. After the 1.0.3 release, which...
335
by: extrudedaluminiu | last post by:
Hi, Is there any group in the manner of the C++ Boost group that works on the evolution of the C language? Or is there any group that performs an equivalent function? Thanks, -vs
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
3
by: dianedebuda | last post by:
Using only Access 97. Need to run as admin in order to use Tool /Compact, etc. Tried Allen Browne's suggestion about registry hack meant for multiple versions of Access, but doesn't seem to work...
6
by: John | last post by:
Hi If I have a choice of WPF or Windows Form versions of a control which one should I purchase? Thanks Regards
3
by: Jethro | last post by:
Hi guys, I have inherited a .NET 2.0 web project. It consists of a root site, and 3 sub directories. Ideally these are seperate projects/websites. The root is a customer- facing one, and the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.