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 ;
21
+ uint8_t rotation = 0 ;
10
22
11
23
/* Initialize graphics drawing */
12
24
gfx_Begin ();
@@ -18,21 +30,35 @@ int main(void)
18
30
/* Draw to buffer to avoid artifacts */
19
31
gfx_SetDrawBuffer ();
20
32
33
+ /* Record the start time */
34
+ const clock_t start_time = clock ();
35
+
21
36
/* Rotate the sprite until a key is pressed */
22
- do
23
- {
37
+ do {
38
+ /* Get the elasped time in seconds */
39
+ float time_elasped = (float )(clock () - start_time ) / CLOCKS_PER_SEC ;
40
+
41
+ /* Interpolates between 75% and 200% scale (64 = 100% scale) */
42
+ uint8_t scale = (uint8_t )cosine_interpolate (time_elasped , 48 , 160 );
43
+
44
+ /* The output size of the sprite can be calculated with this formula */
45
+ uint8_t output_size = (scale * star_width ) / 64 ;
46
+
47
+ /* Calculate the x and y position to center the sprite */
48
+ int x_pos = x_center - output_size / 2 ;
49
+ int y_pos = y_center - output_size / 2 ;
24
50
25
51
/* Draw a rotated transparent scaled spite */
26
- gfx_RotatedScaledTransparentSprite_NoClip (star , 120 , 80 , 256 - x , 128 );
52
+ gfx_RotatedScaledTransparentSprite_NoClip (star , x_pos , y_pos , rotation , scale );
27
53
28
54
/* Show the buffered screen */
29
55
gfx_BlitBuffer ();
30
56
31
57
/* Clear the old drawn sprite */
32
58
gfx_FillScreen (1 );
33
-
59
+
34
60
/* Change the rotation amount */
35
- x ++ ;
61
+ rotation += 3 ;
36
62
37
63
} while (!os_GetCSC ());
38
64
0 commit comments