Skip to content

Instantly share code, notes, and snippets.

@azazellj
Created July 1, 2024 06:30
Show Gist options
  • Select an option

  • Save azazellj/ed4a7d95d9ccf5da78468cf1a451403c to your computer and use it in GitHub Desktop.

Select an option

Save azazellj/ed4a7d95d9ccf5da78468cf1a451403c to your computer and use it in GitHub Desktop.
Sakura
@Composable
internal fun FallItem(
painter: VectorPainter,
initialPositionX: Float,
initialPositionY: Float,
densityDpi: Float,
) {
val windWidth = 150 * densityDpi * if (Random.nextBoolean()) 1 else -1
val fallSpeed = (Random.nextFloat() * 2.66f + 0.33f) * densityDpi
val scale: Float = Random.nextFloat() * 0.66f + 0.33f
val alpha: Float = Random.nextFloat() * 0.7f + 0.2f
val infiniteTransition = rememberInfiniteTransition()
val positionX by infiniteTransition.animateFloat(
initialValue = initialPositionX,
targetValue = initialPositionX + windWidth,
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = Random.nextInt(5000) + 2000,
easing = FastOutSlowInEasing
),
repeatMode = RepeatMode.Reverse,
),
)
var positionY by remember { mutableStateOf(initialPositionY) }
val rotation by infiniteTransition.animateFloat(
initialValue = (Random.nextInt(150) + 30).toFloat(),
targetValue = (Random.nextInt(150) + 30).toFloat(),
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = Random.nextInt(5000) + 2000,
easing = FastOutSlowInEasing
),
repeatMode = RepeatMode.Reverse,
),
)
fun onFall(size: Size) {
positionY += fallSpeed
if (positionY > size.height) {
positionY = -painter.intrinsicSize.height
}
}
Canvas(
modifier = Modifier
.fillMaxSize()
) {
withTransform({
translate(
left = positionX,
top = positionY,
)
scale(scale, pivot = painter.intrinsicSize.center)
rotate(rotation, pivot = painter.intrinsicSize.center)
}) {
with(painter) {
draw(
size = painter.intrinsicSize,
alpha = alpha,
)
}
}
onFall(size)
}
}
fun leafLargeIcon(
defaultWidth: Dp = 60.dp,
defaultHeight: Dp = 60.dp,
viewportWidth: Float = 100f,
viewportHeight: Float = 100f,
) = ImageVector.Builder(
name = "leaf_new_1",
defaultWidth = defaultWidth,
defaultHeight = defaultHeight,
viewportWidth = viewportWidth,
viewportHeight = viewportHeight,
).apply {
path(
fill = SolidColor(Color(0xFFE9C2CD)),
pathBuilder = {
// M15.6,1.3
moveTo(15.6f, 1.3f)
// C1.7,43.4 31.8,80.7 70.9,98.7
curveTo(1.7f, 43.4f, 31.8f, 80.7f, 70.9f, 98.7f)
// C111,52.1 75.1,9.7 15.6,1.3z
curveTo(111f, 52.1f, 75.1f, 9.7f, 15.6f, 1.3f)
close()
},
)
path(
fill = SolidColor(Color(0xFFEA9AB6)),
pathBuilder = {
// M86,72.3
moveTo(86f, 72.3f)
// c2.1,-21.8 -33.2,-29.4 -49.8,-45.2
curveToRelative(2.1f, -21.8f, -33.2f, -29.4f, -49.8f, -45.2f)
// c6.5,8.1 6.3,24.8 -1.5,30.4
curveToRelative(6.5f, 8.1f, 6.3f, 24.8f, -1.5f, 30.4f)
// c0,0 9.9,0.6 9.9,-4.5
curveToRelative(0f, 0f, 9.9f, 0.6f, 9.9f, -4.5f)
// c12.5,10.4 12.3,38.2 12.3,38.2
// c12.5,10.4 12.3,38.2 12.3,38.2
curveToRelative(12.5f, 10.4f, 12.3f, 38.2f, 12.3f, 38.2f)
// l14,7.5
lineToRelative(14f, 7.5f)
// C72.4,99.6 87.6,73.2 86,72.3z
curveTo(72.4f, 99.6f, 87.6f, 73.2f, 86f, 72.3f)
close()
},
)
path(
fill = SolidColor(Color(0x00000000)),
stroke = SolidColor(Color(0xFF000000)),
strokeLineWidth = 2f,
pathBuilder = {
// M15.6,1.3
moveTo(15.6f, 1.3f)
// C75.1,9.7 111,52.1 70.9,98.7
curveTo(75.1f, 9.7f, 111f, 52.1f, 70.9f, 98.7f)
// C31.8,80.7 1.7,43.4 15.6,1.3z
curveTo(31.8f, 80.7f, 1.7f, 43.4f, 15.6f, 1.3f)
close()
},
)
path(
fill = SolidColor(Color(0xFF000000)),
pathBuilder = {
// M15.6,1.3
moveTo(15.6f, 1.3f)
// C24,28.4 44.8,29.2 56.9,68.4
curveTo(24f, 28.4f, 44.8f, 29.2f, 56.9f, 68.4f)
// c-7.7,-1.3 -15.6,-5.8 -22.9,-10.6
curveToRelative(-7.7f, -1.3f, -15.6f, -5.8f, -22.9f, -10.6f)
// c5.5,6 13,9.8 21.8,12.1
curveToRelative(5.5f, 6f, 13f, 9.8f, 21.8f, 12.1f)
// c1,0.3 1.6,0.6 2.5,1.7
curveToRelative(1f, 0.3f, 1.6f, 0.6f, 2.5f, 1.7f)
// c4.1,7.1 7.9,16.3 7.5,24.6
curveToRelative(4.1f, 7.1f, 7.9f, 16.3f, 7.5f, 24.6f)
// l5.2,2.6
lineToRelative(5.2f, 2.6f)
// c-0.4,-2.8 -19.6,-40.9 -15.6,-43
curveToRelative(-0.4f, -2.8f, -19.6f, -40.9f, -15.6f, -43f)
// c2.4,-6.2 8.2,-23 7.7,-25.5
curveToRelative(2.4f, -6.2f, 8.2f, -23f, 7.7f, -25.5f)
// c-1.3,5.2 -9.7,26.6 -9.5,26
curveToRelative(-1.3f, 5.2f, -9.7f, 26.6f, -9.5f, 26f)
// C51.1,48.6 36.3,26.5 35,25.8
curveTo(51.1f, 48.6f, 36.3f, 26.5f, 35f, 25.8f)
// C35,25.8 22.1,15 15.6,1.3
curveTo(35f, 25.8f, 22.1f, 15f, 15.6f, 1.3f)
// L15.6,1.3z
lineTo(15.6f, 1.3f)
close()
},
)
}.build()
fun leafSmallIcon(
defaultWidth: Dp = 60.dp,
defaultHeight: Dp = 60.dp,
viewportWidth: Float = 100f,
viewportHeight: Float = 100f,
) = ImageVector.Builder(
name = "leaf_new_2",
defaultWidth = defaultWidth,
defaultHeight = defaultHeight,
viewportWidth = viewportWidth,
viewportHeight = viewportHeight,
).apply {
path(
fill = SolidColor(Color(0xFFE5C2C8)),
pathBuilder = {
// M81.5,6.2
moveTo(81.5f, 6.2f)
// c-15.9,7.9 -30,18.8 -43.2,30.5
curveToRelative(-15.9f, 7.9f, -30f, 18.8f, -43.2f, 30.5f)
// C25.5,48 13.5,61.4 7.7,77.7
curveTo(25.5f, 48f, 13.5f, 61.4f, 7.7f, 77.7f)
// c-11.6,33 0.7,19.7 12.6,1
curveToRelative(-11.6f, 33f, 0.7f, 19.7f, 12.6f, 1f)
// c12.8,-17.3 22.9,-37.3 40.9,-49.9
curveToRelative(12.8f, -17.3f, 22.9f, -37.3f, 40.9f, -49.9f)
// C70.7,21.2 81,14.5 91.4,8.3
curveTo(70.7f, 21.2f, 81f, 14.5f, 91.4f, 8.3f)
// C101.5,-0.3 96.4,-1.2 81.5,6.2z
curveTo(101.5f, -0.3f, 96.4f, -1.2f, 81.5f, 6.2f)
close()
},
)
path(
fill = SolidColor(Color(0xFFE8A0B3)),
pathBuilder = {
// M47.4,36.1
moveTo(47.4f, 36.1f)
// c-8.1,10.7 -15.2,22.1 -25.3,31.2
curveToRelative(-8.1f, 10.7f, -15.2f, 22.1f, -25.3f, 31.2f)
// c-9.9,8 -13.2,19.8 -12.4,26.1
curveToRelative(-9.9f, 8f, -13.2f, 19.8f, -12.4f, 26.1f)
// c19,-24.3 32.4,-53.8 59.5,-70.6
curveToRelative(19f, -24.3f, 32.4f, -53.8f, 59.5f, -70.6f)
// C62.2,27.3 54.2,31.2 47.4,36.1
curveTo(62.2f, 27.3f, 54.2f, 31.2f, 47.4f, 36.1f)
// C47.5,36 47.5,36.1 47.4,36.1
curveTo(47.5f, 36f, 47.5f, 36.1f, 47.4f, 36.1f)
// L47.4,36.1z
lineTo(47.4f, 36.1f)
close()
},
)
path(
fill = SolidColor(Color(0x00000000)),
stroke = SolidColor(Color(0xFF000000)),
strokeLineWidth = 2f,
pathBuilder = {
// M81.5,6.2
moveTo(81.5f, 6.2f)
// c-15.9,7.9 -30,18.8 -43.2,30.5
curveToRelative(-15.9f, 7.9f, -30f, 18.8f, -43.2f, 30.5f)
// C25.5,48 13.5,61.4 7.7,77.7
curveTo(25.5f, 48f, 13.5f, 61.4f, 7.7f, 77.7f)
// c-11.6,33 0.7,19.7 12.6,1
curveToRelative(-11.6f, 33f, 0.7f, 19.7f, 12.6f, 1f)
// c12.8,-17.3 22.9,-37.3 40.9,-49.9
curveToRelative(12.8f, -17.3f, 22.9f, -37.3f, 40.9f, -49.9f)
// C70.7,21.2 81,14.5 91.4,8.3
curveTo(70.7f, 21.2f, 81f, 14.5f, 91.4f, 8.3f)
// C101.5,-0.3 96.4,-1.2 81.5,6.2
curveTo(101.5f, -0.3f, 96.4f, -1.2f, 81.5f, 6.2f)
// L81.5,6.2z
lineTo(81.5f, 6.2f)
close()
},
)
}.build()
fun footprintIcon(
defaultWidth: Dp = 24.dp,
defaultHeight: Dp = 24.dp,
viewportWidth: Float = 24f,
viewportHeight: Float = 24f,
) = ImageVector.Builder(
name = "footprint",
defaultWidth = defaultWidth,
defaultHeight = defaultHeight,
viewportWidth = viewportWidth,
viewportHeight = viewportHeight,
).apply {
path(
fill = SolidColor(Color(0xFF000000)),
pathBuilder = {
// M15.72,0.03
moveTo(15.72f, 0.03f)
// c-3.78,0.53 -4.97,7.35 -1.52,9.01
curveToRelative(-3.78f, 0.53f, -4.97f, 7.35f, -1.52f, 9.01f)
// C18.78,10.28 20.62,0.39 15.72,0.03z
curveTo(18.78f, 10.28f, 20.62f, 0.39f, 15.72f, 0.03f)
close()
},
)
path(
fill = SolidColor(Color(0xFF000000)),
pathBuilder = {
// M7.33,0.21
moveTo(7.33f, 0.21f)
// c-4.19,1.31 -2.08,9.15 2.03,8.86
curveToRelative(-4.19f, 1.31f, -2.08f, 9.15f, 2.03f, 8.86f)
// C13.61,7.94 11.54,-0.24 7.33,0.21z
curveTo(13.61f, 7.94f, 11.54f, -0.24f, 7.33f, 0.21f)
close()
},
)
path(
fill = SolidColor(Color(0xFF000000)),
pathBuilder = {
// M21.05,5.62
moveTo(21.05f, 5.62f)
// c-4.71,0.64 -4.42,12.68 1.07,9.2
curveToRelative(-4.71f, 0.64f, -4.42f, 12.68f, 1.07f, 9.2f)
// C24.48,12.82 25.12,5.88 21.05,5.62z
curveTo(24.48f, 12.82f, 25.12f, 5.88f, 21.05f, 5.62f)
close()
},
)
path(
fill = SolidColor(Color(0xFF000000)),
pathBuilder = {
// M2.45,6.1
moveTo(2.45f, 6.1f)
// c-4.61,1.12 -2.07,10.13 2.36,9
curveToRelative(-4.61f, 1.12f, -2.07f, 10.13f, 2.36f, 9f)
// C8.59,13.38 6.53,5.91 2.45,6.1z
curveTo(8.59f, 13.38f, 6.53f, 5.91f, 2.45f, 6.1f)
close()
},
)
path(
fill = SolidColor(Color(0xFF000000)),
pathBuilder = {
// M11.88,9.46
moveTo(11.88f, 9.46f)
// c-2.71,0.08 -2.97,3.34 -4.32,5.04
curveToRelative(-2.71f, 0.08f, -2.97f, 3.34f, -4.32f, 5.04f)
// c-0.84,1.85 -3.4,3.63 -3.26,5.87
curveToRelative(-0.84f, 1.85f, -3.4f, 3.63f, -3.26f, 5.87f)
// c0.1,4.07 4.16,3.72 6.98,2.86
curveToRelative(0.1f, 4.07f, 4.16f, 3.72f, 6.98f, 2.86f)
// c1.3,-0.1 2.75,0.14 3.96,0.57
curveToRelative(1.3f, -0.1f, 2.75f, 0.14f, 3.96f, 0.57f)
// c4.2,1.22 6.62,-4.57 3.75,-7.4
curveToRelative(4.2f, 1.22f, 6.62f, -4.57f, 3.75f, -7.4f)
// C17.42,14.53 14.56,9.28 11.88,9.46z
curveTo(17.42f, 14.53f, 14.56f, 9.28f, 11.88f, 9.46f)
close()
},
)
}.build()
@Composable
internal fun SplashScreenView() {
val density = LocalDensity.current.density
val painters = listOf(
rememberVectorPainter(leafLargeIcon()),
rememberVectorPainter(leafSmallIcon()),
)
BoxWithConstraints(
modifier = Modifier
.fillMaxSize(),
) {
repeat(100) {
FallItem(
painter = painters[Random.nextInt(painters.size)],
initialPositionX = this.maxWidth.value * density * Random.nextFloat(),
initialPositionY = this.maxHeight.value * density * Random.nextFloat(),
densityDpi = density,
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment