Drawing a polygon

Report a typo

Write a function that returns a buffered image of size 300x300. The image should have TYPE_INT_RGB color components, and it should contain a polygon drawn in this exact order:

  • the first point, at position (50, 150)

  • the second point, at position (100, 250)

  • the third point, at position (200, 250)

  • the fourth point, at position (250, 150)

  • the fifth point, at position (200, 50)

  • the sixth point, at position (100, 50)

The return value of the function should be a BufferedImage with the following content:

yellow hexagon on black background

Tip: Your task is to draw the polygon's outline by setting its color to Color.YELLOW.

Write a program in Kotlin
import java.awt.Color
import java.awt.image.BufferedImage

fun drawPolygon(): BufferedImage {
// Add your code here
}
___

Create a free account to access the full topic