Jump to content

Read file to 2D Array


 Share

Recommended Posts

This grabs pixel locations from a preset file, then draws them in different colors. It seems the load function is spectacularly slow, any suggestions for speeding that up would be welcomed.

Also if you reverse the X and Y coordinates in the setpixel it will draw it vertically and mirrored, yay math.

Loading.txt is attached = the preset file of the pixels for the string LOADING...

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$fromFile1 = _load("c:\test\LOADING.txt")

_DrawPicfromArray ($fromfile1)



Func _DrawPicfromArray($Srcarray)

$MAX = ubound($SrcArray) - 1
$Half = $MAX / 2


While 1
  Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    Local $D, $E



     For $i = 0 To $MAX
        $D = $SrcArray[$i][0]
        $E = $SrcArray[$i][1]
        _PixelSetColor($E , $D, 0xFFFFFF)
        next
    For $i = 0 To $Half
        random(0, $Max)
        $D = $SrcArray[$i][0]
        $E = $SrcArray[$i][1]
        _PixelSetColor($E, $D,0xFF0000)
        _HPSleep(100,0)
    Next
      For $i = $Half To $MAX
        $D = $SrcArray[$i][0]
        $E = $SrcArray[$i][1]
        _PixelSetColor($E, $D, 0x00FF00)
        _HPSleep(100,0)
    Next
    For $j = 0 to $Max * 100
        $i = random (0, $MAX)
        $D = $SrcArray[$i][0]
        $E = $SrcArray[$i][1]
        _PixelSetColor($E, $D, random(0x000000 , 0xFFFFFF))

    Next



  DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $dc[0])
WEnd
EndFunc

; Modified from http://www.autoitscript.com/forum/index.php?showtopic=7315&view=findpost&p=178779
Func _PixelSetColor($XCoord, $YCoord, $Color)
    Local $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    If Not IsArray($dc) Then Return -1
    DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $XCoord, "long", $YCoord, "long", _
            "0x" & StringRegExpReplace(hex($Color,6), "(..)(..)(..)", "\3\2\1")) ; Change to 0xBBGGRR hex colour format.
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $dc[0])
EndFunc ;==>_PixelSetColor

Func _HPSleep($iSleep, $fMs = 1)
    ; default is milliseconds, otherwise microseconds (1 ms = 1000 µs)
    If $fMs Then $iSleep *= 1000 ; convert to ms
    DllCall("ntdll.dll", "dword", "NtDelayExecution", "int", 0, "int64*", -10 * $iSleep)
EndFunc



Func _load($file)

    $J = 11008
    $H = 11008 / 2
    Dim $BArray [$H][2]
$file = fileopen ($file , 0)
for $K = 0 to $H - 1
$line = filereadline ($file)
$BArray[$K][0] = $line
$line = filereadline ($file)
$BArray[$K][1] = $line
Next

FileClose ($file)
Return $BArray
EndFunc

LOADING.txt

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Relevant remarks from FileReadLine help:

If no line number to read is given, the "next" line will be read. ("Next" for a newly opened file is initially the first line.)

...

From a performance standpoint it is a bad idea to read line by line specifying "line" parameter whose value is incrementing by one. This forces AutoIt to reread the file from the beginning until it reach the specified line.

Ergo: ditch those line parameters on your FileReadLine code to get up to normal speed.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Thank you sir, I would have never suspected that in a loop it would just remember where it left off. And the helpfile wins again.

edited first post reflects the much speedier version.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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