How To Make a Strobe Out of a Monitor (or The Most Powerful JavaScript Ever)

by Matthew Russell

A project I'm finishing off involves a simple little front end that I've decided to implement using some DHTML. As I was reading up on JavaScript's setTimeout method as part of my DHTML research, an interesting thought crossed my mind: would it be possible to make a strobe light out of that old archaic CRT monitor sitting on my closet floor and such a weak (as in weakly typed) language as JavaScript?

Well, I decided to give it a try and it actually worked out pretty well -- although it did give me a mild headache after I had the not so keen idea to stare directly at it for a few seconds. Be warned that if you're that one other extremely unlucky person, you might just ruin your equipment (or cause someone you know to have a seizure) by running a script as powerful as this one.

Here's the code you need to make use of that old dust magnet.



<html><head>
<title>Strobe</title>

<script>
<!-- If you're extremely unlucky, you may break your equipment, or worse, have a seizure -->
function toggleBgColor()
{
document.bgColor = document.bgColor == '#ffffff' ? '#000000' : '#ffffff';
setTimeout('toggleBgColor()', 75); //in milliseconds
}
</script>
</head>

<body onLoad='toggleBgColor();'>
</body></html>



Just save the code as a webpage (text file that ends in ".html") and open it up in your favorite semi-modern web browser to let the fun begin. Pretty simple, huh?

Can you think of anything better to do with that old monitor than make a strobe out of it? (Or do you know of any other JavaScript hacks that could potentially be hazardous to your health?)

10 Comments

rsbohn
2006-01-27 20:10:36
brain hurts
make it stop!
DELORES
2006-01-28 05:54:55
I HAVE A 6101 NOKIA FLIP PHONE AND THE T-ZONE WILL NOT WORK
ptwobrussell
2006-01-28 11:28:53
I HAVE A 6101 NOKIA FLIP PHONE AND THE T-ZONE WILL NOT WORK


You realize that this was intended to be used with a monitor, right? As in an old computer and monitor. Sorry if that wasn't clear. Phones have a long way to go with scripting...

Peter NES
2006-01-28 19:22:58
This sounds like a fun holloween project, just think, the "Haunted Apple iMac!" boooo!
joe
2006-01-29 01:04:05
wow, trippy. this is similar to my first dhtml project, though mine was a multi-colored ode to overly flashy 80s gaming gone terribly terribly wrong.
Bob
2006-02-08 09:27:43
Interesting. I published a far more complete implementation the day before the original post. It's important to have as short a flash as possible, some browsers allow 10 ms some 15 ms. Of course the typical monitor is scanning at 60 to 100 hertz, which is perfect. Try it out. Scroll down to the start strobe button
See:
www.bobshowto.com/fun/strobe-light.htm
for a monitor strobe with adjustable flash rate, and a couple other features. Color to come.
ptwobrussell
2006-02-08 09:32:56
@Bob: Crazy timing. I definitely didn't think it through to anywhere near the level you did. It was just one of those things I stumbled across while investigating the wild and wonderful world of JavaScript and DOM manipulation.
Bob
2006-02-08 09:50:04
I was surprised to see in my weblogs just how many people are thinking about it ALL OVER the world! It's barely indexed by Google and I see lots of searches for "strobe light monitor", etc. My code's still very sloppy, but what the heck.
Strobe Light
Anonymous Coward
2006-02-08 10:05:32
The number one hit I get on a search is the Make Blog which is a cross reference to this post.
AngryJohn
2006-05-17 02:35:21
This could be combined with this:
<SCRIPT LANGUAGE="JavaScript1.2">


function shake_xy(n) {

if (self.moveBy) {

for (i = n; i > 0; i--) {

self.moveBy(0,i);

self.moveBy(i,0);

self.moveBy(0,-i);

self.moveBy(-i,0);

}

}

}

</script>

<body onload="shake_xy(1000)">
Or something