Created
February 9, 2022 11:31
-
-
Save Sardorbekcyber/ebb396aed908fd39d97b6b2aedd5ecbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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