Skip to content

Commit dd6c76c

Browse files
committed
Added a demo for the clipped/unclipped and opaque/transparent rotated sprite routines. Also updated the apng for sprites_rotate_scale
1 parent 4021275 commit dd6c76c

File tree

10 files changed

+166
-2
lines changed

10 files changed

+166
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
obj/
2+
bin/
3+
src/gfx/*.c
4+
src/gfx/*.h
5+
src/gfx/*.8xv
6+
.DS_Store
7+
convimg.yaml.lst
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"transfer_files":
3+
[
4+
"bin/DEMO.8xp"
5+
],
6+
"target":
7+
{
8+
"name": "DEMO",
9+
"isASM": true
10+
},
11+
"sequence":
12+
[
13+
"action|launch",
14+
"delay|500",
15+
"key|enter",
16+
"delay|100",
17+
"hashWait|1"
18+
],
19+
"hashes":
20+
{
21+
"1":
22+
{
23+
"description": "Test program exit",
24+
"start": "vram_start",
25+
"size": "vram_16_size",
26+
"expected_CRCs": [ "FFAF89BA", "101734A5", "9DA19F44", "A32840C8", "349F4775" ]
27+
}
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ----------------------------
2+
# Makefile Options
3+
# ----------------------------
4+
5+
NAME = DEMO
6+
ICON = icon.png
7+
DESCRIPTION = "CE C Toolchain Demo"
8+
COMPRESSED = NO
9+
10+
CFLAGS = -Wall -Wextra -Oz
11+
CXXFLAGS = -Wall -Wextra -Oz
12+
13+
# ----------------------------
14+
15+
include $(shell cedev-config --makefile)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Clipped Rotation Demo
2+
3+
Demonstrates the clipped/unclipped and opaque/transparent rotated sprite routines.
4+
5+
![Screenshot](screenshot.png)
634 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
palettes:
2+
- name: global_palette
3+
fixed-entries:
4+
- color: {index: 0, r: 255, g: 0, b: 128}
5+
- color: {index: 1, r: 255, g: 255, b: 255}
6+
images: automatic
7+
8+
converts:
9+
- name: sprites
10+
palette: global_palette
11+
transparent-color-index: 0
12+
images:
13+
- star.png
14+
15+
outputs:
16+
- type: c
17+
include-file: gfx.h
18+
palettes:
19+
- global_palette
20+
converts:
21+
- sprites
22+
23+
2.06 KB
Loading
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <ti/getcsc.h>
2+
#include <graphx.h>
3+
#include <math.h>
4+
#include <time.h>
5+
6+
/* Include the converted image data */
7+
#include "gfx/gfx.h"
8+
9+
int main(void)
10+
{
11+
/* Center of the screen */
12+
const int x_center = GFX_LCD_WIDTH / 2;
13+
const int y_center = GFX_LCD_HEIGHT / 2;
14+
15+
/* Parameters for the clipping box */
16+
const int box_width = 80;
17+
const int box_height = 80;
18+
const float box_pivot_radius = 20.0f;
19+
20+
/* The positions of the 4 sprites on the screen */
21+
const int distance_from_center = 30;
22+
const int pos_left = x_center - distance_from_center - (star_width / 2);
23+
const int pos_right = x_center + distance_from_center - (star_width / 2);
24+
const int pos_top = y_center - distance_from_center - (star_height / 2);
25+
const int pos_bottom = y_center + distance_from_center - (star_height / 2);
26+
27+
/* Initialize graphics drawing */
28+
gfx_Begin();
29+
30+
/* Set the palette used by the sprites */
31+
gfx_SetPalette(global_palette, sizeof_global_palette, 0);
32+
gfx_SetTransparentColor(0);
33+
34+
/* Draw to buffer to avoid artifacts */
35+
gfx_SetDrawBuffer();
36+
37+
/* Record the start time */
38+
const clock_t start_time = clock();
39+
40+
/* Rotate the sprites until a key is pressed */
41+
do {
42+
/* Get the elasped time in seconds */
43+
float time_elasped = (float)(clock() - start_time) / CLOCKS_PER_SEC;
44+
45+
/* Calculate the clipping region */
46+
int x_offset = cosf(time_elasped) * box_pivot_radius;
47+
int y_offset = sinf(time_elasped) * box_pivot_radius;
48+
int box_left = x_center - (box_width / 2) + x_offset;
49+
int box_right = x_center + (box_width / 2) + x_offset;
50+
int box_top = y_center - (box_height / 2) + y_offset;
51+
int box_bottom = y_center + (box_height / 2) + y_offset;
52+
gfx_SetClipRegion(box_left, box_top, box_right, box_bottom);
53+
54+
/* Draw a rectangle to indicate the clipping region */
55+
gfx_SetColor(2);
56+
gfx_Rectangle_NoClip(box_left - 1, box_top - 1, box_width + 2, box_height + 2);
57+
58+
/* Complete one rotation every 6 seconds */
59+
uint8_t sprite_angle = fmodf(time_elasped * 256.0f / 6.0f, 256.0f);
60+
61+
/* Draws an unclipped rotated sprite */
62+
gfx_RotatedSprite_NoClip(star, pos_left, pos_bottom, sprite_angle);
63+
64+
/* Draws a rotated sprite that is clipped to the rectangular box */
65+
gfx_RotatedSprite(star, pos_right, pos_bottom, sprite_angle);
66+
67+
/* Draws an unclipped rotated sprite with transparency */
68+
gfx_RotatedTransparentSprite_NoClip(star, pos_right, pos_top, sprite_angle);
69+
70+
/* Draws a rotated sprite with transparency that is clipped to the rectangular box */
71+
gfx_RotatedTransparentSprite(star, pos_left, pos_top, sprite_angle);
72+
73+
/* Show the buffered screen */
74+
gfx_BlitBuffer();
75+
76+
/* Clear the old drawn sprite */
77+
gfx_FillScreen(1);
78+
79+
} while (!os_GetCSC());
80+
81+
/* End graphics drawing */
82+
gfx_End();
83+
84+
return 0;
85+
}
182 KB
Loading

examples/library_examples/graphx/sprites_rotate_scale/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ int main(void)
4040
/* Complete one rotation every 5 seconds */
4141
uint8_t rotation = fmodf(time_elasped * 256.0f / 5.0f, 256.0f);
4242

43-
/* Interpolates between 75% and 250% scale (64 = 100% scale) */
44-
uint8_t scale = (uint8_t)cosine_interpolate(time_elasped, 48, 160);
43+
/* Interpolates between 75% and 225% scale (64 = 100% scale) */
44+
uint8_t scale = (uint8_t)cosine_interpolate(time_elasped, 48, 144);
4545

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

0 commit comments

Comments
 (0)