Sign in to follow this  
Followers 0
iamtheky

Saving every location that is not <color>

1 post in this topic

#1 ·  Posted (edited)

I can pick out all of a single color and save those locations, as the example should do for RED(FF0000).

I would like to know if there are any keen ways of determining all items in the array NOT (FF0000), so i can draw the inverse.

Thanks

#include <Array.au3>

Global $RED
Global $ALL[1]
Global $Columns[1]
Global $SAVEFILE = "c:\test\TEST.txt"
Global $IMAGE = "TEST.bmp"

$loading = _PicToArray($IMAGE, 400)

_findcolor ($loading, "FF0000")

_save($ALL , $SAVEFILE)


Func _PicToArray($pic, $size)
    Dim $BArray[$size][$size]
SplashImageOn("", $pic , $size, $size, 0, 0, 1)
For $B = 0 To ubound ($BArray, 1) - 1
    For $C = 0 To ubound ($BArray, 2) - 1
        $BArray[$B][$C] = "0x" & Hex(PixelGetColor($B + 1, $C + 1), 6)
    Next
Next
splashoff ()
Return $BArray
EndFunc

Func _findcolor ($SrcArray, $Color)

For $i = 0 TO Ubound ($SrcArray) - 1
$RED = _ArrayFindAll ($SrcArray , $Color , 0 , 0 ,0 ,1, $i)

For $k = 0 to ubound ($RED) - 1
    _ArrayAdd ($Columns , $i)
    Next

_ArrayConcatenate ($ALL , $RED)
Next

EndFUnc


Func _save($SrcArray , $FileName)
$pixFile = fileopen ($FileName , 2)

For $i = 1 to ubound ($All) - 1
    filewriteline ($pixFile , $Columns[$i])
        filewriteline ($pixFile , $ALL[$i])
    Next

FileClose ($pixFile)
EndFunc

Draws from the saved text file:

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


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

$TOP = ubound ($fromfile1) / 2

ReDim $fromfile1[$TOP][2]

_DrawPicfromArray ($fromfile1)



Func _DrawPicfromArray($Srcarray)

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

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

    For $j = 0 to $Max * 10
        $i = random (0, $MAX)
        $D = $SrcArray[$i][0]
        $E = $SrcArray[$i][1]
        _PixelSetColor($E, $D, random(0x000000 , 0xFFFFFF))
    Next


     For $i = 0 To $MAX - 1
        $D = $SrcArray[$i][0]
        $E = $SrcArray[$i][1]
        _PixelSetColor($E + 400 , $D , 0xFFFFFF)
    next

    For $z = 0 To $Half
        $D = $SrcArray[$z][0]
        $E = $SrcArray[$z][1]
        _PixelSetColor($E + 400 , $D ,0xFF0000)
        _HPSleep(100,0)
    Next

      For $x = $Half To $MAX - 1
        $D = $SrcArray[$x][0]
        $E = $SrcArray[$x][1]
        _PixelSetColor($E + 400, $D , 0x00FF00)
        _HPSleep(100,0)
    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)

$Num = _FileCountLines ($file)

msgbox (0, '' , $num)

$J = $Num
    $H = $Num / 2
    Dim $BArray [$J][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

Edited by iamtheky

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0