Showing posts with label Simple Animation - Drawing Border using C Program. Show all posts
Showing posts with label Simple Animation - Drawing Border using C Program. Show all posts

Saturday, December 12, 2015

Simple Animation - Drawing Border using C Program


Program #21

Description:
To draw Border in the Screen using dots.  All dots are in multi-colors. Once the border drawing completed.  System will prints success message.


#include<dos.h>
#include<conio.h>
#include<stdlib.h>

/* global prototype declaration */
void setTextColor();

int main(){
  int leftPos=1, rightPos=25;
  int botPos=1, topPos=80;

 /* prototype declaration */
  void drawLeftBorder(int);
  void drawRightBorder(int);
  void drawTopBorder(int);
  void drawBottomBorder(int);
  void initialMessage();
  void finalMessage();
 
/* Clear Screen */
  clrscr();

  /* Initial Message */
  initialMessage();

  for(;!kbhit();){

     /* take a random color */
     setTextColor();

     if (botPos == 1 && topPos == 80 && leftPos <= 25 && rightPos >= 1){
       drawLeftBorder(leftPos++);
       drawRightBorder(rightPos--);
     }
     if (leftPos == 25 && rightPos == 1 && topPos >= 1 && botPos <= 80){
       drawBottomBorder(botPos++);
       drawTopBorder(topPos--);
     }

     if(leftPos == 25 && rightPos == 1 && botPos == 80 && topPos == 1){
       finalMessage();
       getch();

       /* End the Program Execution */
       return 0;
     }
  }
  getch();
  return 0;
}

/*  Draw Left Border */
void drawLeftBorder(int leftPos){
 gotoxy(1,leftPos);
 cprintf("*",leftPos);
 delay(100);
}

/*  Draw Right Border */
void drawRightBorder(int rightPos){
 gotoxy(80,rightPos);
 cprintf("*",rightPos);
 delay(100);
}

/*  Draw Top Border */
void drawTopBorder(int topPos){
 gotoxy(topPos,1);
 cprintf("*",topPos);
 delay(100);
}

/*  Draw Bottom Border */
void drawBottomBorder(int bottomPos){
 gotoxy(bottomPos, 25);
 cprintf("*",bottomPos);
 delay(100);
}

void finalMessage(){
  int i;
  gotoxy(30,12);
  setTextColor();
  cprintf("Border Drawing Completed!");
  gotoxy(30,13);
  for(i=1;i<=25;i++){
    printf("_");
    delay(100);
  }
}

void initialMessage(){
  int i;
  gotoxy(30,13);
  setTextColor();
  cprintf("Press any Key to EXIT!");
  gotoxy(30,14);
  for(i=1;i<=22;i++){
    printf("-");
    delay(100);
  }
}

void setTextColor(){
  int a;
  a = random(15);
  if (a == 0) {
    /* Restrict BLACK color */
    setTextColor();
  } else {
    textcolor(a);
  }
}



 

Popular Posts