fillRect

fun Image.fillRect(x: Int, y: Int, width: Int, height: Int, color: Color)(source)

Sets every pixel of the rectangle width pixels wide and height pixels tall whose top-left corner is at column x and row y to color, alpha included, as Image.set does. Nothing is blended, so a transparent color clears the rectangle; Image.draw is the call that blends.

Coordinates are in pixels from the image's top-left corner. The parts of the rectangle outside the image are left out, so a rectangle that lies wholly outside, or has a width or height of 0, paints nothing. Pass width, height and color by name; x and y are a conventional pair.

Throws

Samples

val image = Image(8, 8)
image.fillRect(x = 2, y = 2, width = 4, height = 3, color = Color.WHITE)
assertPrints(image[2, 2], "Color(#ffffffff)")
assertPrints(image[5, 4], "Color(#ffffffff)")
assertPrints(image[6, 4], "Color(#00000000)")
// The part of a rectangle outside the image is left out.
image.fillRect(x = 6, y = 6, width = 10, height = 10, color = Color.RED)
assertPrints(image[7, 7], "Color(#ff0000ff)")
assertFailsWith<IllegalArgumentException> { image.fillRect(x = 0, y = 0, width = -1, height = 1, color = Color.RED) }