Jump to content

Matrix style background effect ( Screensaver )


Jex
 Share

Recommended Posts

  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I like the one posted by Saunders but is it possible to change the vertical spacing according to the font size so that the smaller letters dont have such a big gap between them? I think this would give it a real depth affect.

I am afraid that my skills aren't yet up to it but I will have a go. Can anyone else see how to achieve this?

Link to comment
Share on other sites

I like the one posted by Saunders but is it possible to change the vertical spacing according to the font size so that the smaller letters dont have such a big gap between them? I think this would give it a real depth affect.

I am afraid that my skills aren't yet up to it but I will have a go. Can anyone else see how to achieve this?

I was trying to figure out a good way to do this as well, but came up with nothing (nothing elegant anyway, thought about manually entering the vertical spacing for each size, but ew). I just had an idea though... gonna go try something.

Link to comment
Share on other sites

Done!

...

Now if I can just figure out a way to center the characters in their columns. :)

*Edit: Okay, so I figured that out too.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include <Math.au3>
#include <_Variable.au3>

;~ ==============================================================
;~ User Settings - Feel free to modify these values!
;~ ==============================================================
Global $iSpaceHori = 25 ; The horizontal space (width) of each column
Global $iSpaceVert = 25 ; The vertical space (height) of each row
Global $sChars = '0123456789ABCDEFGHZYXWVUTSRQPONMLKJIabcd' ; The characters that will appear in the dropping text
Global $sFontName = 'Matrix Code Font'
Global $iFontSizeMax = 20
Global $iFontSizeMin = 8


;~ ==============================================================
;~ Here there be dragons...
;~ ==============================================================
Global $iWidth = @DesktopWidth, $iHeight = @DesktopHeight
Global $iThreadCount = Ceiling($iWidth / $iSpaceHori)
Global $hFont, $hFamily, $hFormat, $hBrush, $hGraphic
Global $iFadeLength = 40
Global $iDelayMax = 5
Global $hUser32dll = DllOpen('user32.dll')

;~ Set colours for the different font sizes (smaller = darker to give the impression of perspective.. or smth)
Global $aColours[$iFontSizeMax + 1]
    $aColours[08] = 0x003300
    $aColours[09] = 0x004400
    $aColours[10] = 0x005500
    $aColours[11] = 0x006600
    $aColours[12] = 0x007700
    $aColours[13] = 0x008800
    $aColours[14] = 0x009900
    $aColours[15] = 0x00aa00
    $aColours[16] = 0x00bb00
    $aColours[17] = 0x00cc00
    $aColours[18] = 0x00dd00
    $aColours[19] = 0x00ee00
    $aColours[20] = 0x00ff00
Global $aVSpaces[$iFontSizeMax + 1]
Global $aStrings = StringSplit($sChars, '') ; Split the character set
Global $aThreads[$iThreadCount][5] ; Initiate threads
$iThreadCount -= 1 ; Just to keep from having to -1 in every For loop (one less calculation = potential speed increase?)
Global Enum $THR_DELAY, $THR_DELAYCOUNT, $THR_FONTSIZE, $THR_VERTPOS, $THR_HORIPOS
For $iThread = 0 To $iThreadCount ; Pre-set threads
    $aThreads[$iThread][$THR_DELAY] = Random(0, $iDelayMax, 1) ; Delay - some threads descend slower
    $aThreads[$iThread][$THR_VERTPOS] = -Random(0, $iThreadCount, 1) * $iSpaceVert
    $aThreads[$iThread][$THR_FONTSIZE] = Random($iFontSizeMin, $iFontSizeMax, 1)
    $aThreads[$iThread][$THR_DELAY] = $iFontSizeMax - $aThreads[$iThread][$THR_FONTSIZE]
Next

$gui = GUICreate('RobsMatrixThing', 0,0,0,0, BitOR($WS_POPUP, $WS_MAXIMIZE), $WS_EX_TOPMOST)
GUISetCursor(16, 1)
GUISetBkColor(0)

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($gui)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate($sFontName)
$hFaderBrush = _GDIPlus_BrushCreateSolid(0x20000000)
$hHalfBrush = _GDIPlus_BrushCreateSolid(0x80000000)

$tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
For $iFontSize = $iFontSizeMin to $iFontSizeMax
    $aVSpaces[$iFontSize] = 0
    $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 0)
    For $iLetter = 1 to $aStrings[0]
        $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $aStrings[$iLetter], $hFont, $tLayout, $hFormat)
        $aVSpaces[$iFontSize] = _Max($aVSpaces[$iFontSize], Ceiling(DllStructGetData($aInfo[0], 'height')))
    Next
Next

Global $aTextBrushes[$iFontSizeMax + 1]
For $i = 0 To $iFontSizeMax
    $aTextBrushes[$i] = _GDIPlus_BrushCreateSolid(0xff000000 + $aColours[$i])
Next

ProcessSetPriority(@AutoItPID, 0)
Sleep(100)

GUISetState()
Global $i_LastActive = _LastActive($hUser32dll)
Global $iTimer = TimerInit()
While 1
    If $i_LastActive <> _LastActive($hUser32dll) Then Exit
    
    For $iThread = 0 To $iThreadCount
        If $aThreads[$iThread][$THR_DELAY] > $aThreads[$iThread][$THR_DELAYCOUNT] Then
            $aThreads[$iThread][$THR_DELAYCOUNT] += 1
            ContinueLoop
        EndIf
        $aThreads[$iThread][$THR_DELAYCOUNT] = 0
        
        $iColumnPos = $aThreads[$iThread][$THR_HORIPOS]
        $iColumnPos = $iThread * $iSpaceHori
        $iRowPos = $aThreads[$iThread][$THR_VERTPOS]
        
        $iFontSize = $aThreads[$iThread][$THR_FONTSIZE]
        $sLetter = $aStrings[Random(1, $aStrings[0], 1)]
        $iSpaceVert = $aVSpaces[$iFontSize]
        
        $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 0)
        $hBrush = $aTextBrushes[$iFontSize]
        $tLayout = _GDIPlus_RectFCreate($iColumnPos, $iRowPos, 0, 0)
        $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sLetter, $hFont, $tLayout, $hFormat)
        ;~ These next two lines will center the skinny characters.
        $fCharWidth = DllStructGetData($aInfo[0], 'width')
        DllStructSetData($aInfo[0], 'x', $iColumnPos + ($iSpaceHori - $fCharWidth) / 2)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, $sLetter, $hFont, $aInfo[0], $hFormat, $hBrush)
        _GDIPlus_GraphicsFillRect($hGraphic, $iColumnPos, $iRowPos - $iSpaceVert, $iSpaceHori, $iSpaceVert, $hHalfBrush)
        _GDIPlus_GraphicsFillRect($hGraphic, $iColumnPos, $iRowPos - ($iSpaceVert * $iFadeLength), $iSpaceHori, $iSpaceVert * 10, $hFaderBrush)

        $aThreads[$iThread][$THR_VERTPOS] += $iSpaceVert
        If $aThreads[$iThread][$THR_VERTPOS] >= $iHeight + ($iSpaceVert * $iFadeLength) Then
            $aThreads[$iThread][$THR_DELAY] = Random(0, $iDelayMax, 1)
            $aThreads[$iThread][$THR_DELAYCOUNT] = 0
            $aThreads[$iThread][$THR_VERTPOS] = -Random(0, $iThreadCount, 1) * $iSpaceVert
            $aThreads[$iThread][$THR_FONTSIZE] = Random($iFontSizeMin, $iFontSizeMax, 1)
            $aThreads[$iThread][$THR_DELAY] = $iFontSizeMax - $aThreads[$iThread][$THR_FONTSIZE]
        EndIf
    Next
    
    If TimerDiff($iTimer) > 1000 Then
        $iTimer = TimerInit()
        For $i = 1 To 5
            $iColumn = Random(0, $iThreadCount, 1)
            _GDIPlus_GraphicsFillRect($hGraphic, $iColumn * $iSpaceHori, 0, $iSpaceHori, $iHeight, $hFaderBrush)
        Next
    EndIf
    Sleep(10) ; Just a little sleep to cut the CPU down (still 20-40% on my system though)
WEnd

Func _LastActive($vUser32Dll = 'user32.dll')
    Local $tLastInput = DllStructCreate('uint;dword')
    DllStructSetData($tLastInput, 1, DllStructGetSize($tLastInput))
    DllCall($vUser32Dll, 'int', 'GetLastInputInfo', 'ptr', DllStructGetPtr($tLastInput))

    Return DllStructGetData($tLastInput, 2)
EndFunc
Edited by Saunders
Link to comment
Share on other sites

Had to negotiate the timeline matrix to find the Variable.au3 UDF...it's left out of current prod version, and that version leaves one beta-less().

Good intentions will always be pleaded for every assumption of authority. It is hardly too strong to say that the Constitution was made to guard the people against the dangers of good intentions. There are men in all ages who mean to govern well, but they mean to govern. They promise to be good masters, but they mean to be masters.-Daniel Webster

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...