Basic Canvas Drawing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ${your_package} | |
import androidx.compose.foundation.Canvas | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.layout.size | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.geometry.Offset | |
import androidx.compose.ui.geometry.Size | |
import androidx.compose.ui.graphics.Brush | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.graphics.drawscope.DrawStyle | |
import androidx.compose.ui.graphics.drawscope.Fill | |
import androidx.compose.ui.graphics.drawscope.Stroke | |
import androidx.compose.ui.tooling.preview.Preview | |
import androidx.compose.ui.unit.dp | |
@Composable | |
fun BasicDrawing(){ | |
Canvas( | |
modifier = Modifier | |
.padding(20.dp) | |
.size(300.dp) | |
) { | |
// 배경 | |
drawRect( | |
color = Color.Black, | |
size = size, | |
style = Fill | |
) | |
drawRect( | |
color = Color.Red, | |
topLeft = Offset(100f, 100f), | |
size = Size(100f, 100f), | |
style = Stroke( | |
width = 3.dp.toPx() | |
), | |
) | |
drawCircle( | |
brush = Brush.radialGradient( | |
colors = listOf(Color.Red, Color.Yellow), | |
center = center, | |
radius = 100f | |
), | |
radius = 100f, | |
) | |
drawArc( | |
color = Color.Green, | |
startAngle = 0f, | |
sweepAngle = 270f, | |
useCenter = false, | |
topLeft = Offset(100f, 500f), | |
size = Size(200f, 200f), | |
style = Stroke( | |
width = 3.dp.toPx() | |
) | |
) | |
drawOval( | |
color = Color.Magenta, | |
topLeft = Offset(500f, 100f), | |
size = Size(200f, 300f) | |
) | |
drawLine( | |
color = Color.Cyan, | |
start = Offset(300f, 700f), | |
end = Offset(700f, 700f), | |
strokeWidth = 5.dp.toPx() | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment