Post by SleipOdin on Jan 29, 2005 16:57:13 GMT -5
Since most of the information for this function is scattered through different threads and replies, I figured I'd just compile it all here. This post will hopefully clear up your confusion on implementing this function.
i. Getting a Screenshot
ii. Getting an x,y Coordinate
iii. Getting The Color Code
iv. Syntax of PixelGetColor()
A pixel is, at least on a computer screen, a square block of color. Thousands of these blocks make up what you see on your screen. If you have a 1024x768 resolution, then you have 1024 columns of 768 of these color blocks, and 768 rows of 1024 blocks. This is why increasing your resolution makes things look "better", but smaller...it's because more blocks need to fit on the same screen, so their area is smaller.
You will need two pieces of information to use this fucntion correctly. The first is the x,y coordinate of the pixel that you're requesting information from. The second is the actual color of that pixel. In the latter part, I'll briefly explain the Hexidecimal number system for those that are unfamiliar with it.
i. Getting a Screenshot
First and foremost, you will need a screenshot of the situation that you're trying to replicate with a script, whether in be a line of text in the chat log, or the name of a mob on your targetting window. To do this, you'll need a third party program to save the image. I personally use Fraps (unsure of a URL), but others have recommended Cipper as well. You simply run this program in the background, enter the game, and press some F-key to take a screenshot. Done.
ii. Getting an x,y Coordinate
You'll now need to know the position of the pixels you're trying to examine. People recommend graphics software to get this information. While they're nice, they can often be overcomplicated for simple users. I'm fairly confident that anyone reading this has at least opened MSPaint once, so let's use that, as everyone (probably) has it. Go to Start->Programs->Accesories->Paint to open the application. Find and open your image through the File menu, and hopefully you should be looking at your nice little screenshot. Zoom in to your specific area to see the pixels up close and personal, then switch to the "Free-Form Select" tool. You won't actually be using it, but it has a precise cursor so you can see exactly what pixel you're getting information for. When you've hovered over your target pixel, look in the lower-right corner, and there's your x,y coordinate!
iii. Getting The Color Code
Last, but certainly not least, you'll need to know the color of the pixel for comparison. The best way that I've found to do this is to select the Eyedropper tool. Click and DRAG the approximate area where your target pixel is. As you move your cursor around, you will see colors appear on the left bar...these are the colors of the pixels you're dragging over. Once you get the correct color, simply left go of the mouse button. NOTE: If you need to try again, Paint will default back to the last tool that you used (Pencil maybe?), so be sure to reselect the Eyedropper. Your color is now recognized in Paint. Along the top bar, go to Colors->Edit Colors..., then most of the way down the dialog, select 'Define Custom Colors >>'. You will see a colorfield and more nifty stuff, but the only thing you need to be concerned about are the 'Red', 'Green' and 'Blue' values. Write them down.
At this point, if you know how the hex number system works, skip the next paragraph. Otherwise, keep reading for a quick lesson in computer science.
When we were all kids, we were taught to count in something called base-10. That means, when you count after 0...9, you're taught to add another digit, and start over. 9 turns into 10...19 turns into 20...99 turns into 100, etc. This is called base-10 because you're simply recycling after every 10 numbers. Hexidecimal is exactly the same, except that it is base-16. People that work with computers like hex because many things in a computer are binary (0s and 1s, so they have 2 values), and 16 is a power of 2. Instead of 10, you have A...instead of 11, you have B...etc, up to 15 being F. Once you get to 16, you cycle through again. Here are some very simple examples:
DEC <--> HEX
1 1
2 2
3 3
...
9 9
10 A
11 B
12 C
13 D
14 E
15 F
16 10 (notice how the second place digit just increased by 1)
17 11
...
159 99
160 A0 (again, the left digit was increased 1...from 9 to A)
161 A1
...
255 FF
256 100 (this is 16*16...you add another digit on any power of 16)
Hopefully now you have a vague notion of what hex is, and can understand this next part a little easier.
You now have three numbers, in RGB format. For those of you that don't know, RGB values range from 0 to 255, where 0 is no color, and 255 is 100% of that color. Red, green and blue can combine to make tons of colors. I'll be using a nice teal color that I use in my game as an example (R=43 G=154 B=147). We now need to convert these three values to hexidecimal. This can easily be done by going to Start->Programs->Accesories->Calculator, then selecting 'Scientific' from the 'View' menu. To convert from DEC to HEX, simply type your number in (43 for the red component of my teal color), then go to View->Hex (F5). Success! The calculator now shows '2B', which is the hex value for '43'. Write this number down. Switch back to decimal by going to View-> Decimal (F6), clear the calculator, and repeat with your other two numbers (154 converted to 9A and 147 converted to 93). You now need to convert one more time, but in the reverse order. Make sure your calculator is in HEX, and enter your 6 digits in RGB order. Since we got Red=2B Blue=9A Green=93, our calculator should show '2B9A93'. Once that is in, switch back to DEC, and you have your color code! For the teal example, we get 2857619.
To summarize this last part: Get RGB values, convert each value to HEX, concatenate (squish) the three values in RGB order, then convert back to decimal.
iv. Syntax of PixelGetColor()
Well, congratulations if you've made it this far...you're past the hard stuff. You just need to know how to use the function. PixelGetColor(x,y) takes two values, your x and y coordinates, and returns the color code of that pixel. Therefore, if you wanted to get the pixel color at position 42,42, you'd simply type:
$colorCodeAtPosition = PixelGetColor(42,42)
; $colorCodeAtPosition now contains the color code at 42,42
That's all there is to it!
I hope this has helped...feel free to comment as needed!^^
i. Getting a Screenshot
ii. Getting an x,y Coordinate
iii. Getting The Color Code
iv. Syntax of PixelGetColor()
A pixel is, at least on a computer screen, a square block of color. Thousands of these blocks make up what you see on your screen. If you have a 1024x768 resolution, then you have 1024 columns of 768 of these color blocks, and 768 rows of 1024 blocks. This is why increasing your resolution makes things look "better", but smaller...it's because more blocks need to fit on the same screen, so their area is smaller.
You will need two pieces of information to use this fucntion correctly. The first is the x,y coordinate of the pixel that you're requesting information from. The second is the actual color of that pixel. In the latter part, I'll briefly explain the Hexidecimal number system for those that are unfamiliar with it.
i. Getting a Screenshot
First and foremost, you will need a screenshot of the situation that you're trying to replicate with a script, whether in be a line of text in the chat log, or the name of a mob on your targetting window. To do this, you'll need a third party program to save the image. I personally use Fraps (unsure of a URL), but others have recommended Cipper as well. You simply run this program in the background, enter the game, and press some F-key to take a screenshot. Done.
ii. Getting an x,y Coordinate
You'll now need to know the position of the pixels you're trying to examine. People recommend graphics software to get this information. While they're nice, they can often be overcomplicated for simple users. I'm fairly confident that anyone reading this has at least opened MSPaint once, so let's use that, as everyone (probably) has it. Go to Start->Programs->Accesories->Paint to open the application. Find and open your image through the File menu, and hopefully you should be looking at your nice little screenshot. Zoom in to your specific area to see the pixels up close and personal, then switch to the "Free-Form Select" tool. You won't actually be using it, but it has a precise cursor so you can see exactly what pixel you're getting information for. When you've hovered over your target pixel, look in the lower-right corner, and there's your x,y coordinate!
iii. Getting The Color Code
Last, but certainly not least, you'll need to know the color of the pixel for comparison. The best way that I've found to do this is to select the Eyedropper tool. Click and DRAG the approximate area where your target pixel is. As you move your cursor around, you will see colors appear on the left bar...these are the colors of the pixels you're dragging over. Once you get the correct color, simply left go of the mouse button. NOTE: If you need to try again, Paint will default back to the last tool that you used (Pencil maybe?), so be sure to reselect the Eyedropper. Your color is now recognized in Paint. Along the top bar, go to Colors->Edit Colors..., then most of the way down the dialog, select 'Define Custom Colors >>'. You will see a colorfield and more nifty stuff, but the only thing you need to be concerned about are the 'Red', 'Green' and 'Blue' values. Write them down.
At this point, if you know how the hex number system works, skip the next paragraph. Otherwise, keep reading for a quick lesson in computer science.
When we were all kids, we were taught to count in something called base-10. That means, when you count after 0...9, you're taught to add another digit, and start over. 9 turns into 10...19 turns into 20...99 turns into 100, etc. This is called base-10 because you're simply recycling after every 10 numbers. Hexidecimal is exactly the same, except that it is base-16. People that work with computers like hex because many things in a computer are binary (0s and 1s, so they have 2 values), and 16 is a power of 2. Instead of 10, you have A...instead of 11, you have B...etc, up to 15 being F. Once you get to 16, you cycle through again. Here are some very simple examples:
DEC <--> HEX
1 1
2 2
3 3
...
9 9
10 A
11 B
12 C
13 D
14 E
15 F
16 10 (notice how the second place digit just increased by 1)
17 11
...
159 99
160 A0 (again, the left digit was increased 1...from 9 to A)
161 A1
...
255 FF
256 100 (this is 16*16...you add another digit on any power of 16)
Hopefully now you have a vague notion of what hex is, and can understand this next part a little easier.
You now have three numbers, in RGB format. For those of you that don't know, RGB values range from 0 to 255, where 0 is no color, and 255 is 100% of that color. Red, green and blue can combine to make tons of colors. I'll be using a nice teal color that I use in my game as an example (R=43 G=154 B=147). We now need to convert these three values to hexidecimal. This can easily be done by going to Start->Programs->Accesories->Calculator, then selecting 'Scientific' from the 'View' menu. To convert from DEC to HEX, simply type your number in (43 for the red component of my teal color), then go to View->Hex (F5). Success! The calculator now shows '2B', which is the hex value for '43'. Write this number down. Switch back to decimal by going to View-> Decimal (F6), clear the calculator, and repeat with your other two numbers (154 converted to 9A and 147 converted to 93). You now need to convert one more time, but in the reverse order. Make sure your calculator is in HEX, and enter your 6 digits in RGB order. Since we got Red=2B Blue=9A Green=93, our calculator should show '2B9A93'. Once that is in, switch back to DEC, and you have your color code! For the teal example, we get 2857619.
To summarize this last part: Get RGB values, convert each value to HEX, concatenate (squish) the three values in RGB order, then convert back to decimal.
iv. Syntax of PixelGetColor()
Well, congratulations if you've made it this far...you're past the hard stuff. You just need to know how to use the function. PixelGetColor(x,y) takes two values, your x and y coordinates, and returns the color code of that pixel. Therefore, if you wanted to get the pixel color at position 42,42, you'd simply type:
$colorCodeAtPosition = PixelGetColor(42,42)
; $colorCodeAtPosition now contains the color code at 42,42
That's all there is to it!
I hope this has helped...feel free to comment as needed!^^