Pixel

A pixel is a single dot of color in a picture.

It contains an x and y location, with (0, 0) at the top left of the picture.

It contains a color object which has red, green, and blue values between 0 and 255 (inclusive).

Example Usage

myBluePixel = Pixel(0, 0, red=0, green=0, blue=255)
pixels = picture.getPixels()
pixels[0] = myBluePixel

Initialization

Pixel.Pixel(self, x, y, red, green, blue)
Parameters:
  • x (int) – horizontal location of pixel.
  • y (int) – vertical location of pixel.
  • red (int) – degree of redness of pixel. Between 0 and 255 inclusive.
  • green (int) – degree of greenness of pixel. Between 0 and 255 inclusive.
  • blue (int) – degree of blueness of pixel. Between 0 and 255 inclusive.

Methods

Getters

Return the x value of a pixel.

Pixel.getX(self)
pixel = picture.getPixel(200, 10)

# This will print 200.
print(pixel.getX())

Return the y value of a pixel.

Pixel.getY(self)
pixel = picture.getPixel(200, 10)

# This will print 10.
print(pixel.getY())

This function returns the Color object of the pixel.

Pixel.getColor(self)
color = pixel.getColor()

These functions return the red, green, and blue values of the pixel.

Pixel.getRed(self)
red = pixel.getRed()
Pixel.getGreen(self)
green = pixel.getGreen()
Pixel.getBlue(self)
blue = pixel.getBlue()

Setters

These functions allow you to set the color values of a pixel.

Pixel.setRed(self, red)
Parameters:red (int) – between 0 and 255 (inclusive).
pixel.setRed(red)
Pixel.setGreen(self, green)
Parameters:green (int) – between 0 and 255 (inclusive).
pixel.setGreen(green)
Pixel.setBlue(self, blue)
Parameters:blue (int) – between 0 and 255 (inclusive).
pixel.setBlue(blue)

Table Of Contents