Advertisement
rvinter

Untitled

Dec 22nd, 2023
1,256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.17 KB | None | 0 0
  1.  
  2.                 val value = bytes[bytePosition]
  3.                 val height = (((value.toInt() and 0xFF).toFloat() - 128F) / 128F * 80)
  4.                     .coerceAtLeast(5F)
  5.  
  6.     Canvas(modifier = modifier) {
  7.         if (bytes.isNotEmpty()) {
  8.             val barWidthPx = BarWidth.toPx()
  9.             val gapWidthPx = GapWidth.toPx()
  10.  
  11.             val barsCount = (size.width / (barWidthPx + (gapWidthPx / 2)))
  12.                 .toInt()
  13.                 .coerceIn(MIN_BARS_COUNT, MAX_BARS_COUNT)
  14.  
  15.             val div = bytes.size / barsCount
  16.             val halfHeight = size.height / 2
  17.  
  18.             for (i in 0 until barsCount) {
  19.                 val bytePosition = i * div
  20.                 val value = bytes[bytePosition]
  21.  
  22.                 val bottom = ((value.toInt() and 0xFF).toFloat() - 128F) / 128F * halfHeight
  23.                 val top = -bottom
  24.  
  25.                 val x = i * ((barWidthPx + gapWidthPx) / 2)
  26.  
  27.                 drawLine(
  28.                     brush = brush,
  29.                     start = Offset(x = x, y = bottom),
  30.                     end = Offset(x = x, y = top),
  31.                     strokeWidth = barWidthPx
  32.                 )
  33.             }
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement