Форум для тех, кто программирует под Android
Anonymous
Как нарисовать очерченный треугольник Рело в Jetpack Compose Canvas?
Сообщение
Anonymous » 16 ноя 2024, 03:45
Я пытаюсь создать очерченный треугольник Рело с помощью Jetpack Compose.
Я пробую этот код:
Код: Выделить всё
@Composable
fun ReuleauxTriangle() {
Canvas(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
) {
val rect = Rect(Offset.Zero, size)
val trianglePath = Path().apply {
moveTo(rect.topCenter)
lineTo(rect.bottomRight)
lineTo(rect.bottomLeft)
close()
}
drawIntoCanvas { canvas ->
canvas.drawOutline(
outline = Outline.Generic(trianglePath),
paint = Paint().apply {
color = Color.Black
pathEffect = PathEffect.cornerPathEffect(rect.maxDimension / 3)
}
)
}
}
}
Помощники пути:
Код: Выделить всё
fun Path.moveTo(offset: Offset) = moveTo(offset.x, offset.y)
fun Path.lineTo(offset: Offset) = lineTo(offset.x, offset.y)
Результат | Ожидаемое
Как мне нарисовать ожидаемое ниже?
Подробнее здесь:
https://stackoverflow.com/questions/791 ... ose-canvas
1731717958
Anonymous
Я пытаюсь создать очерченный треугольник Рело с помощью Jetpack Compose. Я пробую этот код: [code]@Composable fun ReuleauxTriangle() { Canvas( modifier = Modifier .fillMaxWidth() .aspectRatio(1f) ) { val rect = Rect(Offset.Zero, size) val trianglePath = Path().apply { moveTo(rect.topCenter) lineTo(rect.bottomRight) lineTo(rect.bottomLeft) close() } drawIntoCanvas { canvas -> canvas.drawOutline( outline = Outline.Generic(trianglePath), paint = Paint().apply { color = Color.Black pathEffect = PathEffect.cornerPathEffect(rect.maxDimension / 3) } ) } } } [/code] Помощники пути: [code]fun Path.moveTo(offset: Offset) = moveTo(offset.x, offset.y) fun Path.lineTo(offset: Offset) = lineTo(offset.x, offset.y) [/code] Результат | Ожидаемое Как мне нарисовать ожидаемое ниже? Подробнее здесь: [url]https://stackoverflow.com/questions/79193325/how-to-draw-an-outlined-reuleaux-triangle-in-jetpack-compose-canvas[/url]