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)





Font Size


x-coordinate for string


y-coordinate for string


String color


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


Angle at which string will be drawn


Distance from center at which string will be drawn


String text






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 */



void loop()


 /* Start building a screen frame */



 /* 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 */







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.





Click on the video clip to view the output -


Animated Strings