// GPL Copyright (C) 2000 Paul Makepeace, satur8@hues.org var r, g, b, its_body; var t; // "Let t equal time..." function psychle_next () { t += 1; // This could be larger to make it seem faster // e.g. 1+10/delay.value -- 10ms is where most browsers seem to max out r = 127.5 + 127.5 * Math.sin(t/97); // These three denominators are (co-)prime, g = 127.5 + 127.5 * Math.sin(t/59); // so shouldn't repeat for a reasonable period: b = 127.5 + 127.5 * Math.sin(t/29); // about four hours with default 100ms delay. } // (I can't believe I have to write a dec2hex routine.) var hex_chars = "0123456789ABCDEF"; function dec2hex(d) { return hex_chars.charAt(d/16) + hex_chars.charAt(d%16); } // Manipulate calling document's bgColor function psychle_bgcolor() { its_body.bgColor = dec2hex(r) + dec2hex(g) + dec2hex(b); } var delay; // psychle_delay get/set function function psychle_delay(d) { return d ? (delay.value = d) : delay.value; } // Entry point. b is the document (body) object whose // bgColor property we'll poke around with. Shame // we can't pass the actual bgColor object reference // itself :-/ (It gets stringified). Mail me if you // know how to do this! // d is the initial delay value. We check for a frameset // and pick up *that* delay object so that it's shared // (see psychle_2x2.html) var psychle_on = 0; function psychle_start(b, d) { psychle_on = 1; t = 1000 * Math.random(); its_body = b; delay = (top && top.psychle_shared_delay) ? top.psychle_shared_delay : new Object; if (d) psychle_delay(d); psychle(); } function psychle_stop(c) { psychle_on = 0; if (c != null) its_body.bgColor = c; } // Main loop. // count is a limiter just used in development -- change 1 || to 0 || to enable. var count = 1000; function psychle() { if (!psychle_on) return; psychle_next(); psychle_bgcolor(); psychle_track(); if (1 || count-- > 0) setTimeout('psychle()', psychle_delay()); } // If there is a psychle_track form object in the calling // document then update its psychle_track_{r,g,b} values // It would be sexy to have this as a callback so it // could move around frames. function psychle_track() { if (!its_body.psychle_track) return; with (its_body.psychle_track) { if (!psychle_track_on.checked) return; psychle_track_r.value = r.toString().substring(0,3); psychle_track_g.value = g.toString().substring(0,3); psychle_track_b.value = b.toString().substring(0,3); } }