Gianni Posted July 27, 2019 Share Posted July 27, 2019 (edited) Just for fun, a weekend script that comes from 2 ideas: one idea is from this link (https://github.com/lukePeavey/quotable), that shows how to get a single random quote from a database, The other idea is to visualize the above quotes by a revisitation of a funny snipped I posted time ago here (https://www.autoitscript.com/forum/topic/159910-useless-code/?do=findComment&comment=1163490) that very rougly simulates a "Departure Mechanical Panel". Of course you could also use an array of your own phrases to send randomly to the _AsciiPanel() function. I hope you have fun and I wish you can use this "Departure Panel" to take a nice journey toward wisdom. expandcollapse popupGlobal $hGuiPanel HotKeySet("{ESC}", "_End") _Example() Func _Example() Local $bError = False, $aSplit Do If GUIGetMsg() = -3 Then ExitLoop $sQuote = InetRead("https://api.quotable.io/random", 1) If Not @error Then $aSplit = StringSplit(BinaryToString($sQuote), '"', 3) $sQuote = $aSplit[7] & " (" & $aSplit[11] & ")" Else $sQuote = "Sorry, no quotes for You." $bError = True EndIf _AsciiPanel($sQuote) Until $bError EndFunc ;==>_Example Func _AsciiPanel($sMsg, $iSeconds = 8, $iColumns = 30) ; only ascii chars allowed $sMsg = StringRegExpReplace($sMsg, "[^\x20-\x7F]+", " ") $sMsg = _StringColumn($sMsg, $iColumns) Local $aAsciiLines = StringSplit($sMsg, @CR, 3) Local $iRows = UBound($aAsciiLines) Local $aPanelLines[$iRows] Local $iTotChars = $iRows * $iColumns, $iMatches = 0, $sOutput = '' ; dimensions of the GUI based on Font Courier New 48 Local $iY = $iRows * 68, $iX = $iColumns * 38.33 $hGuiPanel = GUICreate('The talking oracle', $iX, $iY) Local $hPanel = GUICtrlCreateLabel('', 0, 0, $iX, $iY) GUICtrlSetFont(-1, 48, -1, -1, "Courier New") GUISetState() For $row = 0 To $iRows - 1 $aAsciiLines[$row] = StringToASCIIArray(StringFormat("%-" & $iColumns & "." & $iColumns & "s", $aAsciiLines[$row])) $aPanelLines[$row] = StringSplit(StringTrimRight(StringReplace(StringFormat('%' & $iColumns & 's', ""), ' ', '127,'), 1), ',', 3) ; 31 Next Do $iMatches = 0 For $row = 0 To UBound($aAsciiLines) - 1 For $col = 0 To $iColumns - 1 _SetInnerArray($aPanelLines[$row], $col, ($aPanelLines[$row])[$col] - (($aPanelLines[$row])[$col] <> ($aAsciiLines[$row])[$col])) $iMatches += (($aPanelLines[$row])[$col] = ($aAsciiLines[$row])[$col]) Next $sOutput &= StringFromASCIIArray($aPanelLines[$row]) & @CRLF Next ControlSetText('', '', $hPanel, $sOutput) $sOutput = '' Sleep(10) If GUIGetMsg() = -3 Then Exit Until $iMatches = $iTotChars Local $iTimer = TimerInit() Do If GUIGetMsg() = -3 Then Exit Until TimerDiff($iTimer) > (1000 * $iSeconds) GUIDelete($hGuiPanel) EndFunc ;==>_AsciiPanel ; to sets an element of an arry (within array) Func _SetInnerArray(ByRef $aArray, $iElement, $Value) $aArray[$iElement] = $Value EndFunc ;==>_SetInnerArray ; formats a long string within a column of n. chars without splitting words Func _StringColumn($sString, $x = 20) For $i = $x To StringLen($sString) Step $x $i = StringInStr($sString, " ", 0, -1, $i) If $i = 0 Then Return SetError(1, 0, "") $sString = StringReplace($sString, $i, @CR) Next If StringRight($sString, 1) = @CR Then $sString = StringTrimRight($sString, 1) Return $sString EndFunc ;==>_StringColumn Func _End() If WinActive("[ACTIVE]") = $hGuiPanel Then GUIDelete($hGuiPanel) Exit EndIf EndFunc ;==>_End Edited July 27, 2019 by Chimp t0nZ, RTFC and bolthead 3 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now