Here’s what I’m aiming to include in the design:
A realistic layout for the upper and lower jaw. Proper spacing and alignment of teeth, mimicking human anatomy. Curved or rounded edges for the jaws and teeth to make it visually appealing. Ability to interact with individual teeth (if applicable).
I am developing an Android mobile application, and I am designing with Jetpack Compose. If I want to create a design similar to the one here, how can I do it?
@Composable fun TeethChartView(
isUpperJaw: Boolean,
modifier: Modifier = Modifier ) {
Canvas(
modifier = modifier
.fillMaxWidth()
.aspectRatio(1.2f) // Daha kare bir görünüm için aspect ratio'yu değiştirdik
) {
val teeth = generateTeethPositions(isUpperJaw, size)
teeth.forEachIndexed { index, toothPosition ->
drawToothShape(toothPosition, index + 1)
}
} }
private fun generateTeethPositions(isUpperJaw: Boolean, canvasSize: Size): List<Offset> {
val centerX = canvasSize.width / 2f
val centerY = if (isUpperJaw) canvasSize.height * 0.3f else canvasSize.height * 0.7f
// Yay yarıçapını artırdık ve daha eliptik bir form verdik
val radiusX = canvasSize.width * 0.35f
val radiusY = canvasSize.height * 0.25f
// Yay açılarını ayarladık
val startAngle = if (isUpperJaw) 180f else 0f
val endAngle = if (isUpperJaw) 360f else 180f
val numTeeth = 14 // Her çenede 14 diş
val teethPositions = mutableListOf<Offset>()
for (i in 0 until numTeeth) {
val angle = Math.toRadians((startAngle + i * (endAngle - startAngle) / (numTeeth - 1)).toDouble())
// Eliptik yay için x ve y koordinatlarını ayrı hesaplıyoruz
val x = centerX + radiusX * cos(angle).toFloat()
val y = centerY + radiusY * sin(angle).toFloat()
teethPositions.add(Offset(x, y))
}
return teethPositions }
private fun DrawScope.drawToothShape(position: Offset, toothNumber: Int) {
// Dişleri daha yuvarlak ve doğal yapıyoruz
val toothSize = size.width * 0.045f // Diş boyutunu canvas'a göre ayarlıyoruz
// Diş şekli için daha yuvarlak bir görünüm
drawRoundRect(
color = Color.White,
topLeft = Offset(
position.x - toothSize / 2,
position.y - toothSize / 2
),
size = Size(toothSize, toothSize),
cornerRadius = CornerRadius(toothSize / 2f, toothSize / 2f), // Daha yuvarlak köşeler
style = Fill
)
// Dış çerçeve
drawRoundRect(
color = Color.Gray,
topLeft = Offset(
position.x - toothSize / 2,
position.y - toothSize / 2
),
size = Size(toothSize, toothSize),
cornerRadius = CornerRadius(toothSize / 2f, toothSize / 2f),
style = Stroke(width = size.width * 0.002f) // İnce bir çerçeve
) }
Source: View source