Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EntityRelationsAppTheme {
- val scope = rememberCoroutineScope()
- val red = Color(0xFFFF7F4D)
- val gray = Color(0xFF34343C).copy(alpha = 0.12f)
- var start by remember {
- mutableStateOf(-1)
- }
- LaunchedEffect(key1 = Unit) {
- while (scope.isActive) {
- delay(150)
- start = if (start == -1) 0 else -1
- }
- }
- Canvas(
- Modifier
- .padding(top = 100.dp)
- .border(1.dp, Color.Black)
- .padding(10.dp)
- .fillMaxWidth()
- .height(40.dp)
- .clip(RoundedCornerShape(12.dp))
- .background(red)
- ) {
- val step = 10.dp // line width
- val angleDegrees = 35f // todo adjust depending on roundedCornerShape
- val stepPx = step.toPx()
- val stepsCount = (size.width / stepPx).roundToInt()
- val actualStep = size.width / stepsCount
- val dotSize = Size(width = actualStep, height = size.height * 2)
- for (i in start..stepsCount step 2) {
- val rect = Rect(
- offset = Offset(x = i * actualStep, y = (size.height - dotSize.height) / 2),
- size = dotSize,
- )
- rotate(angleDegrees, pivot = rect.center) {
- drawRect(
- gray,
- topLeft = rect.topLeft,
- size = rect.size,
- )
- }
- }
- }
- // Canvas(
- // modifier = Modifier
- // .padding(20.dp)
- // .background(Color.Transparent)
- // .size(166.dp, 166.dp)
- // ) {
- // drawCircle(
- // Color.Gray,
- // blendMode = androidx.compose.ui.graphics.BlendMode.DstOver
- // )
- // drawIntoCanvas {
- // val paintRed = Color.Red
- // val paintBlack = Color.Black
- // val lineWidth = with(dens) {
- // 7.dp
- // .toPx()
- // .toInt()
- // }
- //
- // // Draw red and black lines with mixing effect
- // var x = 0f
- // var y = 0f
- // var color = 0
- // while (y < size.height) {
- // drawLine(
- // color = if (color % 2 == 0) paintRed else paintBlack,
- // start = Offset(0f, y),
- // end = Offset(x, 0f),
- // strokeWidth = 5.dp.toPx()
- // )
- // y += lineWidth
- // x += lineWidth
- // color = color.xor(1)
- // }
- // x = 0f
- // y = 0f
- // while (y < size.height) {
- // drawLine(
- // color = if (color % 2 == 0) paintRed else paintBlack,
- // start = Offset(x, size.height),
- // end = Offset(size.width, y),
- // strokeWidth = 5.dp.toPx(),
- // blendMode = androidx.compose.ui.graphics.BlendMode.DstOut
- // )
- // y += lineWidth
- // x += lineWidth
- // color = color.xor(1)
- // }
- // }
- // }
- Box(
- modifier = Modifier
- .padding(20.dp)
- .background(Color.Transparent)
- // .size(166.dp, 166.dp)
- // .size(
- // width = 166.dp,
- // height = 56.dp
- // )
- // .drawBehind {
- // drawLine(
- // Color.Black,
- // start = Offset(0f, this.size.center.y),
- // end = Offset(this.size.width, this.size.center.y),
- // strokeWidth = 2f
- // )
- // }
- // .clip(RoundedCornerShape(16.dp))
- // .clip(RoundedCornerShape(16.dp))
- // .drawBehind {
- // val paintRed = Color.Red
- // val paintBlack = Color.Black
- // val lineWidth = with(dens) {
- // 5.dp
- // .toPx()
- // .toInt()
- // }
- //
- // // Draw red and black lines with mixing effect
- // var x = 0f
- // var y = 0f
- // var color = 0
- // while (y < size.height) {
- // val rect = Rect(
- // offset = Offset(0f, y),
- // size = Size(size.width, lineWidth.toFloat())
- // )
- // drawRect(
- // color = if (color % 2 == 0) paintRed else paintBlack,
- // topLeft = rect.topLeft,
- // size = rect.size,
- // )
- //
- //// drawLine(
- //// color = if (color % 2 == 0) paintRed else paintBlack,
- //// start = Offset(0f, y),
- //// end = Offset(size.width, y),
- //// strokeWidth = lineWidth.toFloat()
- //// )
- // y += lineWidth
- // color = color.xor(1)
- // }
- // }
- // .drawBehind {
- // val paintRed = Color.Red
- // val paintBlack = Color.Black
- // val lineWidth = with(dens) {
- // 7.dp
- // .toPx()
- // .toInt()
- // }
- //
- // // Draw red and black lines with mixing effect
- // var x = 0f
- // var y = 0f
- // var color = 0
- // while (y < size.height) {
- // drawLine(
- // color = if (color % 2 == 0) paintRed else paintBlack,
- // start = Offset(0f, y),
- // end = Offset(x, 0f),
- // strokeWidth = 5.dp.toPx()
- // )
- // y += lineWidth
- // x += lineWidth
- // color = color.xor(1)
- // }
- // x = 0f
- // y = 0f
- // while (y < size.height) {
- // drawLine(
- // color = if (color % 2 == 0) paintRed else paintBlack,
- // start = Offset(x, size.height),
- // end = Offset(size.width, y),
- // strokeWidth = 5.dp.toPx()
- // )
- // y += lineWidth
- // x += lineWidth
- // color = color.xor(1)
- // }
- // }
- // .drawBehind {
- // drawCircle(
- // color = Color.Blue,
- // blendMode = androidx.compose.ui.graphics.BlendMode.DstOut
- // )
- // }
- // .drawBehind {
- // val lineWidth = with(dens) { 7.dp.toPx() } // Line width
- // val lineColor = Color.Red
- // val maxLines = ((size.width + size.height) / (2 * lineWidth)).toInt() // Number of lines based on diagonal coverage
- //
- // var color = 0
- // for (i in 0 until maxLines) {
- // val offset = i * lineWidth
- // if (offset <= size.width && offset <= size.height) {
- // drawLine(
- // color = if (color % 2 == 0) lineColor else Color.Black,
- // start = Offset(0f, offset),
- // end = Offset(offset, 0f),
- // strokeWidth = lineWidth
- // )
- // }
- //
- // if (offset <= size.width && offset <= size.height) {
- // drawLine(
- // color = if (color % 2 == 0) lineColor else Color.Black,
- // start = Offset(size.width - offset, size.height),
- // end = Offset(size.width, size.height - offset),
- // strokeWidth = lineWidth
- // )
- // }
- //
- // color = color.xor(1)
- // }
- // }
- // .drawBehind {
- // val paintRed = Color.Red
- // val paintBlack = Color.Black
- // val step = 10.dp
- // val angleDegrees = 45f
- // val stepPx = step.toPx()
- // val stepsCount = (size.width / stepPx).roundToInt()
- // val actualStep = size.width / stepsCount
- // val dotSize = Size(width = actualStep / 2, height = size.height * 2)
- // var color = 0
- // for (i in -1..stepsCount) {
- // val rect = Rect(
- // offset = Offset(
- // x = i * actualStep,
- // y = (size.height - dotSize.height) / 2
- // ),
- // size = dotSize,
- // )
- // rotate(angleDegrees, pivot = rect.center) {
- // drawRect(
- // color = if (color % 2 == 0) paintRed else paintBlack,
- // topLeft = rect.topLeft,
- // size = rect.size,
- // )
- // }
- // color = color.xor(1)
- // }
- // }
- // .drawBehind {
- // val lineWidth = with(dens) { 7.dp.toPx() } // Line width
- // val paintRed = Color.Red
- // val paintBlack = Color.Black
- //
- // val numLinesWidth = (size.width / lineWidth).toInt()
- // val numLinesHeight = (size.height / lineWidth).toInt()
- //
- // for (i in 0 until numLinesWidth + numLinesHeight) {
- // val offset = i * lineWidth
- //
- // // Draw lines from bottom-left to top-right
- // if (offset <= size.width) {
- // drawLine(
- // color = if (i % 2 == 0) paintRed else paintBlack,
- // start = Offset(offset, 0f),
- // end = Offset(0f, offset),
- // strokeWidth = lineWidth
- // )
- // }
- // if (offset <= size.height) {
- // drawLine(
- // color = if (i % 2 == 0) paintRed else paintBlack,
- // start = Offset(0f, offset),
- // end = Offset(offset, 0f),
- // strokeWidth = lineWidth
- // )
- // }
- //
- // // Draw lines from top-left to bottom-right
- // if (offset <= size.width) {
- // drawLine(
- // color = if (i % 2 == 0) paintRed else paintBlack,
- // start = Offset(size.width - offset, 0f),
- // end = Offset(size.width, offset),
- // strokeWidth = lineWidth
- // )
- // }
- // if (offset <= size.height) {
- // drawLine(
- // color = if (i % 2 == 0) paintRed else paintBlack,
- // start = Offset(size.width, size.height - offset),
- // end = Offset(size.width - offset, size.height),
- // strokeWidth = lineWidth
- // )
- // }
- // }
- // }
- // .drawBehind {
- // val paintRed = Color.Red
- // val paintBlack = Color.Black
- // val lineWidth = with(dens) { 7.dp.toPx().toInt() }
- //
- // // Draw red and black lines with mixing effect
- // var x = 0f
- // var y = 0f
- // var color = 0
- // while(y < size.height) {
- // drawLine(
- // color = if (color % 2 == 0) paintRed else paintBlack,
- // start = Offset(0f, y),
- // end = Offset(x, 0f),
- // strokeWidth = 5.dp.toPx()
- // )
- // y += lineWidth
- // x += lineWidth
- // color = color.xor(1)
- // }
- // }
- )
- // Canvas(modifier = Modifier.fillMaxSize()) {
- // drawIntoCanvas { canvas ->
- // var clr = 0
- // for (x in 0 until size.width.toInt()) {
- // canvas.drawLine(
- // p1 = Offset(x.toFloat(), 0f),
- // p2 = Offset(0f, x.toFloat()),
- // paint = Paint().apply {
- // color = if (clr % 2 == 0) Color.Red else Color.Black
- // strokeWidth = 4f
- // }
- // )
- // clr = clr.xor(1)
- // }
- // }
- // }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement