Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions examples/library_examples/graphx/sprites_rotate_scale/src/main.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#include <ti/getcsc.h>
#include <graphx.h>
#include <math.h>
#include <time.h>

/* Include the converted image data */
#include "gfx/gfx.h"

float cosine_interpolate(float t, float min_val, float max_val) {
/* Interpolates between min_val and max_val on a cosine wave */
/* t = 0 returns min_val */
float amplitude = (min_val - max_val) / 2.0f;
float offset = (min_val + max_val) / 2.0f;
return amplitude * cosf(t) + offset;
}

int main(void)
{
uint8_t x = 0;
const int x_center = GFX_LCD_WIDTH / 2;
const int y_center = GFX_LCD_HEIGHT / 2;

/* Initialize graphics drawing */
gfx_Begin();
Expand All @@ -18,22 +29,36 @@ int main(void)
/* Draw to buffer to avoid artifacts */
gfx_SetDrawBuffer();

/* Record the start time */
const clock_t start_time = clock();

/* Rotate the sprite until a key is pressed */
do
{
do {
/* Get the elasped time in seconds */
float time_elasped = (float)(clock() - start_time) / CLOCKS_PER_SEC;

/* Complete one rotation every 5 seconds */
uint8_t rotation = fmodf(time_elasped * 256.0f / 5.0f, 256.0f);

/* Interpolates between 75% and 250% scale (64 = 100% scale) */
uint8_t scale = (uint8_t)cosine_interpolate(time_elasped, 48, 160);

/* The output size of the sprite can be calculated with this formula */
uint8_t output_size = (scale * star_width) / 64;

/* Calculate the x and y position to center the sprite */
int x_pos = x_center - output_size / 2;
int y_pos = y_center - output_size / 2;

/* Draw a rotated transparent scaled spite */
gfx_RotatedScaledTransparentSprite_NoClip(star, 120, 80, 256 - x, 128);
gfx_RotatedScaledTransparentSprite_NoClip(star, x_pos, y_pos, rotation, scale);

/* Show the buffered screen */
gfx_BlitBuffer();

/* Clear the old drawn sprite */
gfx_FillScreen(1);

/* Change the rotation amount */
x++;

} while (!os_GetCSC());

/* End graphics drawing */
Expand Down
26 changes: 22 additions & 4 deletions examples/library_examples/graphx/text_custom/autotest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
"key|enter",
"hashWait|2",
"key|enter",
"hashWait|3"
"hashWait|3",
"key|enter",
"hashWait|4",
"key|enter",
"hashWait|5"
],
"hashes":
{
Expand All @@ -25,16 +29,30 @@
"description": "Test custom font display",
"start": "vram_start",
"size": "vram_8_size",
"expected_CRCs": [ "F717BF65" ]
"expected_CRCs": [ "711E0ED5" ]
},
"2":
{
"description": "Test hidden font display",
"description": "Before: ***",
"start": "vram_start",
"size": "vram_8_size",
"expected_CRCs": [ "EDA09A59" ]
"expected_CRCs": [ "1BD16129" ]
},
"3":
{
"description": "After: ***",
"start": "vram_start",
"size": "vram_8_size",
"expected_CRCs": [ "B090D407" ]
},
"4":
{
"description": "Test hidden font display",
"start": "vram_start",
"size": "vram_8_size",
"expected_CRCs": [ "0170C971" ]
},
"5":
{
"description": "Test program exit",
"start": "vram_start",
Expand Down
36 changes: 26 additions & 10 deletions examples/library_examples/graphx/text_custom/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ static unsigned char font8x8_spacing[128];

int main(void)
{
int i;

/* Initialize graphics drawing */
gfx_Begin();

Expand All @@ -24,15 +22,30 @@ int main(void)
/* Waits for a key */
while (!os_GetCSC());

PrintCentered("Before: ***");

/* Waits for a key */
while (!os_GetCSC());

/* Get a pointer to the character data for '*' by passing in NULL */
unsigned char *char_ptr = gfx_SetCharData('*', NULL);

/* Invert the pixels of '*' */
for (int i = 0; i < 8; i++) {
char_ptr[i] = ~char_ptr[i];
}

PrintCentered("After: ***");

/* Waits for a key */
while (!os_GetCSC());

/* Change the font by shifting each character up 1 */
for (i = 127; i > 0; --i)
for (int i = 127; i > 0; --i)
{
gfx_SetCharData(i, &font8x8[(i - 1) * 8]);
}

/* Clear old string */
gfx_FillScreen(255);

/* Print with the changed font */
PrintCentered("Uijt!tusjoh!xbt!ijeefo\"");

Expand All @@ -48,9 +61,12 @@ int main(void)
/* Prints a screen centered string */
void PrintCentered(const char *str)
{
gfx_PrintStringXY(str,
(GFX_LCD_WIDTH - gfx_GetStringWidth(str)) / 2,
(GFX_LCD_HEIGHT - 8) / 2);
/* Clear old string */
gfx_FillScreen(255);

int x_center = (GFX_LCD_WIDTH - gfx_GetStringWidth(str)) / 2;
int y_center = (GFX_LCD_HEIGHT - 8) / 2;
gfx_PrintStringXY(str, x_center, y_center);
}

static unsigned char font8x8_spacing[128] =
Expand Down Expand Up @@ -181,7 +197,7 @@ static unsigned char font8x8[128 * 8] =
0x00, 0x00, 0x00, 0x7e, 0x46, 0x62, 0x62, 0x7e, // Char 111 (o)
0x00, 0x00, 0x00, 0x7e, 0x46, 0x42, 0x7e, 0x60, // Char 112 (p)
0x60, 0x00, 0x00, 0x7e, 0x46, 0x42, 0x7e, 0x02, // Char 113 (q)
0x02, 0x00, 0x00, 0x7e, 0x46, 0x60, 0x60, 0x60, // Char 114 (r)
0x00, 0x00, 0x00, 0x7e, 0x46, 0x60, 0x60, 0x60, // Char 114 (r)
0x00, 0x00, 0x00, 0x7c, 0x40, 0x7c, 0x04, 0x7c, // Char 115 (s)
0x00, 0x10, 0x10, 0x3c, 0x10, 0x10, 0x18, 0x1c, // Char 116 (t)
0x00, 0x00, 0x00, 0x46, 0x46, 0x62, 0x62, 0x7e, // Char 117 (u)
Expand Down
1 change: 1 addition & 0 deletions examples/library_examples/graphx/tilemap/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ bin/
src/gfx/*.c
src/gfx/*.h
src/gfx/*.8xv
src/tilemap/*.c
.DS_Store
convimg.yaml.lst
1 change: 1 addition & 0 deletions examples/library_examples/graphx/tilemap_appvar/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ bin/
src/gfx/*.c
src/gfx/*.h
src/gfx/*.8xv
src/tilemap/*.c
.DS_Store
convimg.yaml.lst
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ bin/
src/gfx/*.c
src/gfx/*.h
src/gfx/*.8xv
src/tilemap/*.c
.DS_Store
convimg.yaml.lst
Loading
Loading