Wednesday, December 23, 2015

Star Message Print using C Program


Program #35


Description:
Print the Message in a 4 different angle and approximately like a Star !!.  And print will happen one after another in Multi-Color.  This Program will Indefinitely print (Slow Motion using Delay) until User press any Key. 

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

/* Global Constant */
#define PRINT_SPEED 50

/* Global Variable Declaration */
char inputStr[25];
int col, row;

/* Global Prototype Declaration */
void identifyCoOrdinates(int);

int main(void){

  /* Local Variable Declaration */
  int i, yPos;

  /* Local Prototype Declaration */
  void validateStrLength();
  void printHorizontal();
  void printVertical();
  void printVerticalFromTopLeft();
  void printVerticalFromTopRight();
  void printVerticalFromBottomLeft();
  clrscr();

  /* get Input String */
  printf("Please Enter a Message:\n");
  gets(inputStr);

  /*  Validate Character Length */
  validateStrLength();
  for (; !kbhit(); ){

    /* Clear the Screen */
    clrscr();

    /* Print Horizontal Message */
    printHorizontal();

    /* Print Vertical Message */
    printVertical();

    /* Print Vertical Message From Left */
    printVerticalFromTopLeft();

    /* Print Vertical Message From Right */
    printVerticalFromTopRight();
  }
  getch();
  return 0;
}

void setColor(){
  int color, colorCode[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
  color = random(15);
  textcolor( colorCode[color] );
}

/* Validate String Lengh */
void validateStrLength(){
  if ( strlen(inputStr) > 25){
    clrscr();
    cprintf("Invalid Input! Bye!!");
    getch();
    exit(0);
  }
}

/* Print Message in Vertical-from-right */
void printVerticalFromTopRight(){
 int speed, i, colVal, rowVal;
 speed = PRINT_SPEED;

 /* setColor */
 setColor();

 /* Identify Position */
 identifyCoOrdinates(4);

 /* get Column Value */
 colVal = col;

 /* get Row Value */
 rowVal = row;

 for (i=0; i< strlen(inputStr); i++){
   gotoxy(colVal--, rowVal++);
   cprintf("%c", inputStr[i]);
   delay(speed);
 }
}

/* Print Message in Vertical-from-left */
void printVerticalFromTopLeft(){
 int speed, i, colVal, rowVal;
 speed = PRINT_SPEED;

 /* setColor */
 setColor();

 /* Identify Position */
 identifyCoOrdinates(3);

 /* get Column Value */
 colVal = col;

 /* get Row Value */
 rowVal = row;
 for (i=0; i< strlen(inputStr); i++){
   gotoxy(colVal++, rowVal++);
   cprintf("%c", inputStr[i]);
   delay(speed);
 }
}

/* Print Message in Vertical */
void printVertical(){
 int speed, i, colVal, rowVal;
 speed = PRINT_SPEED;

 /* setColor */
 setColor();

 /* Identify Position */
 identifyCoOrdinates(2);

 /* get Column Value */
 colVal = col;

 /* get Row Value */
 rowVal = row;
 for (i=0; i< strlen(inputStr); i++){
   gotoxy(colVal, rowVal++);
   cprintf("%c", inputStr[i]);
   delay(speed);
 }
}

/* Identify Right Co-Ordinate */
void identifyCoOrdinates(int Place){
  int rowCalc=12, colCalc=39;

  /* Horizontal */
  if (Place == 1){
    colCalc = strlen(inputStr);
    colCalc = 80 - colCalc;
    colCalc = (int)(colCalc/2);

    /* Assign to Global Column Variable */
    col = colCalc-strlen(inputStr)/2+1;

    /* Assign to Global Row Variable */
    row = rowCalc;
  }

  /* Vertical */
  else if (Place == 2){
    rowCalc = strlen(inputStr);
    rowCalc = 25 - rowCalc;
    rowCalc = (int)(rowCalc/2);

    /* Assign to Global Column Variable */
    col = colCalc;

    /* Assign to Global Row Variable */
    row = rowCalc;
  }

  /* Vertical From Left */
  else if (Place == 3){
    rowCalc = strlen(inputStr);
    rowCalc = 25 - rowCalc;
    rowCalc = (int)(rowCalc/2);

    colCalc = strlen(inputStr);
    colCalc = 80 - colCalc;
    colCalc = (int)(colCalc/2);

    /* Assign to Global Column Variable */
    col = colCalc;

    /* Assign to Global Row Variable */
    row = rowCalc;
  }

  /* Vertical From Right */
  else if (Place == 4){
    rowCalc = strlen(inputStr);
    rowCalc = 25 - rowCalc;
    rowCalc = (int)(rowCalc/2);

    colCalc = strlen(inputStr);
    colCalc = 80 - colCalc;
    colCalc = (int)(colCalc/2);

    /* Assign to Global Column Variable */
    col = colCalc+strlen(inputStr);

    /* Assign to Global Row Variable */
    row = rowCalc;
  }

}

/* Print Message in Horizontal */
void printHorizontal(){
 int speed, i, colVal, rowVal;
 speed = PRINT_SPEED;

 /* setColor */
 setColor();

 /* Identify Position */
 identifyCoOrdinates(1);

 /* get Column Value */
 colVal = col;

 /* get Row Value */
 rowVal = row;
 for (i=0; i< strlen(inputStr); i++){
   gotoxy(colVal, rowVal);
   cprintf("%c", inputStr[i]);
   colVal += 2;
   delay(speed);
 }
}







 

No comments:

Post a Comment

Popular Posts