Fastest Way to Flash the Screen

What’s the fastest way to change a window from all black to all white repeatedly? I’d like to use my computer screen as a sort of strobe to flash at 25-60 times per second. I’ve got the code working, but performance is abysmal, especially when the window is maximized. Would using some Cocoa API calls yield better results perhaps, or should I just program my Arduino to flash some LEDs?



Oh, forgot to mention that my current approach is to use FillRect on the window’s graphics context. I just alternately fill it with black and white. Is there a faster way?


Create two pictures, one all-black, the other all-white, then swap those pictures in Graphics. It sounds like you are recreating the images on each “flash”, and there is no reason to do that.

MBS plugins had something… Display.DrawingContext. It’s analogous to the Cocoa api’s. I’m pretty sure that would be the fastest possible way in Cocoa… of course you have to use the CG drawing functions, but if you’re only flashing it, then it shouldn’t be a major problem.

Oi, that makes sense! I’ll give it a go. Thanks, Kem.


OpenGL can do fullscreen at 60fps pretty easily.

Another approach I hadn’t considered! If the picture technique doesn’t cut it, I’ll give OpenGL a try. Thanks, Will.


I don’t think this will work, at least by default, due to OS X’s window update coalescing:

You may need to fiddle with your app’s Info.plist to get this to work, and even then I’d be skeptical. What in the world are you trying to do, anyway?

BTW, since this appear to be a Mac-specific question, it should have been posted under Targets->Mac, not General.

Since when?

Why, does it matter? Although the post mentions Cocoa APIs, the developer did not specify a specific operating system and it might be useful if this question was answered with regard for Windows and Linux.

Just an idea : why not use an HTML Viewer and load an animated Gif ?

Just tried an experiment using self.backcolor and under cocoa (on an old macbook) I’m seeing 800+fps on a small sized window down to about 30fps fullscreen. Seems like the simplest solution. Just be sure to turn on customColor in the window properties.