Skip to content

Instantly share code, notes, and snippets.

@Sardorbekcyber
Created February 9, 2022 11:31
Show Gist options
  • Save Sardorbekcyber/ebb396aed908fd39d97b6b2aedd5ecbf to your computer and use it in GitHub Desktop.
Save Sardorbekcyber/ebb396aed908fd39d97b6b2aedd5ecbf to your computer and use it in GitHub Desktop.
private class ColorWheel(diameter: Int) {
private val radius = diameter / 2f
private val sweepGradient = SweepGradientShader(
colors = listOf(
Color.Red, Color.Magenta, Color.Blue,
Color.Cyan, Color.Green, Color.Yellow, Color.Red
),
center = Offset(radius, radius)
)
private val radialGradient = RadialGradientShader(
center = Offset(radius, radius),
radius = radius,
colors = listOf(Color.White, Color.Transparent),
)
val image = ImageBitmap(diameter, diameter)
.also { bitmap ->
val canvas = Canvas(bitmap)
val center = Offset(radius, radius)
val paint = Paint().apply { shader = sweepGradient }
canvas.drawCircle(center, radius, paint)
val saturation = Paint().apply { shader = radialGradient }
canvas.drawCircle(center, radius, saturation)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment