1+ package dev.baseio.composeplayground.ui.animations
2+ 3+ import androidx.compose.animation.core.*
4+ import androidx.compose.foundation.Image
5+ import androidx.compose.foundation.background
6+ import androidx.compose.foundation.layout.*
7+ import androidx.compose.material.MaterialTheme
8+ import androidx.compose.material.Surface
9+ import androidx.compose.runtime.Composable
10+ import androidx.compose.runtime.getValue
11+ import androidx.compose.runtime.remember
12+ import androidx.compose.ui.Alignment
13+ import androidx.compose.ui.Modifier
14+ import androidx.compose.ui.draw.scale
15+ import androidx.compose.ui.layout.ContentScale
16+ import androidx.compose.ui.platform.LocalConfiguration
17+ import androidx.compose.ui.platform.LocalDensity
18+ import androidx.compose.ui.unit.IntOffset
19+ import androidx.compose.ui.unit.dp
20+ import dev.baseio.composeplayground.R
21+ import dev.baseio.composeplayground.contributors.AnmolVerma
22+ 23+ @Composable
24+ fun Github404 (modifier : Modifier ) {
25+ 26+ val infiniteTransition = rememberInfiniteTransition()
27+ val yFactor by infiniteTransition.animateFloat(
28+ initialValue = 0f ,
29+ targetValue = 30f ,
30+ animationSpec = infiniteRepeatable(
31+ animation = tween(durationMillis = 2000 , delayMillis = 0 , easing = LinearEasing ),
32+ repeatMode = RepeatMode .Reverse
33+ )
34+ )
35+ 36+ val bgImageScaleFactor by infiniteTransition.animateFloat(
37+ initialValue = 1f ,
38+ targetValue = 1.5f ,
39+ animationSpec = infiniteRepeatable(
40+ animation = tween(durationMillis = 2000 , delayMillis = 1000 , easing = LinearEasing ),
41+ repeatMode = RepeatMode .Reverse
42+ )
43+ )
44+ 45+ 46+ val width = with (LocalDensity .current) {
47+ LocalConfiguration .current.screenWidthDp.dp.toPx()
48+ }
49+ val height = with (LocalDensity .current) {
50+ LocalConfiguration .current.screenHeightDp.dp.toPx()
51+ }
52+ 53+ val githubAvatarX = remember {
54+ Animatable (width.div(2 ))
55+ }
56+ 57+ val githubAvatarY = remember {
58+ Animatable (height.div(2 ))
59+ }
60+ 61+ 62+ Surface (
63+ modifier
64+ .background(MaterialTheme .colors.background)
65+ ) {
66+ 67+ Box (Modifier .fillMaxSize()) {
68+ 69+ Box {
70+ BackgroundImageGithub (bgImageScaleFactor)
71+ Looking404 (githubAvatarX.value, githubAvatarY.value)
72+ HomeTwo (githubAvatarX.value.plus(480 ), githubAvatarY.value.minus(220 ))
73+ HomeOne (githubAvatarX.value.plus(80 ), githubAvatarY.value.minus(180 ))
74+ SpaceShip (githubAvatarX.value.plus(10 ), githubAvatarY.value.plus(30 ).minus(yFactor))
75+ AvatarShadow (githubAvatarX.value.minus(150 ), githubAvatarY.value.plus(210 ).minus(yFactor))
76+ GithubAvatar (githubAvatarX.value.minus(160 ), githubAvatarY.value.minus(yFactor))
77+ }
78+ 79+ Box (
80+ modifier = Modifier
81+ .scale(0.6f )
82+ .align(Alignment .BottomEnd )
83+ .background(MaterialTheme .colors.background)
84+ ) {
85+ AnmolVerma (Modifier .align(Alignment .Center ))
86+ }
87+ }
88+ }
89+ }
90+ 91+ @Composable
92+ private fun HomeTwo (
93+ githubAvatarX : Float ,
94+ githubAvatarY : Float
95+ ) {
96+ Image (
97+ painter = androidx.compose.ui.res.painterResource(id = R .drawable.deserthome1),
98+ contentDescription = null , modifier = Modifier
99+ .offset {
100+ IntOffset (
101+ githubAvatarX
102+ .toInt(),
103+ githubAvatarY
104+ .toInt()
105+ )
106+ }
107+ .scale(1.5f )
108+ )
109+ }
110+ 111+ @Composable
112+ private fun HomeOne (
113+ githubAvatarX : Float ,
114+ githubAvatarY : Float
115+ ) {
116+ Image (
117+ painter = androidx.compose.ui.res.painterResource(id = R .drawable.deserthome1),
118+ contentDescription = null , modifier = Modifier
119+ .offset {
120+ IntOffset (
121+ githubAvatarX
122+ .toInt(),
123+ githubAvatarY
124+ .toInt()
125+ )
126+ }
127+ .scale(2.8f )
128+ )
129+ }
130+ 131+ @Composable
132+ private fun SpaceShip (
133+ githubAvatarX : Float ,
134+ githubAvatarY : Float
135+ ) {
136+ Image (
137+ painter = androidx.compose.ui.res.painterResource(id = R .drawable.spaceship),
138+ contentDescription = null , modifier = Modifier
139+ .offset {
140+ IntOffset (
141+ githubAvatarX
142+ .toInt(),
143+ githubAvatarY
144+ .toInt()
145+ )
146+ }
147+ .scale(1.8f )
148+ )
149+ }
150+ 151+ @Composable
152+ private fun Looking404 (
153+ githubAvatarX : Float ,
154+ githubAvatarY : Float
155+ ) {
156+ Image (
157+ painter = androidx.compose.ui.res.painterResource(id = R .drawable.notfound),
158+ contentDescription = null , modifier = Modifier
159+ .offset {
160+ IntOffset (
161+ githubAvatarX
162+ .minus(480 )
163+ .toInt(),
164+ githubAvatarY
165+ .toInt()
166+ .minus(130 )
167+ )
168+ }
169+ .scale(1.8f )
170+ )
171+ }
172+ 173+ @Composable
174+ private fun GithubAvatar (
175+ githubAvatarX : Float ,
176+ githubAvatarY : Float
177+ ) {
178+ Image (
179+ painter = androidx.compose.ui.res.painterResource(id = R .drawable.githubavatar),
180+ contentDescription = null , modifier = Modifier
181+ .offset {
182+ IntOffset (
183+ githubAvatarX
184+ .toInt(),
185+ githubAvatarY.toInt()
186+ )
187+ }
188+ .scale(1.8f )
189+ )
190+ }
191+ 192+ @Composable
193+ private fun AvatarShadow (
194+ githubAvatarX : Float ,
195+ githubAvatarY : Float
196+ ) {
197+ Image (
198+ painter = androidx.compose.ui.res.painterResource(id = R .drawable.avatarshadow),
199+ contentDescription = null , modifier = Modifier
200+ .offset {
201+ IntOffset (
202+ githubAvatarX
203+ .toInt(),
204+ githubAvatarY.toInt()
205+ )
206+ }
207+ .scale(1.8f )
208+ )
209+ }
210+ 211+ @Composable
212+ private fun BackgroundImageGithub (bgImageScaleFactor : Float ) {
213+ Image (
214+ painter = androidx.compose.ui.res.painterResource(id = R .drawable.background),
215+ contentDescription = null ,
216+ contentScale = ContentScale .Crop ,
217+ modifier = Modifier .fillMaxSize().scale(bgImageScaleFactor)
218+ )
219+ }
0 commit comments