-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDraw Points.kt
108 lines (101 loc) · 3.14 KB
/
Draw Points.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package xyz.jayeshseth.canvasexample.canvas
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.PointMode
import androidx.compose.ui.unit.dp
@Composable
fun DrawPoints() {
val color = MaterialTheme.colorScheme.primary
val gradientColor =
listOf(MaterialTheme.colorScheme.primary, MaterialTheme.colorScheme.primaryContainer)
val canvasSize = 300.dp
val textModifier = Modifier
.fillMaxWidth()
.padding(16.dp)
val textStyle = MaterialTheme.typography.titleLarge
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(
state = rememberScrollState(),
)
.padding(bottom = 40.dp)
.navigationBarsPadding(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
text = "Points - Mode Polygon",
modifier = textModifier.statusBarsPadding(),
style = textStyle
)
Canvas(
modifier = Modifier
.size(canvasSize)
) {
val points = listOf(
Offset(size.width, 0f),
Offset(size.width, size.height),
Offset(0f, size.height),
Offset(size.width, 0f),
)
drawPoints(
points = points,
strokeWidth = 15f,
pointMode = PointMode.Polygon,
color = color,
)
}
Text(
text = "Points - Mode Point",
modifier = textModifier.statusBarsPadding(),
style = textStyle
)
Canvas(
modifier = Modifier
.size(canvasSize)
) {
val points = listOf(
Offset(size.width, 0f),
Offset(size.width, size.height),
Offset(0f, size.height),
Offset(size.width, 0f),
)
drawPoints(
points = points,
strokeWidth = 15f,
pointMode = PointMode.Points,
color = color,
)
}
Text(
text = "Points - Mode Lines",
modifier = textModifier.statusBarsPadding(),
style = textStyle
)
Canvas(
modifier = Modifier
.size(canvasSize)
) {
val points = listOf(
Offset(size.width, 0f),
Offset(size.width, size.height),
Offset(0f, size.height),
Offset(size.width, 0f),
)
drawPoints(
points = points,
strokeWidth = 15f,
pointMode = PointMode.Lines,
color = color,
)
}
}
}