Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val value = bytes[bytePosition]
- val height = (((value.toInt() and 0xFF).toFloat() - 128F) / 128F * 80)
- .coerceAtLeast(5F)
- Canvas(modifier = modifier) {
- if (bytes.isNotEmpty()) {
- val barWidthPx = BarWidth.toPx()
- val gapWidthPx = GapWidth.toPx()
- val barsCount = (size.width / (barWidthPx + (gapWidthPx / 2)))
- .toInt()
- .coerceIn(MIN_BARS_COUNT, MAX_BARS_COUNT)
- val div = bytes.size / barsCount
- val halfHeight = size.height / 2
- for (i in 0 until barsCount) {
- val bytePosition = i * div
- val value = bytes[bytePosition]
- val bottom = ((value.toInt() and 0xFF).toFloat() - 128F) / 128F * halfHeight
- val top = -bottom
- val x = i * ((barWidthPx + gapWidthPx) / 2)
- drawLine(
- brush = brush,
- start = Offset(x = x, y = bottom),
- end = Offset(x = x, y = top),
- strokeWidth = barWidthPx
- )
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement