Last active
December 18, 2020 14:53
-
-
Save AdrianoCelentano/b6bd7036bec615e63c8ea289bbe78cbf to your computer and use it in GitHub Desktop.
This file contains 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
@Composable | |
fun WaveClock() { | |
var radiusNoise = remember { Random.nextFloat() * 10 } | |
var xNoise = remember { Random.nextFloat() * 10 } | |
var yNoise = remember { Random.nextFloat() * 10 } | |
var angNoise = remember { Random.nextFloat() * 10 } | |
var strokeColor = 0f | |
var increaseColor = true | |
var angle = (-1 * PI) / 2 | |
Canvas(modifier = Modifier.fillMaxSize()) { | |
for (currentAngleStep in 0..360 step 1) { | |
radiusNoise += 0.005f | |
//Perlin Noise function comes from the Processing core lib | |
//https://android.processing.org/tutorials/android_studio/index.html | |
val radius = proNoise(radiusNoise) * 750 + 1 | |
angNoise += 0.005f | |
angle += proNoise(angNoise) * 1f | |
if (angle > 360) angle -= 360 | |
if (angle < 0) angle += 360 | |
xNoise += 0.01f | |
yNoise += 0.01f | |
val centerX = size.width / 2 + proNoise(xNoise) * 100 - 50 | |
val centerY = size.height / 2 + proNoise(yNoise) * 100 - 50 | |
val rad = angleToRadians(angle) | |
val x = centerX + (radius * cos(rad)) | |
val y = centerY + (radius * sin(rad)) | |
val opprad = rad + PI | |
val x2 = centerX + (radius * cos(opprad)) | |
val y2 = centerY + (radius * sin(opprad)) | |
if (increaseColor) strokeColor += 0.01f | |
else strokeColor -= 0.01f | |
val color = lerp(Color.Gray, Color.Transparent, strokeColor) | |
if (strokeColor > 0.9f) increaseColor = false | |
if (strokeColor < 0.1f) increaseColor = true | |
drawLine( | |
color, | |
Offset(x, y), | |
Offset(x2, y2), | |
1f | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment