Animated Tickertape
Create the illusion of a rolling tickertape
inside of a rectangular box on your
normal C++ output screen. This illusion will give the appearance that the code is being
"pulled" into the box from its right hand side, moves across the box toward the
left hand side, and exits the box on the left side.
// tickertape
#include <iostream.h>
#include<stdlib.h>
#include"screen.h"
#include "apstring.cpp"
void mid_string(apstring banner, int starting, int number);
void rectangle_box(int x, int y, int length, int width);
void tickertape(apstring banner, int repeats, int box_size, int x_right_box,
int y_middle, int x_left_box);
int main(void)
{
system("CLS");
// Here is the WINDOW (or the
box) for the tickertape
rectangle_box(30, 10, 12, 4);
// Here is the Tickertape
message with spaces added that are length of box
apstring banner = "Computer Science 2 is great!
";
// Here comes the tickertape
effect
tickertape(banner, 3, 11, 42, 12, 31);
cout<<flush<<endl<<endl<<endl<<endl;
return 0;
}
// Function to chop our middle portions of the string
void mid_string(apstring banner, int starting, int number)
{
for (int n = 0; n <= number - 1; n++)
{
cout<<banner[starting+n];
cout<<flush;
}
return;
}
// Function to create rectangular box using ASCII
characters
void rectangle_box(int x, int y, int length, int width)
{
gotoxy(x,y);
cout<<char(201);
for(int i = 1; i<=length; i++)
// row across the top
{
cout<<char(205)<<flush;
}
cout<<char(187)<<flush;
for(int j = 1; j <= width; j++)
// edges of box
{
gotoxy(x,y+j);
cout<<char(186)<<flush;
gotoxy(x+length+1,
y+j);
cout<<char(186)<<flush;
}
gotoxy(x,y+width);
cout<<char(200)<<flush;
for(i=1; i <= length ; i++) //
row across the bottom
{
cout<<char(205)<<flush;
}
cout<<char(188)<<flush;
return;
}
// Function for tickertape effect
void tickertape(apstring banner, int repeats, int box_size, int x_right_box, int
y_middle,
int x_left_box)
{
// The c loop controls the
number of repetitions
for (int c = 1; c <= repeats; c++)
{
for(int s = 1; s <=
box_size; s++)
{
gotoxy(x_right_box-s, y_middle);
// control speed of tickertape
delay(150);
cout<<flush;
for(int m = 0; m <= s-1; m++) //fill box with leftmost
characters of banner
{
cout<<banner[m];
cout<<flush;
}
}
for(int y = 1; y <
banner.length()-box_size; y++)
{
gotoxy(x_left_box, y_middle);
// control speed of tickertape
delay(150);
cout<<flush;
mid_string(banner, y, box_size); //call function
to chop middle
}
}
return;
}
|