Deviant Posted November 16, 2004 Share Posted November 16, 2004 (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 November 16, 2004 by Deviant Link to comment Share on other sites More sharing options...
Deviant Posted November 16, 2004 Author Share Posted November 16, 2004 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 More sharing options...
ezzetabi Posted November 16, 2004 Share Posted November 16, 2004 15. What are the current technical limits of AutoIt v3? String length: 2,147,483,647 characters Link to comment Share on other sites More sharing options...
Deviant Posted November 16, 2004 Author Share Posted November 16, 2004 (edited) Dim $area1x = 100Dim $area1y = 100Dim $area2x = 200Dim $area2y = 200Dim $x = $area2x - $area1xDim $y = $area2x - $area1xDim $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]) NextNextCan someone please explain to me, why this array doesn't work. I'm not sure my brain can handle much more.Thanks. Edited November 16, 2004 by Deviant Link to comment Share on other sites More sharing options...
SlimShady Posted November 16, 2004 Share Posted November 16, 2004 (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 November 16, 2004 by SlimShady Link to comment Share on other sites More sharing options...
Deviant Posted November 16, 2004 Author Share Posted November 16, 2004 (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 November 16, 2004 by Deviant Link to comment Share on other sites More sharing options...
ezzetabi Posted November 16, 2004 Share Posted November 16, 2004 (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 November 16, 2004 by ezzetabi Link to comment Share on other sites More sharing options...
JSThePatriot Posted November 16, 2004 Share Posted November 16, 2004 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 More sharing options...
Deviant Posted November 16, 2004 Author Share Posted November 16, 2004 (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 WEndPlease test it and let me know if it bugs out on you.JS<{POST_SNAPBACK}>Errors out on line 7Array 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 November 16, 2004 by Deviant Link to comment Share on other sites More sharing options...
JSThePatriot Posted November 16, 2004 Share Posted November 16, 2004 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 More sharing options...
Deviant Posted November 17, 2004 Author Share Posted November 17, 2004 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 More sharing options...
JSThePatriot Posted November 18, 2004 Share Posted November 18, 2004 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 More sharing options...
JSThePatriot Posted November 18, 2004 Share Posted November 18, 2004 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 More sharing options...
Deviant Posted November 18, 2004 Author Share Posted November 18, 2004 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 More sharing options...
Deviant Posted November 18, 2004 Author Share Posted November 18, 2004 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. Link to comment Share on other sites More sharing options...
JSThePatriot Posted November 18, 2004 Share Posted November 18, 2004 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 More sharing options...
Deviant Posted November 19, 2004 Author Share Posted November 19, 2004 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 More sharing options...
Mr.Wizard Posted November 19, 2004 Share Posted November 19, 2004 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. Link to comment Share on other sites More sharing options...
SlimShady Posted November 19, 2004 Share Posted November 19, 2004 This works: dim $colours[255][255][255] Link to comment Share on other sites More sharing options...
Mr.Wizard Posted November 19, 2004 Share Posted November 19, 2004 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. 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