Hi. How can I apply gradient from start to end of an arc only? I want to draw an arc like the image and animate it to rotate in a circle
❤️ 1
c
Colton Idle
08/11/2021, 3:38 PM
I asked a similar question in the past and got an answer of
"you can draw the path with a sweepGradient with the starting and ending colors being the faded/non faded colors respectively"
I looked at my code and I didn't end up working with a sweep for some reason, but chose a linear gradient instead.
Copy code
drawPath(
path = path,
brush =
Brush.linearGradient(
colorStops =
arrayOf(
0.1f to Color(0x00ff0000),
.2f to Color(0xFFff0000),
.8f to Color(0xFFff0000),
.9f to Color(0x00ff0000),
),
),
t
Tash
08/11/2021, 9:36 PM
you could do the same with
sweepGradient
by making sure color stops are passed instead of just a list of colors
Copy code
Brush.sweepGradient(
0.0f to Color.Red,
0.3f to Color.Green,
1.0f to Color.Blue,
center = Offset(0.0f, 100.0f)
)
Tash
08/11/2021, 9:38 PM
sweepGradient
helps especially if you want the leading edge to go back to the starting color when it completes the arc
today i learned 2
t
Tin Tran
08/12/2021, 6:17 AM
Thanks guys! I ended up export the circle vector and animate the rotation 😅. I’ll try your solution to night.