Surface.getPixel
From Spheriki
Gets the colour of the pixel at the given coordinates of the surface.
Contents |
Usage
- Surface Sphere Surface object. The surface to get the pixel from.
- x Number, non-negative. The x coordinate of the pixel on the surface.
- y Number, non-negative. The y coordinate of the pixel on the surface.
- Color is returned, which is a Sphere Color object containing the colour of the chosen pixel.
Examples
const S_WIDTH = 100;
const S_HEIGHT = 100;
function game()
{
var msg = "";
var c1 = CreateColor(100, 100, 100);
var c2 = CreateColor(200, 200, 200);
var s = CreateSurface(S_WIDTH, S_HEIGHT, c1);
var col;
s.setPixel(20, 30, c2);
col = s.getPixel(20, 30);
msg += "c1 = " + color_to_str(c1) + "\n";
msg += "c2 = " + color_to_str(c2) + "\n";
msg += "col = " + color_to_str(col) + "\n";
Abort(msg);
}
function color_to_str(c)
{
var str = "{";
str += "r:" + c.red;
str += ",g:" + c.green;
str += ",b:" + c.blue;
str += "}";
return str;
}
This example first creates a surface with the colour contained in c1 as the background. One pixel at coordinates (20, 30) is set to a lighter shade, represented as c2. Finally, we pick that same pixel, grab the colour there, and display all three colours. We can see which colour the chosen pixel matches.
Notes
- This function will also choose the alpha at that point on the surface, which may not always be maxed at 255.
See also
- Sphere Surface object
- Sphere Color object
- Abort()
- CreateColor()