fillCircle

fun Image.fillCircle(centerX: Float, centerY: Float, radius: Float, color: Color)(source)

Paints a disc of radius pixels centered on (centerX, centerY) in color, over what the image already holds.

Coordinates are in pixels from the image's top-left corner, where pixel (x, y) covers the square from x to x + 1, so the center of a 16 by 16 image is (8, 8). Each pixel is covered by how far its center lies inside the circle's edge, from 0 at half a pixel outside to 1 at half a pixel inside, which gives the disc a soft edge one pixel wide. A fully covered pixel takes color; a partly covered one is blended over its old color by color's alpha times its coverage, so a disc painted on a transparent image keeps its color all the way to the edge. The parts of the disc outside the image are left out, and a radius of 0 paints nothing. Pass the Float parameters by name.

Throws

if radius is negative or not finite, or centerX or centerY is not finite.

Samples

val image = Image(16, 16)
image.fillCircle(centerX = 8f, centerY = 8f, radius = 6f, color = Color.WHITE)
assertPrints(image[8, 8], "Color(#ffffffff)")
assertPrints(image[0, 0], "Color(#00000000)")