Friday, December 11, 2015

Simple Animation using C Program


Program #17

Description:
Randomly move the position and rotate {/ \ | } symbols.


#include<conio.h>
#include<stdlib.h>
#include<dos.h>
void main(){
  int counter=0, rowValue=1, colValue=1, colorValue;

 /* function prototype declaration */
  int getRow();
  int getColumn();

 /* Clear the Screen */
  clrscr();

 /* Iterate Indefinite loop */
  for(;!kbhit();){
   
/* Move the Rotation every 32766 counter */
    if (counter%32766 == 0){
   /* Get New Row and Column */
      rowValue = getRow();
      colValue = getColumn();
     
/* Re-initialize counter as 0 once it reaches INT max value */
      if (counter == 32766){
 counter = 0;

/* Delay for a while in Milliseconds */
 delay(100);
      }
  
 /* Clear the Screen, and show a fresh as Rotation */
      //clrscr();
    }

   /* Increase the Counter */
    counter++;

    colorValue = getColor();
    textcolor(colorValue);
    gotoxy(colValue, rowValue);
    cprintf("|");
    gotoxy(colValue, rowValue);
    cprintf("/");
    gotoxy(colValue, rowValue);
    cprintf("\\");
   }
}

int getRow(){
  int rowNum=1, i=0;
  for(;i<25;i++){
   /* getting a randow row, if system gives 0, trying next number */
   rowNum = random(25);
    if (rowNum!=0){
      return rowNum;
    }
  }
  /* worst case, hope it won't return */
  return rowNum;
}

int getColumn(){
  int colNum=1, i=0;
  for(;i<80;i++){
   /* getting a randow column, if system gives 0, trying next number */
   colNum = random(80);
    if (colNum!=0){
      return colNum;
    }
  }
  /* worst case, hope it won't return */
  return colNum;
}

int getColor(){
   int color;
   /* getting a randow color */
   color = random(15);
   return color;
}


 

No comments:

Post a Comment

Popular Posts