Jump to content
Sign in to follow this  
NileshSutar

entering values in array

Recommended Posts

NileshSutar

Hi all,

i want to create an array that contains pixel colours. I want to scan a client area for all the colors it contains and enter all the colors  found(excluding duplicates) in an array called  $get_pix.color.So how can i do that??

Edited by NileshSutar

Share this post


Link to post
Share on other sites
NileshSutar

You cannot have a "." in a variable name.

They are used as operators in objects.

Show what code you have

The code is :

Func start_capture()
   For $i=$x1 To $x2 Step 1
      For $j=$y1 To $y2 Step 1
         For $s=0 To <??> Step 1; Don't know how many pixels will be  there. What to do?
             $pixel[$s] = PixelGetColor($i,$j,2)
         Next
      Next
   Next
EndFunc

Share this post


Link to post
Share on other sites
NileshSutar

 

The code is :

 

now i have modified it:

global $Area=($x2-$x1)*($y2-$y1)
global $x1
global $x2
global $y1
global $y2
Func start_capture()
   For $i=$x1 To $x2 Step 1
      For $j=$y1 To $y2 Step 1
         For $s=0 To $Area Step 1; Don't know how many pixels will be  there. What to do?
             $pixel[$s] = PixelGetColor($i,$j,2)
         Next
      Next
   Next
EndFunc

Share this post


Link to post
Share on other sites
JohnOne

Why not use a 2D array, for example...

#include <Array.au3>

$Width = 10
$Height = 10
$StartX = 0
$StartY = 0

Local $aPixels[$Height][$Width]

For $y = $StartY To $Height -1
    For $x = $StartX To $Width -1
        $aPixels[$y][$x] = "0x" & Hex(PixelGetColor($x,$y),6)
    Next
Next

_ArrayDisplay($aPixels) 

To make it more generic you need to apply a little maths logic.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
NileshSutar

Why not use a 2D array, for example...

#include <Array.au3>

$Width = 10
$Height = 10
$StartX = 0
$StartY = 0

Local $aPixels[$Height][$Width]

For $y = $StartY To $Height -1
    For $x = $StartX To $Width -1
        $aPixels[$y][$x] = "0x" & Hex(PixelGetColor($x,$y),6)
    Next
Next

_ArrayDisplay($aPixels) 

To make it more generic you need to apply a little maths logic.

i tested the code.I found that the coordinates $StartX and  $StartY must be zero for the script to run.Otherwise it will not five results.I figured out why this is happening but i am unable to change the code.So the $y and $x values are not zero when i set $StartX and $StartY to some non-zero.So as they are input to the pixel array the array is getting confused.We should some how set $y=0 and increament its value without affecting PixelGetColor($x,$y).

Share this post


Link to post
Share on other sites
NileshSutar

 

The start x and y can be whatever you want so long as you as add to it the width and height.

For $y = $StartY To $Height -1
      For $x = $StartX To $Width -1
         For $i=0 To ($Width-$StartX+1)*($Height-$StartY+1)  +1 
            $aPixels[$i] = ("0x" & Hex(PixelGetColor($x,$y))
         Next
     Next
     
   Next

I have made it like that but it is giving me an error "Array variable has incorrect number of subscripts or subscript dimension range exceeded"

Share this post


Link to post
Share on other sites
JohnOne

Look at the for loop, if start y is 300 and height is 20, the loop will be going from 300 to 20.

Hint

For $y = $StartY To ? + $Height -1

EDIT:

Apply reverse logic to your array.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
NileshSutar

Look at the for loop, if start y is 300 and height is 20, the loop will be going from 300 to 20.

Hint

For $y = $StartY To ? + $Height -1

EDIT:

Apply reverse logic to your array.

For $y = $StartY To $StartY + $Height -1;is it right
Edited by NileshSutar

Share this post


Link to post
Share on other sites
NileshSutar

John i think that the thing that is going wrong is the

$aPixels[$y][$x] = "0x" & Hex(PixelGetColor($x,$y),6)

When $y and $x are zero then there is no problem for $aPixels to take values in.But when $y and $x are non-zero the first element   should get 0 index(in array $aPixels) will be told to take $y index which is not zero. I think this is a big problem.

Edited by NileshSutar

Share this post


Link to post
Share on other sites
JohnOne

Off top of my head it'd be something like this

#include <Array.au3>

$Width = 10
$Height = 10
$StartX = 0
$StartY = 0

Local $aPixels[$Height][$Width]

For $y = $StartY To $StartY + $Height -1
    For $x = $StartX To $StartX + $Width -1
        $aPixels[$y - $StartY][$x - $StartX] = "0x" & Hex(PixelGetColor($x,$y),6)
    Next
Next

_ArrayDisplay($aPixels)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
NileshSutar

 

Off top of my head it'd be something like this

#include <Array.au3>

$Width = 10
$Height = 10
$StartX = 0
$StartY = 0

Local $aPixels[$Height][$Width]

For $y = $StartY To $StartY + $Height -1
    For $x = $StartX To $StartX + $Width -1
        $aPixels[$y - $StartY][$x - $StartX] = "0x" & Hex(PixelGetColor($x,$y),6)
    Next
Next

_ArrayDisplay($aPixels)

lol working. :dance::thumbsup::sweating:

Share this post


Link to post
Share on other sites
NileshSutar

Ace.

Just pop in a function now and use those non scoped vars as parameters.

Yes i did it.VERRY HAPPY.

THANKS.

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  

×