Jump to content

Colored Boxes screensaver


james3mg
 Share

Recommended Posts

Yet another screensaver here, but this is the first one I've made that actually fully functions as a real screensaver (preview and everything). I just couldn't find a simple decent-looking screensaver that would work on Vista installations w/o Aero (at least none bundled) and I needed something to script, so I made this. It gets the job done, if nothing else! :D Thought I'd share. Side note: I made this for a computer that displays a static window 24/7 at work, and after little more than a year, I'm seeing signs of the image burning in. So I actually found a real need for a screensaver!

This just covers all your monitors with an array of rectangles (selectable size) of random color (red, green or blue hues), and each box fades to black, then pops back to full saturation again. It's similar to a screensaver included in Ubuntu :D

As with all screensaver scripts' source, this must be compiled into an .exe, then renamed with a .scr extension and moved into your System32 directory for Windows to offer it as a screensaver in the normal drop-down selector. Note that if the filename begins with "ss", Windows will trim that and use the rest of the file name as the name of the screensaver. For instance, I named mine "ssColored Boxes.scr", and Windows calls it "Colored Boxes" in the dropdown. However, you can just run the uncompiled script if you want to see what the screensaver looks like...exit by hitting a typing keyboard key (not the F# buttons, home, arrows, etc), Esc, or by moving the mouse (the mouse is purposefully not too sensitive).

Note I haven't upgraded to AutoIt 3.2.10 yet...I've got one huge script I can't get compatible, so this is still written under 3.2.8.1. The only difference should be that $SM_VIRTUALWIDTH and HEIGHT are (I think) predefined constants in the newer versions, so you might need to comment out lines 6 and 7.

#NoTrayIcon
#include <GUIConstants.au3>
If WinExists("Colored Boxes Screensaver") Then WinKill("Colored Boxes Screensaver")
AutoItWinSetTitle("Colored Boxes Screensaver")

Global Const $SM_VIRTUALWIDTH = 78
Global Const $SM_VIRTUALHEIGHT = 79
$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
$VirtualDesktopHeight = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT)
$VirtualDesktopHeight = $VirtualDesktopHeight[0]

Global $Colors[3][3]
$Colors[0][0]=0xFF0000;red
$Colors[0][1]=0x00FFFF;mask for creating 'pure' color of random saturation, typical of (3)
$Colors[0][2]=0x040000;amount to reduce color by each interval, typical of (3)

$Colors[1][0]=0x007700;green (full saturation green is ugly)
$Colors[1][1]=0x0000FF
$Colors[1][2]=0x000400

$Colors[2][0]=0x0000FF;blue
$Colors[2][1]=0x000000
$Colors[2][2]=0x000004

Global $SelColor=Random(0,2,1);0=red, 1=green, 2=blue
Global $BoxSize=IniRead(@UserProfileDir&"\ColoredBoxesScreensaver.ini","Config","BoxSize",150)
If $BoxSize<=0 Then $BoxSize=150
Global $SleepTime=IniRead(@UserProfileDir&"\ColoredBoxesScreensaver.ini","Config","SleepTime",1)
If $SleepTime<=0 Then $SleepTime=1

If $CmdLine[0]=0 Or StringLeft($CmdLine[1],2)="/s" Then
    RunScreensaver(0)
ElseIf StringLeft($CmdLine[1],2)="/c" Then
    ConfigureScreensaver()
ElseIf StringLeft($CmdLine[1],2)="/p" Then
    If $CmdLine[0] < 2 Then Exit
    RunScreensaver(1)
EndIf

Func RunScreensaver($IsPreview=0)
    If $IsPreview Then
        $VirtualDesktopWidth=152
        $VirtualDesktopHeight=112
        $BoxSize=35
        $ScreensaverGUI=GUICreate("ColorBoxes Screensaver",$VirtualDesktopWidth,$VirtualDesktopHeight,0,0,$WS_POPUP)
        $USER32 = DllOpen("user32.dll")
        DllCall($USER32,"int","SetParent","hwnd",$ScreensaverGUI,"hwnd",HWnd($CmdLine[2]))
    Else
        $ScreensaverGUI=GUICreate("ColorBoxes Screensaver",$VirtualDesktopWidth,$VirtualDesktopHeight,0,0,$WS_POPUP,$WS_EX_TOPMOST+$WS_EX_TOOLWINDOW)
        GUISetCursor(16,1)
    EndIf
    GUISetBkColor(0x000000)
    If NOT $IsPreview Then
        Global $KeyGrab=GUICtrlCreateEdit("",0,0,0,0)
        GUICtrlSetState(-1,$GUI_HIDE)
    EndIf
    Global $NumW=Round($VirtualDesktopWidth/$BoxSize)
    Global $StdW=Ceiling($VirtualDesktopWidth/$NumW)
    Global $NumH=Round($VirtualDesktopHeight/$BoxSize)
    Global $StdH=Ceiling($VirtualDesktopHeight/$NumH)
    Global $Boxes[$NumW][$NumH][2]
    For $y=0 To $NumH-1
        For $x=0 To $NumW-1
            $Boxes[$x][$y][1]=Random(0x000000,$Colors[$SelColor][0])
            $Boxes[$x][$y][1]-=BitAND($Colors[$SelColor][1],$Boxes[$x][$y][1])
            $Boxes[$x][$y][0]=GUICtrlCreateLabel("",$x*$StdW,$y*$StdH,$StdW,$StdH)
            GUICtrlSetBkColor(-1,$Boxes[$x][$y][1])
        Next
    Next
    GUISetState()
    Global $ColorTimer=TimerInit()
    Global $MsgTimer[2]=[0,TimerInit()]
    
    While 1
        If Not $IsPreview Then
            If GUICtrlRead($KeyGrab) <> "" Then Return
            $msg=GUIGetMsg()
            If $MsgTimer[0]=0 Then
                If $msg <> 0 Then
                    $MsgTimer[0]=$msg
                    $MsgTimer[1]=TimerInit()
                EndIf
            ElseIf $msg=0 Then
                $MsgTimer[0]=0
            Else
                If TimerDiff($MsgTimer[1]) > 100 AND $msg=$MsgTimer[0] Then Return
            EndIf
        Else
            If NOT WinExists(HWnd($CmdLine[2])) Then
                DllClose($USER32)
                Exit
            EndIf
        EndIf
        
        For $y=0 To $NumH-1
            For $x=0 To $NumW-1
                Sleep($SleepTime)
                If $Boxes[$x][$y][1] < $Colors[$SelColor][2] Then $Boxes[$x][$y][1] = $Colors[$SelColor][0]
                $Boxes[$x][$y][1]-=$Colors[$SelColor][2]
                GUICtrlSetBkColor($Boxes[$x][$y][0],$Boxes[$x][$y][1])
            Next
        Next
    WEnd
EndFunc

Func ConfigureScreensaver()
    GUICreate("Configure Screensaver",280,160)
    GUICtrlCreateLabel("Approx. size of boxes: (default = 150)",5,5,270,20)
    $BoxSizeInput=GUICtrlCreateInput(IniRead(@UserProfileDir&"\ColoredBoxesScreensaver.ini","Config","BoxSize",150),5,25,150,20,$ES_NUMBER+$ES_LEFT+$ES_AUTOHSCROLL)
    GUICtrlCreateUpDown($BoxSizeInput,$UDS_NOTHOUSANDS+$UDS_ALIGNRIGHT)
    GUICtrlSetLimit(-1,$VirtualDesktopHeight/2,5)
    GUICtrlCreateLabel("Reduction of visual anomolies (min/default = 1)"&@CRLF&"(larger numbers = slower movement = better rendering):",5,55,270,30)
    $SleepTimeInput=GUICtrlCreateInput(IniRead(@UserProfileDir&"\ColoredBoxesScreensaver.ini","Config","SleepTime",1),5,85,150,20,$ES_NUMBER+$ES_LEFT+$ES_AUTOHSCROLL)
    GUICtrlCreateUpDown($SleepTimeInput)
    GUICtrlSetLimit(-1,50,1)
    
    $CancelButton=GUICtrlCreateButton("Cancel",55,120,80,20)
    $OKButton=GUICtrlCreateButton("OK",145,120,80,20)
    GUICtrlCreateLabel("Colored Boxes Screensaver written by james3mg in AutoIt",5,145,275,15)
    GUISetState()
    
    While 1
        Switch GUIGetMsg()
            Case $CancelButton
                Exit
            Case $GUI_EVENT_CLOSE
                Exit
            Case $OKButton
                If GUICtrlRead($BoxSizeInput) > 0 Then IniWrite(@UserProfileDir&"\ColoredBoxesScreensaver.ini","Config","BoxSize",GUICtrlRead($BoxSizeInput))
                If GUICtrlRead($SleepTimeInput) > 0 Then IniWrite(@UserProfileDir&"\ColoredBoxesScreensaver.ini","Config","SleepTime",GUICtrlRead($SleepTimeInput))
                Exit
        EndSwitch
    WEnd    
EndFunc
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

Glad you like it! :D It's by far not the most complex screensaver I've made, but it's kind of a fun one. Thanks for the kind words. Now that I've finally got a "real" screensaver made, I think I'll see if I can't make some kind of easy screensaver udf - something that lets you run a few functions like _SS_MainLoop() and _SS_SetConfigLoop() to point at whatever appropriate functions you have in your script, with some default functions if you don't want to define one or more of the loops. I'll have to think about how to structure everything, though.

By the way, I should have mentioned it in my first post: the only change this script makes to your computer is to add ColoredBoxesScreensaver.ini at @UserProfileDir. To completely uninstall this script, just delete the script and that ini file.

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

Glad you like it! :D It's by far not the most complex screensaver I've made, but it's kind of a fun one. Thanks for the kind words. Now that I've finally got a "real" screensaver made, I think I'll see if I can't make some kind of easy screensaver udf - something that lets you run a few functions like _SS_MainLoop() and _SS_SetConfigLoop() to point at whatever appropriate functions you have in your script, with some default functions if you don't want to define one or more of the loops. I'll have to think about how to structure everything, though.

By the way, I should have mentioned it in my first post: the only change this script makes to your computer is to add ColoredBoxesScreensaver.ini at @UserProfileDir. To completely uninstall this script, just delete the script and that ini file.

Haha, I was looking through my Ubuntu screensavers, and guess what I found? This basically exact one! Woot! Glad you made it in Autoit. How bout making another screensaver? Check out the: Plasma Screensaver in Ubuntu! I'd love to see that one! :D
Link to comment
Share on other sites

Nice work... It flickers some but that's expected..

The flicker is why I built in the ability to vary the sleep length between color updates...try 15 or even 50 and see if the flicker doesn't get better.
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...