Sign in to follow this  
Followers 0
Deviant

Q: Want to return every color within a Grid.

25 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

15. What are the current technical limits of AutoIt v3?

String length: 2,147,483,647 characters

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Share this post


Link to post
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)

Share this post


Link to post
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.

Share this post


Link to post
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)

Share this post


Link to post
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)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Larry with your first example, it took 10.8 seconds to find 1381 different colors.

When the closer to the real size. 200-600x and 150-350y. the script sits in limbo and never returns an answer.

Share this post


Link to post
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)

Share this post


Link to post
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")

Share this post


Link to post
Share on other sites

I tried to write my own colour counting code and it won't let me create this array:

dim $colours[256][256][256]

it says "Array maximum size exceeded". That sucks.


I have a catapult. Give me all the money or I will fling an enormous rock at your head.

Share this post


Link to post
Share on other sites

This works:

dim $colours[255][255][255]

Share this post


Link to post
Share on other sites

Should this be a bug report or a feature request or...?


I have a catapult. Give me all the money or I will fling an enormous rock at your head.

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