d. Animated Strings

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 02 - Drawing Strings >

d. Animated Strings

This section shows how to add animation effects to strings using the StringExt() command. Manipulate the string location (x, y) to create an illusion of the string moving on the screen.

 

 

Command Prototype

 

uint16_t StringExt( int16_t Handle, int X, int Y, uint32_t Color, just_t Justification, int16_t Angle, double Radius, const char* String)

 

Parameters

Description

Handle

Font Size

X

x-coordinate for string

Y

y-coordinate for string

Color

String color

Justification

Justification values (i.e MM,TL,BL, etc.)

Angle

Angle at which string will be drawn

Radius

Distance from center at which string will be drawn

String

String text

 

 

Code

 

 

int minX = 75, minY = 15;

int maxX = 800 - minX, maxY = 480 - minY;

int startX = maxX / 2, startY = maxY / 2;

int deltaX = 2, deltaY = 2;

 

void setup() {

 /* Initialize CleO - needs to be done only once */

 CleO.begin();

}

void loop()

{

 /* Start building a screen frame */

 CleO.Start();

 

 /* Draw the string and update its coordinates */

 CleO.StringExt(FONT_MEDIUM, startX, startY, LIGHT_GREEN, MM, 0, 0, "Hello world");

 startX = startX + deltaX;   startY = startY + deltaY;

 

 /* Take care of screen boundary cases */

 if (startX >= maxX)

   deltaX = -deltaX;

 

 if (startX <= minX)

   deltaX = abs(deltaX);

 

 if (startY >= maxY)

   deltaY = -deltaY;

 

 if (startY <= minY)

   deltaY = abs(deltaY);

 

 /* Display completed screen frame */

 CleO.Show();

}

 

 

Description

 

The above code snippet constructs a string between Start() and Show() routines.

The code then draws the string at the initial location and then keeps on moving its location (startX, startY).

It checks for conditions whether the string has reached the screen boundary and based on the edge, changes the startX and startY values. This way in each frame, the string location is changed, and it gives us an animation of a string moving on the screen.

The values of deltaX and deltaY can be modified to see different animation effects.

 

 

Output

 

Click on the video clip to view the output -

 

Animated Strings