Jump to content

And... another screensaver!


lokster
 Share

Recommended Posts

I just made another screensaver... :D

It needs a little more work, but for now its good enough...

Note: when in fullscreen mode {SPACE} generates random parameters

Screenshot of the configuration dialog:

Posted Image

screensaver-psy.au3

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=screensaver-psy.scr
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseAnsi=y
#AutoIt3Wrapper_Res_Description=AutoIt v3 Compiled Script
#AutoIt3Wrapper_Run_AU3Check=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <Math.au3>
#include <Misc.au3>
#include <File.au3>

Opt("GUIOnEventMode", 1)
Opt("ColorMode", 1) ; use BGR color mode - its easier if you use Windows GDI use BGR format

Global Const $pi = 3.1415926535
Global Const $2pi = 2 * $pi
Global Const $degToRad = $pi / 180

Global $parametersChange = False
Global $mode = 1

Global $StartColor = _RegRead("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "StartColor", 0xFFFFFF)
Global $EndColor = _RegRead("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "EndColor", 0x000000)

Global $speed = 1000
Global $BackGroundColor = _RegRead("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "BackGroundColor", 0x000000)
Global $NumVertices = _RegRead("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "NumVertices", 3)
Global $randomize_interval = _RegRead("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "randomize_interval", 0) ;seconds
Global $num_figures = _RegRead("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "num_figures", 20)
Global $pen_width = _RegRead("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "pen_width", 1)
Global $colors = ColorGradient($StartColor, $EndColor, $num_figures)

If UBound($CmdLine) > 1 Then
    $Command = StringLeft($CmdLine[1], 2)
    If $Command == "/c" Then
        $mode = 0
    ElseIf $Command == "/s" Then
        $mode = 1
    ElseIf $Command == "/p" Then
        $mode = 2
    EndIf
Else
    If @Compiled Then $mode = 0
EndIf

Global $GDI32 = DllOpen("gdi32.dll")
Global $USER32 = DllOpen("user32.dll")

Switch $mode ;0 - config, 1 - run, 2 - preview
    Case 0
        #region CONFIGURE the screensaver
        #Region ### START Koda GUI section ### Form=D:\lokster\autoit\screensaver-psy\config.kxf
        Local $Form1 = GUICreate("Psy screensaver by lokster (v.20070705)", 353, 390)
        Local $iRandomizeInterval = GUICtrlCreateInput("0", 8, 288, 73, 21)
        GUICtrlSetOnEvent($iRandomizeInterval, "ParametersChange")
        GUICtrlSetTip($iRandomizeInterval, "Interval at which the parameters are randomized. 0 is disabled.")
        Local $iNumVertices = GUICtrlCreateInput("3", 96, 288, 73, 21)
        GUICtrlSetOnEvent($iNumVertices, "ParametersChange")
        GUICtrlSetTip($iNumVertices, "Number of the vertices of the figures")
        Local $iPenWidth = GUICtrlCreateInput("1", 184, 288, 73, 21)
        GUICtrlSetOnEvent($iPenWidth, "ParametersChange")
        GUICtrlSetTip($iPenWidth, "The width of the lines")
        Local $iNumFigures = GUICtrlCreateInput("20", 272, 288, 73, 21)
        GUICtrlSetOnEvent($iNumFigures, "ParametersChange")
        GUICtrlSetTip($iNumFigures, "Number of figures to draw")
        Local $Group1 = GUICtrlCreateGroup("Preview", 8, 0, 337, 265)
        Local $preview = GUICtrlCreateLabel("", 16, 16, 320, 240)
        GUICtrlSetBkColor($preview, 0x000000)
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        Local $btnOk = GUICtrlCreateButton("Ok", 8, 368, 59, 17, 0)
        GUICtrlSetOnEvent($btnOk, "btnOkClick")
        Local $btnCancel = GUICtrlCreateButton("Cancel", 72, 368, 59, 17, 0)
        GUICtrlSetOnEvent($btnCancel, "btnCancelClick")
        Local $btnFullscreenPreview = GUICtrlCreateButton("Fullscreen Preview", 248, 368, 97, 17, 0)
        GUICtrlSetOnEvent($btnFullscreenPreview, "btnFullscreenPreviewClick")
        Local $Label1 = GUICtrlCreateLabel("Interval", 8, 272, 39, 14)
        Local $Label2 = GUICtrlCreateLabel("Vertices", 96, 272, 42, 14)
        Local $Label3 = GUICtrlCreateLabel("Pen width", 184, 272, 51, 14)
        Local $Label4 = GUICtrlCreateLabel("Figures", 272, 272, 38, 14)
        Local $lokster = GUICtrlCreateLabel("(c) 2007 by lokster", 147, 369, 91, 17)
        GUICtrlSetColor($lokster, 0xFF0000)
        GUICtrlSetOnEvent($lokster, "loksterClick")
        GUICtrlSetCursor($lokster, 0)
        Local $Group3 = GUICtrlCreateGroup("Colors", 8, 312, 337, 49)
        Local $gradient1 = GUICtrlCreateLabel("", 40, 328, 272, 25)
        Local $btnStartColor = GUICtrlCreateButton(">", 16, 328, 19, 26, 0)
        GUICtrlSetOnEvent($btnStartColor, "btnStartColorClick")
        Local $btnEndColor = GUICtrlCreateButton("<", 318, 328, 19, 26, 0)
        GUICtrlSetOnEvent($btnEndColor, "btnEndColorClick")
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        GUISetState(@SW_SHOW)
        #EndRegion ### END Koda GUI section ###
        $HWND = GUICtrlGetHandle($preview)
        #endregion CONFIGURE the screensaver
        UpdateConfigDialog()
    Case 1
        #region RUN the screensaver
        Global $Display_width = DllCall($USER32, "int", "GetSystemMetrics", "int", 78);SM_CXVIRTUALSCREEN
        $Display_width = $Display_width[0]
        Global $Display_height = DllCall($USER32, "int", "GetSystemMetrics", "int", 79);SM_CYVIRTUALSCREEN
        $Display_height = $Display_height[0]
        Global $Form1 = GUICreate("Form1", $Display_width, $Display_height, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
        GUISetCursor(16)
        GUISetState(@SW_SHOW)
        Global $HWND = $Form1
        #endregion RUN the screensaver
    Case 2
        #region PREVIEW the screensaver
        If UBound($CmdLine) > 2 Then
            Global $HWND = HWnd($CmdLine[2])
            _Singleton("ss_preview")
        Else
            Exit
        EndIf
        #endregion PREVIEW the screensaver
EndSwitch

Global $DC = DllCall($USER32, "hwnd", "GetDC", "hwnd", $HWND)

Global $client_rect = WinGetClientSize($HWND)
Global $max_radius = $client_rect[1] / 2
Global $rect = DllStructCreate("long;long;long;long;")
DllStructSetData($rect, 1, 0)
DllStructSetData($rect, 2, 0)
DllStructSetData($rect, 3, $client_rect[0])
DllStructSetData($rect, 4, $client_rect[1])

Global $memory_dc = DllCall($GDI32, "hwnd", "CreateCompatibleDC", "hwnd", $DC[0])
Global $memory_bm = DllCall($GDI32, "hwnd", "CreateCompatibleBitmap", "ptr", $DC[0], "int", $client_rect[0], "int", $client_rect[1])
DllCall($GDI32, "hwnd", "SelectObject", "hwnd", $memory_dc[0], "hwnd", $memory_bm[0])


If $mode == 1 Then GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "Bye")
GUISetOnEvent($GUI_EVENT_CLOSE, "Bye")

If $mode == 1 And $randomize_interval > 0 Then AdlibEnable("aRandomizeParams", $randomize_interval * 1000)

$start = TimerInit()
Global $frame = 0
Global $randomize = False

If $mode == 2 Then
    While 1
        $frame = TimerDiff($start) / $speed
        If Not WinExists($HWND) Then Bye()
        If BitAND(WinGetState($HWND), 2) Then Draw($DC, $memory_dc, $frame)
    WEnd
Else
    While 1
        $frame = TimerDiff($start) / $speed
        If ($mode == 1 And __IsPressed(0x20)) Or $randomize Then
            Global $colors = ColorGradient(Random(0x000000, 0xFFFFFF, 1), Random(0x000000, 0xFFFFFF, 1), $num_figures)
            Global $NumVertices = Random(2, 6, 1)
            Global $pen_width = Random(1, 100)
            $randomize = False
        ElseIf $parametersChange == True Then
            Global $colors = ColorGradient($StartColor, $EndColor, $num_figures)
            $parametersChange = False
        Else
            Draw($DC, $memory_dc, $frame)
        EndIf
    WEnd
EndIf

Func _RegRead($keyname, $valuename, $default = "")
    Local $result = RegRead($keyname, $valuename)
    If $result == "" Then $result = $default
    Return $result
EndFunc   ;==>_RegRead

Func aRandomizeParams()
    $randomize = True
EndFunc   ;==>aRandomizeParams

Func Draw($DC, $memory_dc, $frame)
    Local $brush = DllCall($GDI32, "hwnd", "CreateSolidBrush", "int", $BackGroundColor)
    DllCall($USER32, "int", "FillRect", "hwnd", $memory_dc[0], "ptr", DllStructGetPtr($rect), "hwnd", $brush[0])
    DllCall($GDI32, "hwnd", "SelectObject", "hwnd", $memory_dc[0], "hwnd", $brush[0])
    DllCall($GDI32, "hwnd", "DeleteObject", "hwnd", $brush[0])

    $multiplyer = Sin($frame / 10)
    ;DllCall($GDI32, "int", "TextOut", "hwnd", $memory_dc[0],"int",0,"int",0,"str"," ","int",7)
    For $s = 1 To $num_figures
        If $parametersChange Then ExitLoop
        Local $r = Sin($s * $frame / 10)
        DllCall($GDI32, "int", "MoveToEx", "hwnd", $memory_dc[0], _
                "int", $client_rect[0] / 2 + Sin($frame + $s * $multiplyer) * ($s / $num_figures) * $max_radius * $r, _
                "int", $client_rect[1] / 2 + Cos($frame + $s * $multiplyer) * ($s / $num_figures) * $max_radius * $r, _
                "ptr", 0)
        If UBound($colors)<$s-1 Then ExitLoop ; HACK!
        Local $pen = DllCall($GDI32, "hwnd", "CreatePen", "int", "0", "int", $pen_width, "int", $colors[$s - 1])
        Local $pen_old = DllCall($GDI32, "hwnd", "SelectObject", "hwnd", $memory_dc[0], "hwnd", $pen[0])

        For $i = 0 To $2pi Step $2pi / $NumVertices
            Local $x = $client_rect[0] / 2 + Sin($i + $frame + $s * $multiplyer) * ($s / $num_figures) * $max_radius * $r
            Local $y = $client_rect[1] / 2 + Cos($i + $frame + $s * $multiplyer) * ($s / $num_figures) * $max_radius * $r
            DllCall($GDI32, "int", "LineTo", "hwnd", $memory_dc[0], "int", $x, "int", $y)
        Next
        DllCall($GDI32, "hwnd", "SelectObject", "hwnd", $memory_dc[0], "hwnd", $pen_old[0])
        DllCall($GDI32, "hwnd", "DeleteObject", "hwnd", $pen[0])
    Next

    DllCall($GDI32, "int", "BitBlt", "hwnd", $DC[0], "int", 0, "int", 0, "int", $client_rect[0], "int", $client_rect[1], "hwnd", $memory_dc[0], "int", 0, "int", 0, "int", 0xCC0020)
EndFunc   ;==>Draw

Func Bye()
    DllCall($GDI32, "hwnd", "DeleteObject", "hwnd", $memory_bm[0])
    DllCall($GDI32, "int", "DeleteObject", "hwnd", $memory_dc[0])
    DllCall($USER32, "int", "ReleaseDC", "hwnd", $DC[0], "hwnd", $HWND)
    Global $rect = 0
    Exit
EndFunc   ;==>Bye

Func OnAutoItExit()
    DllClose($USER32)
    DllClose($GDI32)
EndFunc   ;==>OnAutoItExit

Func ColorGradient($hInitialColor, $hFinalColor, $iReturnSize)
    $hInitialColor = Hex($hInitialColor, 6)
    $hFinalColor = Hex($hFinalColor, 6)

    Local $iRed1 = Dec(StringLeft($hInitialColor, 2))
    Local $iGreen1 = Dec(StringMid($hInitialColor, 3, 2))
    Local $iBlue1 = Dec(StringMid($hInitialColor, 5, 2))

    Local $iRed2 = Dec(StringLeft($hFinalColor, 2))
    Local $iGreen2 = Dec(StringMid($hFinalColor, 3, 2))
    Local $iBlue2 = Dec(StringMid($hFinalColor, 5, 2))

    Local $iPlusRed = ($iRed2 - $iRed1) / ($iReturnSize - 1)
    Local $iPlusBlue = ($iBlue2 - $iBlue1) / ($iReturnSize - 1)
    Local $iPlusGreen = ($iGreen2 - $iGreen1) / ($iReturnSize - 1)

    Local $iColorArray[$iReturnSize]
    For $i = 0 To $iReturnSize - 1
        $iNowRed = Floor($iRed1 + ($iPlusRed * $i))
        $iNowBlue = Floor($iBlue1 + ($iPlusBlue * $i))
        $iNowGreen = Floor($iGreen1 + ($iPlusGreen * $i))
        $iColorArray[$i] = Dec(Hex($iNowRed, 2) & Hex($iNowGreen, 2) & Hex($iNowBlue, 2))
    Next
    Return ($iColorArray)
EndFunc   ;==>ColorGradient

Func __IsPressed($hexKey)
    Local $a_R = DllCall($USER32, "int", "GetAsyncKeyState", "int", $hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc   ;==>__IsPressed

Func btnCancelClick()
    Bye()
EndFunc   ;==>btnCancelClick

Func btnOkClick()
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "randomize_interval", "REG_SZ", $randomize_interval)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "pen_width", "REG_SZ", $pen_width)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "StartColor", "REG_SZ", $StartColor)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "EndColor", "REG_SZ", $EndColor)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "BackGroundColor", "REG_SZ", $BackGroundColor)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "NumVertices", "REG_SZ", $NumVertices)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\K&S tech.\psy", "num_figures", "REG_SZ", $num_figures)
    Bye()
EndFunc   ;==>btnOkClick

Func btnFullscreenPreviewClick()
    If @Compiled Then
        RunWait('"' & @ScriptFullPath & '" /s')
    Else
        RunWait('"' & @AutoItExe & '" "' & @ScriptFullPath & '" /s')
    EndIf
EndFunc   ;==>btnFullscreenPreviewClick

Func loksterClick()
    ShellExecute("http://www.autoitscript.com/forum/index.php?showuser=18476")
EndFunc   ;==>loksterClick

Func DrawGradient($HWND, $aColors)
    Local $DC_Gradient = DllCall($USER32, "hwnd", "GetDC", "hwnd", $HWND)
    Local $pos = WinGetClientSize($HWND)
    For $i = 0 To UBound($aColors) - 1
        Local $rect = DllStructCreate("long;long;long;long;")
        Local $w = $pos[0] / (UBound($aColors))
        DllStructSetData($rect, 1, $i * $w)
        DllStructSetData($rect, 2, 0)
        DllStructSetData($rect, 3, $i * $w + $w)
        DllStructSetData($rect, 4, $pos[1])
        Local $brush = DllCall($GDI32, "hwnd", "CreateSolidBrush", "int", $aColors[$i])
        DllCall($USER32, "int", "FillRect", "hwnd", $DC_Gradient[0], "ptr", DllStructGetPtr($rect), "hwnd", $brush[0])
        DllCall($GDI32, "hwnd", "SelectObject", "hwnd", $DC_Gradient[0], "hwnd", $brush[0])
        DllCall($GDI32, "hwnd", "DeleteObject", "hwnd", $brush[0])
    Next
    DllCall($USER32, "int", "ReleaseDC", "hwnd", $DC_Gradient[0], "hwnd", $HWND)
EndFunc   ;==>DrawGradient

Func btnStartColorClick()
    Local $color = _ChooseColor(0, $StartColor)
    If $color >= 0 Then
        Global $StartColor = $color
        Global $colors = ColorGradient($StartColor, $EndColor, $num_figures)
        ParametersChange()
    EndIf
EndFunc   ;==>btnStartColorClick

Func btnEndColorClick()
    Local $color = _ChooseColor(0, $EndColor)
    If $color >= 0 Then
        Global $EndColor = $color
        Global $colors = ColorGradient($StartColor, $EndColor, $num_figures)
        ParametersChange()
    EndIf
EndFunc   ;==>btnEndColorClick

Func ParametersChange()
    Global $parametersChange = True
    Global $speed = 1000
    Global $BackGroundColor = 0x000000
    Global $NumVertices = GUICtrlRead($iNumVertices)
    Global $randomize_interval = GUICtrlRead($iRandomizeInterval)
    Global $num_figures = GUICtrlRead($iNumFigures)
    Global $colors = ColorGradient($StartColor, $EndColor, $num_figures)
    Global $pen_width = GUICtrlRead($iPenWidth)
    DrawGradient(GUICtrlGetHandle($gradient1), $colors)
EndFunc   ;==>ParametersChange

Func UpdateConfigDialog()
    GUICtrlSetData($iRandomizeInterval, $randomize_interval)
    GUICtrlSetData($iNumVertices, $NumVertices)
    GUICtrlSetData($iNumFigures, $num_figures)
    GUICtrlSetData($iPenWidth, $pen_width)
    DrawGradient(GUICtrlGetHandle($gradient1), $colors)
EndFunc   ;==>UpdateConfigDialog
Edited by lokster
Link to comment
Share on other sites

dewd: you know I like your code alot.. (I don't allways get what you mean but autoIt seems to understand you so the problem here is me)

maybe it's interesting to explain the people in these forums how you do it.. I have no clue on how you start building a screensaver..

(you're on your third or fourth screensaver) :whistle:

I mean give a man a fish and he will eat for a day, Teach a man to fish.. you know what I mean..

have a nice day there!

greetings from Dimitri

Link to comment
Share on other sites

dewd: you know I like your code alot.. (I don't allways get what you mean but autoIt seems to understand you so the problem here is me)

maybe it's interesting to explain the people in these forums how you do it.. I have no clue on how you start building a screensaver..

(you're on your third or fourth screensaver) :lmao:

I mean give a man a fish and he will eat for a day, Teach a man to fish.. you know what I mean..

have a nice day there!

greetings from Dimitri

He posted source code. So you can learn from it.

@Your sig: Tell man about a word and he will change one. Give man dictionary and he will learn for life.

It is not alot, but a lot. It is not allways but always. It is not autoIt but AutoIt. It is not dewd, but dude (if I guess right :whistle: .)

Get yourself a dictionary!

I can do signature me.

Link to comment
Share on other sites

This screensaver is nice too, the space bar randomizer is good.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
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...