Advertisement
Kostiggig

Untitled

Aug 14th, 2024
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.84 KB | None | 0 0
  1. EntityRelationsAppTheme {
  2. val scope = rememberCoroutineScope()
  3. val red = Color(0xFFFF7F4D)
  4. val gray = Color(0xFF34343C).copy(alpha = 0.12f)
  5. var start by remember {
  6. mutableStateOf(-1)
  7. }
  8. LaunchedEffect(key1 = Unit) {
  9. while (scope.isActive) {
  10. delay(150)
  11. start = if (start == -1) 0 else -1
  12. }
  13. }
  14. Canvas(
  15. Modifier
  16. .padding(top = 100.dp)
  17. .border(1.dp, Color.Black)
  18. .padding(10.dp)
  19. .fillMaxWidth()
  20. .height(40.dp)
  21. .clip(RoundedCornerShape(12.dp))
  22. .background(red)
  23. ) {
  24. val step = 10.dp // line width
  25. val angleDegrees = 35f // todo adjust depending on roundedCornerShape
  26. val stepPx = step.toPx()
  27. val stepsCount = (size.width / stepPx).roundToInt()
  28. val actualStep = size.width / stepsCount
  29. val dotSize = Size(width = actualStep, height = size.height * 2)
  30. for (i in start..stepsCount step 2) {
  31. val rect = Rect(
  32. offset = Offset(x = i * actualStep, y = (size.height - dotSize.height) / 2),
  33. size = dotSize,
  34. )
  35. rotate(angleDegrees, pivot = rect.center) {
  36. drawRect(
  37. gray,
  38. topLeft = rect.topLeft,
  39. size = rect.size,
  40. )
  41. }
  42. }
  43. }
  44. // Canvas(
  45. // modifier = Modifier
  46. // .padding(20.dp)
  47. // .background(Color.Transparent)
  48. // .size(166.dp, 166.dp)
  49. // ) {
  50. // drawCircle(
  51. // Color.Gray,
  52. // blendMode = androidx.compose.ui.graphics.BlendMode.DstOver
  53. // )
  54. // drawIntoCanvas {
  55. // val paintRed = Color.Red
  56. // val paintBlack = Color.Black
  57. // val lineWidth = with(dens) {
  58. // 7.dp
  59. // .toPx()
  60. // .toInt()
  61. // }
  62. //
  63. // // Draw red and black lines with mixing effect
  64. // var x = 0f
  65. // var y = 0f
  66. // var color = 0
  67. // while (y < size.height) {
  68. // drawLine(
  69. // color = if (color % 2 == 0) paintRed else paintBlack,
  70. // start = Offset(0f, y),
  71. // end = Offset(x, 0f),
  72. // strokeWidth = 5.dp.toPx()
  73. // )
  74. // y += lineWidth
  75. // x += lineWidth
  76. // color = color.xor(1)
  77. // }
  78. // x = 0f
  79. // y = 0f
  80. // while (y < size.height) {
  81. // drawLine(
  82. // color = if (color % 2 == 0) paintRed else paintBlack,
  83. // start = Offset(x, size.height),
  84. // end = Offset(size.width, y),
  85. // strokeWidth = 5.dp.toPx(),
  86. // blendMode = androidx.compose.ui.graphics.BlendMode.DstOut
  87. // )
  88. // y += lineWidth
  89. // x += lineWidth
  90. // color = color.xor(1)
  91. // }
  92. // }
  93. // }
  94. Box(
  95. modifier = Modifier
  96. .padding(20.dp)
  97. .background(Color.Transparent)
  98. // .size(166.dp, 166.dp)
  99. // .size(
  100. // width = 166.dp,
  101. // height = 56.dp
  102. // )
  103. // .drawBehind {
  104. // drawLine(
  105. // Color.Black,
  106. // start = Offset(0f, this.size.center.y),
  107. // end = Offset(this.size.width, this.size.center.y),
  108. // strokeWidth = 2f
  109. // )
  110. // }
  111. // .clip(RoundedCornerShape(16.dp))
  112. // .clip(RoundedCornerShape(16.dp))
  113. // .drawBehind {
  114. // val paintRed = Color.Red
  115. // val paintBlack = Color.Black
  116. // val lineWidth = with(dens) {
  117. // 5.dp
  118. // .toPx()
  119. // .toInt()
  120. // }
  121. //
  122. // // Draw red and black lines with mixing effect
  123. // var x = 0f
  124. // var y = 0f
  125. // var color = 0
  126. // while (y < size.height) {
  127. // val rect = Rect(
  128. // offset = Offset(0f, y),
  129. // size = Size(size.width, lineWidth.toFloat())
  130. // )
  131. // drawRect(
  132. // color = if (color % 2 == 0) paintRed else paintBlack,
  133. // topLeft = rect.topLeft,
  134. // size = rect.size,
  135. // )
  136. //
  137. //// drawLine(
  138. //// color = if (color % 2 == 0) paintRed else paintBlack,
  139. //// start = Offset(0f, y),
  140. //// end = Offset(size.width, y),
  141. //// strokeWidth = lineWidth.toFloat()
  142. //// )
  143. // y += lineWidth
  144. // color = color.xor(1)
  145. // }
  146. // }
  147. // .drawBehind {
  148. // val paintRed = Color.Red
  149. // val paintBlack = Color.Black
  150. // val lineWidth = with(dens) {
  151. // 7.dp
  152. // .toPx()
  153. // .toInt()
  154. // }
  155. //
  156. // // Draw red and black lines with mixing effect
  157. // var x = 0f
  158. // var y = 0f
  159. // var color = 0
  160. // while (y < size.height) {
  161. // drawLine(
  162. // color = if (color % 2 == 0) paintRed else paintBlack,
  163. // start = Offset(0f, y),
  164. // end = Offset(x, 0f),
  165. // strokeWidth = 5.dp.toPx()
  166. // )
  167. // y += lineWidth
  168. // x += lineWidth
  169. // color = color.xor(1)
  170. // }
  171. // x = 0f
  172. // y = 0f
  173. // while (y < size.height) {
  174. // drawLine(
  175. // color = if (color % 2 == 0) paintRed else paintBlack,
  176. // start = Offset(x, size.height),
  177. // end = Offset(size.width, y),
  178. // strokeWidth = 5.dp.toPx()
  179. // )
  180. // y += lineWidth
  181. // x += lineWidth
  182. // color = color.xor(1)
  183. // }
  184. // }
  185. // .drawBehind {
  186. // drawCircle(
  187. // color = Color.Blue,
  188. // blendMode = androidx.compose.ui.graphics.BlendMode.DstOut
  189. // )
  190. // }
  191. // .drawBehind {
  192. // val lineWidth = with(dens) { 7.dp.toPx() } // Line width
  193. // val lineColor = Color.Red
  194. // val maxLines = ((size.width + size.height) / (2 * lineWidth)).toInt() // Number of lines based on diagonal coverage
  195. //
  196. // var color = 0
  197. // for (i in 0 until maxLines) {
  198. // val offset = i * lineWidth
  199. // if (offset <= size.width && offset <= size.height) {
  200. // drawLine(
  201. // color = if (color % 2 == 0) lineColor else Color.Black,
  202. // start = Offset(0f, offset),
  203. // end = Offset(offset, 0f),
  204. // strokeWidth = lineWidth
  205. // )
  206. // }
  207. //
  208. // if (offset <= size.width && offset <= size.height) {
  209. // drawLine(
  210. // color = if (color % 2 == 0) lineColor else Color.Black,
  211. // start = Offset(size.width - offset, size.height),
  212. // end = Offset(size.width, size.height - offset),
  213. // strokeWidth = lineWidth
  214. // )
  215. // }
  216. //
  217. // color = color.xor(1)
  218. // }
  219. // }
  220. // .drawBehind {
  221. // val paintRed = Color.Red
  222. // val paintBlack = Color.Black
  223. // val step = 10.dp
  224. // val angleDegrees = 45f
  225. // val stepPx = step.toPx()
  226. // val stepsCount = (size.width / stepPx).roundToInt()
  227. // val actualStep = size.width / stepsCount
  228. // val dotSize = Size(width = actualStep / 2, height = size.height * 2)
  229. // var color = 0
  230. // for (i in -1..stepsCount) {
  231. // val rect = Rect(
  232. // offset = Offset(
  233. // x = i * actualStep,
  234. // y = (size.height - dotSize.height) / 2
  235. // ),
  236. // size = dotSize,
  237. // )
  238. // rotate(angleDegrees, pivot = rect.center) {
  239. // drawRect(
  240. // color = if (color % 2 == 0) paintRed else paintBlack,
  241. // topLeft = rect.topLeft,
  242. // size = rect.size,
  243. // )
  244. // }
  245. // color = color.xor(1)
  246. // }
  247. // }
  248. // .drawBehind {
  249. // val lineWidth = with(dens) { 7.dp.toPx() } // Line width
  250. // val paintRed = Color.Red
  251. // val paintBlack = Color.Black
  252. //
  253. // val numLinesWidth = (size.width / lineWidth).toInt()
  254. // val numLinesHeight = (size.height / lineWidth).toInt()
  255. //
  256. // for (i in 0 until numLinesWidth + numLinesHeight) {
  257. // val offset = i * lineWidth
  258. //
  259. // // Draw lines from bottom-left to top-right
  260. // if (offset <= size.width) {
  261. // drawLine(
  262. // color = if (i % 2 == 0) paintRed else paintBlack,
  263. // start = Offset(offset, 0f),
  264. // end = Offset(0f, offset),
  265. // strokeWidth = lineWidth
  266. // )
  267. // }
  268. // if (offset <= size.height) {
  269. // drawLine(
  270. // color = if (i % 2 == 0) paintRed else paintBlack,
  271. // start = Offset(0f, offset),
  272. // end = Offset(offset, 0f),
  273. // strokeWidth = lineWidth
  274. // )
  275. // }
  276. //
  277. // // Draw lines from top-left to bottom-right
  278. // if (offset <= size.width) {
  279. // drawLine(
  280. // color = if (i % 2 == 0) paintRed else paintBlack,
  281. // start = Offset(size.width - offset, 0f),
  282. // end = Offset(size.width, offset),
  283. // strokeWidth = lineWidth
  284. // )
  285. // }
  286. // if (offset <= size.height) {
  287. // drawLine(
  288. // color = if (i % 2 == 0) paintRed else paintBlack,
  289. // start = Offset(size.width, size.height - offset),
  290. // end = Offset(size.width - offset, size.height),
  291. // strokeWidth = lineWidth
  292. // )
  293. // }
  294. // }
  295. // }
  296.  
  297. // .drawBehind {
  298. // val paintRed = Color.Red
  299. // val paintBlack = Color.Black
  300. // val lineWidth = with(dens) { 7.dp.toPx().toInt() }
  301. //
  302. // // Draw red and black lines with mixing effect
  303. // var x = 0f
  304. // var y = 0f
  305. // var color = 0
  306. // while(y < size.height) {
  307. // drawLine(
  308. // color = if (color % 2 == 0) paintRed else paintBlack,
  309. // start = Offset(0f, y),
  310. // end = Offset(x, 0f),
  311. // strokeWidth = 5.dp.toPx()
  312. // )
  313. // y += lineWidth
  314. // x += lineWidth
  315. // color = color.xor(1)
  316. // }
  317. // }
  318.  
  319. )
  320. // Canvas(modifier = Modifier.fillMaxSize()) {
  321. // drawIntoCanvas { canvas ->
  322. // var clr = 0
  323. // for (x in 0 until size.width.toInt()) {
  324. // canvas.drawLine(
  325. // p1 = Offset(x.toFloat(), 0f),
  326. // p2 = Offset(0f, x.toFloat()),
  327. // paint = Paint().apply {
  328. // color = if (clr % 2 == 0) Color.Red else Color.Black
  329. // strokeWidth = 4f
  330. // }
  331. // )
  332. // clr = clr.xor(1)
  333. // }
  334. // }
  335. // }
  336. }
  337. }
  338. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement