Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Resource "gbsnippets.pbr"
Type mtxMatrixStruct
X As Long
Y As Long
CharsDistance As Long
BlackColorMix As Byte
PrintChar As String * 1
CurrentFlag As Long
End Type
Global hDlg As DWord, hSettings as DWord
Global mtxMatrix() As mtxMatrixStruct, mtxMatrixMax As Long
%IDC_Graphic = 600 : %ID_Timer = 700
Function PBMain() As Long
Local w,h As Long
Desktop Get Size To w,h
Dialog New Pixels, 0, "Button Test",0,0,w,h, %WS_Popup To hDlg
Control Add Graphic, hDlg, %IDC_Graphic, "", 0,0,w,h,%WS_Visible
Graphic Attach hDlg, %IDC_Graphic, Redraw
Graphic Font "MS Sans Serif", 18, 1
Graphic Color %Green, %Black
Graphic Clear
ShowCursor(%False)
Dialog Show Modal hDlg Call DlgProc
' Graphic Waitkey$
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_InitDialog
mtxInitializeMatrixScreensaver
SetTimer(CB.Hndl, %ID_Timer, 20, ByVal %NULL) 'uses callback messages
Dialog Post CB.Hndl, %WM_Timer, %ID_TIMER, 0 ' optional - forces an initial %WM_TIMER "event"
Case %WM_Timer
ScreenSaver
Case %WM_Destroy
ShowCursor(%True)
KillTimer CB.Hndl, %ID_Timer
End Select
End Function
Sub ScreenSaver
Local w,h,x,y As Long
Static iCount As Long
Desktop Get Size To w,h
Incr iCount
mtxCreateMatrixScreenSaver
' x = Rnd(1,w) - 100
' y = Rnd(1,h) - 100
' Graphic Clear
' Graphic Render "cowgirl", (x,y)-(x+100,y+100)
' Graphic Print "Screensaver Test" + Str$(iCount)
' Graphic Redraw
End Sub
Sub mtxInitializeMatrixScreenSaver
ReDim mtxMatrix(100)
Local i As Long, w As Long, h As Long
mtxMatrixMax = 100 : Control Get Client hDlg, %IDC_Graphic To w,h
For i = 0 To mtxMatrixMax
mtxMatrix(i).X = Rnd(1,w) 'graphic width
mtxMatrix(i).Y = Rnd(1,h) 'graphic height
mtxMatrix(i).CharsDistance = Rnd(5,15) 'Distance between chars
mtxMatrix(i).BlackColorMix = Rnd(0,255) 'Green to black color
mtxMatrix(i).PrintChar = Chr$(Rnd*1)
mtxMatrix(i).CurrentFlag = 0 'Display chars or black box
Next i
End Sub
Sub mtxCreateMatrixScreenSaver
Local i As Long, k As Long, w As Long, h As Long
Control Get Client hDlg, %IDC_Graphic To w,h : k = 25
For i = 0 To mtxMatrixMax 'Draw one char at each designated position
mtxMatrix(i).Y = mtxMatrix(i).Y + mtxMatrix(i).CharsDistance
If mtxMatrix(i).Y > h Then
mtxMatrix(i).CurrentFlag = mtxMatrix(i).CurrentFlag XOR 1 'chars or black box
mtxMatrix(i).Y = -1
If mtxMatrix(i).CurrentFlag Then mtxMatrix(i).X = Rnd(0,w) 'new x location
mtxMatrix(i).BlackColorMix = Rnd(0,255) 'New random color for the chars
End If
mtxMatrix(i).PrintChar = Chr$(Rnd(0,255))
Graphic Set Pos (mtxMatrix(i).X, mtxMatrix(i).Y) 'Locate the cursor to print
'print greenish character or black box at new XY position
If mtxMatrix(i).CurrentFlag = 0 Then 'Display black block - to erase previously displayed chars
Graphic Box (mtxMatrix(i).X, mtxMatrix(i).Y)-((mtxMatrix(i).X + k), (mtxMatrix(i).Y) + k), %Black, %Black
Else 'Display characters
Graphic Color Rgb(25, mtxMatrix(i).BlackColorMix, 25), %Black
Graphic Print mtxMatrix(i).PrintChar
End If
Next i
Graphic Redraw
End Sub
Sub DisplaySettingsDialog()
Dialog New Pixels, hDlg, "Matrix Screensaver", 100, 100, 200,200, %WS_OverlappedWindow To hSettings
Dialog Set Icon hSettings, "aainfo"
Control Add Label, hSettings, 1000, "gbSnippets 8.1", 40, 10, 200, 40, %SS_Center
Dialog Show Modal hSettings
End Sub
'gbs_00464
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm