1
1
#include <ti/getcsc.h>
2
2
#include <graphx.h>
3
+ #include <math.h>
4
+ #include <time.h>
3
5
4
6
/* Include the converted image data */
5
7
#include "gfx/gfx.h"
6
8
9
+ float cosine_interpolate (float t , float min_val , float max_val ) {
10
+ /* Interpolates between min_val and max_val on a cosine wave */
11
+ /* t = 0 returns min_val */
12
+ float amplitude = (min_val - max_val ) / 2.0f ;
13
+ float offset = (min_val + max_val ) / 2.0f ;
14
+ return amplitude * cosf (t ) + offset ;
15
+ }
16
+
7
17
int main (void )
8
18
{
9
- uint8_t x = 0 ;
19
+ const int x_center = GFX_LCD_WIDTH / 2 ;
20
+ const int y_center = GFX_LCD_HEIGHT / 2 ;
10
21
11
22
/* Initialize graphics drawing */
12
23
gfx_Begin ();
@@ -18,22 +29,36 @@ int main(void)
18
29
/* Draw to buffer to avoid artifacts */
19
30
gfx_SetDrawBuffer ();
20
31
32
+ /* Record the start time */
33
+ const clock_t start_time = clock ();
34
+
21
35
/* Rotate the sprite until a key is pressed */
22
- do
23
- {
36
+ do {
37
+ /* Get the elasped time in seconds */
38
+ float time_elasped = (float )(clock () - start_time ) / CLOCKS_PER_SEC ;
39
+
40
+ /* Complete one rotation every 5 seconds */
41
+ uint8_t rotation = fmodf (time_elasped * 256.0f / 5.0f , 256.0f );
42
+
43
+ /* Interpolates between 75% and 250% scale (64 = 100% scale) */
44
+ uint8_t scale = (uint8_t )cosine_interpolate (time_elasped , 48 , 160 );
45
+
46
+ /* The output size of the sprite can be calculated with this formula */
47
+ uint8_t output_size = (scale * star_width ) / 64 ;
48
+
49
+ /* Calculate the x and y position to center the sprite */
50
+ int x_pos = x_center - output_size / 2 ;
51
+ int y_pos = y_center - output_size / 2 ;
24
52
25
53
/* Draw a rotated transparent scaled spite */
26
- gfx_RotatedScaledTransparentSprite_NoClip (star , 120 , 80 , 256 - x , 128 );
54
+ gfx_RotatedScaledTransparentSprite_NoClip (star , x_pos , y_pos , rotation , scale );
27
55
28
56
/* Show the buffered screen */
29
57
gfx_BlitBuffer ();
30
58
31
59
/* Clear the old drawn sprite */
32
60
gfx_FillScreen (1 );
33
61
34
- /* Change the rotation amount */
35
- x ++ ;
36
-
37
62
} while (!os_GetCSC ());
38
63
39
64
/* End graphics drawing */
0 commit comments