https://kotlinlang.org logo
#compose
Title
# compose
v

Vsevolod Ganin

11/07/2020, 1:00 AM
I think
RadialGradient
is not working properly as of alpha06. I want to draw a simple circle that have white color from center to
0.5 * radius
and then have a uniform blend from white to black from
0.5 * radius
to
radius
. What I did is
Copy code
Canvas(modifier = Modifier.fillMaxSize()) {
    drawCircle(
        brush = RadialGradient(
            0.0f to Color.White,
            0.5f to Color.White,
            1.0f to Color.Black,
            centerX = center.x,
            centerY = center.y,
            radius = size.width
        )
    )
}
This code displays the whole circle in white.
n

Nader Jawad

11/07/2020, 5:43 AM
I think the issue is the radius of the Radial gradient is set to
size.width
instead of
size.width / 2
Copy code
Canvas(modifier = Modifier.fillMaxSize()) {
            drawCircle(
                brush = RadialGradient(
                    0.0f to Color.White,
                    0.5f to Color.White,
                    1.0f to Color.Black,
                    centerX = center.x,
                    centerY = center.y,
                    radius = size.width / 2 // changed from size.width
                )
            )
        }
👍 3
The code above generates the following image
v

Vsevolod Ganin

11/07/2020, 10:22 AM
My bad! Thank you!
3 Views