0% found this document useful (0 votes)
5 views2 pages

radar-with-lines

Uploaded by

anas farhad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

radar-with-lines

Uploaded by

anas farhad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package com.faras.rider.ui.

rating

import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.keyframes
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.drawscope.rotate
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import kotlin.math.PI
import kotlin.math.absoluteValue
import kotlin.math.sin

@Composable
fun RadarAnimation(modifier: Modifier = Modifier) {
var rotationAngle by remember { mutableStateOf(0f) }
var pulseRadius by remember { mutableStateOf(0f) }

LaunchedEffect(Unit) {
while (true) {
delay(16) // Approx. 60 FPS
rotationAngle += 1f
}
}

RadarCanvas(
modifier = Modifier.size(300.dp),
rotationAngle = rotationAngle,
// pulseRadius = pulseRadius
)

@Composable
fun RadarCanvas(
modifier: Modifier = Modifier,
rotationAngle: Float
) {
Canvas(modifier = modifier.size(140.dp)) {
val midPoint = size.width / 2f // Center of the canvas
val circleRadius = size.width / 2f - 1.dp.toPx() // Adjust for border width

// Draw the border of the circle


drawCircle(
color = Color(0xFF48A651).copy(0.2f), // Deeper green border
radius = circleRadius,
center = Offset(midPoint, midPoint),
style = Stroke(width = 1.dp.toPx())
)

// Create the pie slice path


val path = Path().apply {
moveTo(midPoint, midPoint) // Start at the center
arcTo(
rect = Rect(
left = midPoint - circleRadius,
top = midPoint - circleRadius,
right = midPoint + circleRadius,
bottom = midPoint + circleRadius
),
startAngleDegrees = -90f,
sweepAngleDegrees = 90f,
forceMoveTo = false
)
close() // Close the path to form the pie slice
}

// Create a linear gradient brush for the pie slice


val gradientBrush = Brush.linearGradient(
colors = listOf(
Color.Green.copy(alpha = 0f), // Fully transparent
Color.Green.copy(alpha = 0.5f), // Partially transparent
Color.Green // Full color
),
start = Offset(midPoint, midPoint), // Start at the center
end = Offset(midPoint + circleRadius, midPoint) // End at the edge
)

// Draw the rotating pie slice inside the circle


rotate(rotationAngle, pivot = Offset(midPoint, midPoint)) {
drawPath(
path = path,
brush = gradientBrush
)
}
}
}

You might also like