Skip to content

Instantly share code, notes, and snippets.

@programmerAbc
Created February 1, 2023 10:04
Show Gist options
  • Select an option

  • Save programmerAbc/8cef89f0fd98c84550917f73a2883299 to your computer and use it in GitHub Desktop.

Select an option

Save programmerAbc/8cef89f0fd98c84550917f73a2883299 to your computer and use it in GitHub Desktop.
compose wave slider
@Composable
fun WaveSlider() {
var progress by remember { mutableStateOf(0f) }
var phase by remember { mutableStateOf(0.0) }
LaunchedEffect(true) {
try {
while (true) {
delay(30)
if (phase >= 10.0) {
phase = 0.0
}
phase += 0.002
}
} catch (e: Exception) {
}
}
Box(modifier = Modifier.fillMaxSize().padding(30.dp)) {
Slider(
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colors.primary,
disabledThumbColor = MaterialTheme.colors.onSurface
.copy(alpha = ContentAlpha.disabled)
.compositeOver(MaterialTheme.colors.surface),
activeTrackColor = Color(0),
inactiveTrackColor = Color(0),
disabledActiveTrackColor =
Color(0),
disabledInactiveTrackColor =
Color(0),
activeTickColor = Color(0),
inactiveTickColor = Color(0),
disabledActiveTickColor = Color(0),
disabledInactiveTickColor = Color(0)
),
value = progress,
onValueChange = { progress = it },
modifier = Modifier.fillMaxWidth()
.height(10.dp)
.align(Alignment.Center)
.drawBehind {
var yOffset = size.height / 2
val step = 5.0
var x1 = 0.0
var y1 = 0.0 + yOffset
val t = size.width / 10
val w = 2 * Math.PI / t
val a = 10
var x2 = 0.0
var y2 = 0.0
while (x1 < size.width * progress) {
x2 = x1 + step
y2 = a * Math.sin(w * x2 + phase * t) + yOffset
drawLine(
color = Color(0xfff93684),
start = Offset(x1.toFloat(), y1.toFloat()),
end = Offset(x2.toFloat(), y2.toFloat()),
strokeWidth = 5f
)
x1 = x2
y1 = y2
}
drawLine(
color = Color(0xfff93684),
start = Offset(size.width * progress, yOffset),
end = Offset(size.width, yOffset),
strokeWidth = 5f
)
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment