Jump to content

Q: Want to return every color within a Grid.


Deviant
 Share

Recommended Posts

First Version

$startX = 300
$finishX = $startX
$starty = 200
$finishy = $starty

$file = FileOpen("test.txt", 1)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

Do
    Do
        $color = PixelGetColor ($finishX, $finishY)
        FileWrite($file, $color & @CRLF)
        $Finishy = $starty + 1
    Until $finishY = 350
    $FinishX = $startx + 1
Until $finishX = 450

FileClose($file)

Second Version

$file = FileOpen("test.txt", 1)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

For $x = 300 to 500
    For $y = 100 to 200
        $color = PixelGetColor ($X, $Y)
        FileWrite($file, $color & @CRLF)
    Next
Next

FileClose($file)

The 2nd version seems to be working better.

Any ideas on how to speed this up and filter the duplicate colors.

Thanks,

Edited by Deviant
Link to comment
Share on other sites

I was just wondering if it would be faster if I dumped it to an array. Then did some type of logic to pull the unique colors from the array.

Then I'd write those colors to the text file.

((if that makes since))

What I'm doing now is fairly fast, but I'd think it would be faster, if I dodn't write all the duplicates.

Is there a limitation on the length of a string? It wrote out some 500k values or so.

Link to comment
Share on other sites

Dim $area1x = 100

Dim $area1y = 100

Dim $area2x = 200

Dim $area2y = 200

Dim $x = $area2x - $area1x

Dim $y = $area2x - $area1x

Dim $myArray[$x][$y]

For $x = $area1x to $area2x

For $y = $area1y to $area2y

  $color = PixelGetColor ($x,$y)

  MsgBox(4096,"The Color is", $color)

  $myArray[$x][$y] = PixelGetColor ($x , $y) 

  MsgBox(4096,"The Array Value is", $myArray[$x][$y])

Next

Next

Can someone please explain to me, why this array doesn't work. I'm not sure my brain can handle much more.

Thanks.

Edited by Deviant
Link to comment
Share on other sites

When you give an array a size (Dim), you have to remember you can't use the same value.

I'll give a small example.

Dim $TestArr[2]
$TestArr[0] = "this is value number 1"
$TestArr[1] = "this is value number 2"

So if you want to define $TestArr[2], you'll have to do Dim $TestArr[2 + 1].

Dim $TestArr[2 + 1];OR Dim $TestArr[3]
$TestArr[0] = "this is value number 1"
$TestArr[1] = "this is value number 2"
$TestArr[2] = "this is value number 3"

Here's your code updated.

Dim $area1x = 100
Dim $area1y = 100
Dim $area2x = 200
Dim $area2y = 200
Dim $x = $area2x - $area1x
Dim $y = $area2x - $area1x
Dim $myArray[$x + 1][$y + 1]

For $x = $area1x to $area2x 
   For $y = $area1y to $area2y 
      $color = PixelGetColor ($x,$y)
      MsgBox(4096,"The Color is", $color)
      $myArray[$x][$y] = PixelGetColor ($x , $y)
      MsgBox(4096,"The Array Value is", $myArray[$x][$y])
   Next
Next
Edited by SlimShady
Link to comment
Share on other sites

When you give an array a size (Dim), you have to remember you can't use the same value.

I'll give a small example.

Dim $TestArr[2]
$TestArr[0] = "this is value number 1"
$TestArr[1] = "this is value number 2"

So if you want to define $TestArr[2], you'll have to do Dim $TestArr[2 + 1].

Dim $TestArr[2 + 1];OR Dim $TestArr[3]
$TestArr[0] = "this is value number 1"
$TestArr[1] = "this is value number 2"
$TestArr[2] = "this is value number 3"

Here's your code updated.

Dim $area1x = 100
Dim $area1y = 100
Dim $area2x = 200
Dim $area2y = 200
Dim $x = $area2x - $area1x
Dim $y = $area2x - $area1x
Dim $myArray[$x + 1][$y + 1]

For $x = $area1x to $area2x 
   For $y = $area1y to $area2y 
      $color = PixelGetColor ($x,$y)
      MsgBox(4096,"The Color is", $color)
      $myArray[$x][$y] = PixelGetColor ($x , $y)
      MsgBox(4096,"The Array Value is", $myArray[$x][$y])
   Next
Next

<{POST_SNAPBACK}>

The updated version you posted makes it through 1 loop then errors out.

I don't understand why I'd need to increment the value of x and y.

I want it to store the value of the color at 100/100 then the value at 101/101 etc.

If I increment as you have posted. The initial number would be 101/101 skipping the first row and column.

(mumbles)

Anyone have a virtual aspirin dispensor?

Edited by Deviant
Link to comment
Share on other sites

In fact to helping clarity and scripting more easily usually AutoIt use the pos[0] as a place where keep the size of the array - 1.

So in loops you can just say

For $c = 1 to $Array[0]

Instead of keeping the size elsewhere or asking for a Ubound everytime.

Moreover it is abstration for an array indexed from 1 to n where n is keeped in [0].

Usually starting from 1 makes counting and using easier.

Edited by ezzetabi
Link to comment
Share on other sites

Here is what I think should work. I am unable to test right now.

Dim $ax1 = 100
Dim $ay1 = 100
Dim $ax2 = 200
Dim $ay2 = 200
Dim $x = $ax1-$ax2
Dim $y = $ay1-$ay2
Dim $ColorArray[$x][$y]
Dim $color

While $x <= $ax2 AND $x > $ax1
   While $y <= $ay2 AND $y > $ay1
      $color = PixelGetColor($x, $y)
      $ColorArray[$x][$y] = $color
      MsgBox(0, "Array Value", $ColorArray[$x][$y])
      $x = $x + 1
      $y = $y + 1
   WEnd
WEnd

Please test it and let me know if it bugs out on you.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Here is what I think should work. I am unable to test right now.

Dim $ax1 = 100
Dim $ay1 = 100
Dim $ax2 = 200
Dim $ay2 = 200
Dim $x = $ax1-$ax2
Dim $y = $ay1-$ay2
Dim $ColorArray[$x][$y]
Dim $color

While $x <= $ax2 AND $x > $ax1
   While $y <= $ay2 AND $y > $ay1
      $color = PixelGetColor($x, $y)
      $ColorArray[$x][$y] = $color
      MsgBox(0, "Array Value", $ColorArray[$x][$y])
      $x = $x + 1
      $y = $y + 1
   WEnd
WEnd

Please test it and let me know if it bugs out on you.

JS

<{POST_SNAPBACK}>

Errors out on line 7

Array Subscript badly formatted, at the $x in the Dim $colorArray[x]

Which is one of the errors I tend to get, I'm really starting to get puzzled. (shrugs)

Edited by Deviant
Link to comment
Share on other sites

The code below works. It outputs the decimal value to a file called "test.txt" in the script directory. If you would like I can help you keep duplicates from being put in the file. It will take it a little longer to handle, but it could be done.

Dim $ax1 = 100
Dim $ay1 = 100
Dim $ax2 = 200
Dim $ay2 = 200
Dim $x = $ax2 - $ax1
Dim $y = $ay2 - $ay1
Dim $color

$file = FileOpen("test.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While $x <= $ax2
   While $y <= $ay2
      $color = PixelGetColor($x, $y)
      FileWriteLine($file, $color)
      $x = $x + 1
      $y = $y + 1
   WEnd
WEnd

FileClose($file)

Let me know how that works for you,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

The code below works. It outputs the decimal value to a file called "test.txt" in the script directory. If you would like I can help you keep duplicates from being put in the file. It will take it a little longer to handle, but it could be done.

Dim $ax1 = 100
Dim $ay1 = 100
Dim $ax2 = 200
Dim $ay2 = 200
Dim $x = $ax2 - $ax1
Dim $y = $ay2 - $ay1
Dim $color

$file = FileOpen("test.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While $x <= $ax2
   While $y <= $ay2
      $color = PixelGetColor($x, $y)
      FileWriteLine($file, $color)
      $x = $x + 1
      $y = $y + 1
   WEnd
WEnd

FileClose($file)

Let me know how that works for you,

JS

<{POST_SNAPBACK}>

The 2nd version in the script here does the same. That wasn't the issue at hand. I'm trying to speed the script up. So I was going to sort to an array, which I would check against conditions.

Mainly I'm just puzzled why my array example doesn't work. I need someone to fill in the gap.

Link to comment
Share on other sites

I will keep working on the array as well. I am not sure why it isnt working. The helpfile doesnt explain array's very much or how to use them.

How slow is the above script for you? That took all of like 1 second for me to run.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Nice way to put it into an array Larry. Can you see any problems with our above arrays? (I am sorry I didnt understand your above post with either similar or the same code).

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

The problem with loading straight into an array is Checking For Duplicates. You would have to cycle through the array... By keeping it into a string, you can check for duplicates and ignore them. If he is counting colors he can use my method. If he is storing pixel info, he can use a full array...

Lar.

<{POST_SNAPBACK}>

I'll give your first example a shot as soon as I can.

I plan on storing the color data in memory for more manipulations.

This is still in reference to my other questions regarding finding colors of a moveable moving object. My plan is to find every color within the grid, then ignore the colors I know aren't what I need.

But my first problem was trying to get the array to work.

Link to comment
Share on other sites

I tested it and I posted below in the picture my results... Maybe I need a more gfx intensive page to see what it would really do...

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

I tested it and I posted below in the picture my results... Maybe I need a more gfx intensive page to see what it would really do...

<{POST_SNAPBACK}>

I minimized everything and let it hit against the grassy hill picture that comes with windows xp.

This code took 491.22 seconds to find 10780 colors. So a little bit over 8 minutes.

$a = TimerStart()

$colorlist = "*"

For $x = 200 to 650
  For $y = 150 to 350
     $color = PixelGetColor($x,$y)
     If Not StringInStr($colorlist,"*" & $color & "*") Then _
        $colorlist = $colorlist & $color & "*"
  Next
Next

$colorlist = StringTrimLeft(StringTrimRight($colorlist,1),1)
$colorlist = StringSplit($colorlist,"*")

MsgBox(4096,(TimerDiff($a)/1000) & " seconds","I found " & _
            $colorlist[0] & " different colors")
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...