Showing posts with label Indefinite loop in C. Show all posts
Showing posts with label Indefinite loop in C. Show all posts

Thursday, December 31, 2015

Music Visualizer Simulation using C Program

Program #37

Description:
Music Visualization Simulation using C Program.  Dynamically it will pick the Themes.

/*
Music Visualizer Simulation using C Program
Music Visualization Dynamic Effect using C Program
Track Music using Simple Animation in C
Music Visualize Print using C Program
Vertical Progress Bar Print using C Program
*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

/* Defined Constants */
#define TRACK_DELAY 15;

/* Global Function Prototype Declaration */
void clearColumnTrack();
void setColor();
void setTrackCharacter();
void printBaseLine();

/* Global Variables */
int trackChar, cols[25], rows[15];
int main(){

 /* Local Function Prototype Declaration */
 void printRandomTrack();
 void setColumnPosition();
 void setRowPosition();

 /* Clear the Screen */
 clrscr();

 /* randomize */
 randomize();

 /* Set Track Character */
 setTrackCharacter();

 /* Initialize Row & Column Positions */
 setColumnPosition();
 setRowPosition();
 for ( ; !kbhit() ; ){
   printBaseLine();
   printRandomTrack();
 }
 return 1;
}

/* Print Specific Track Dynamics - Specific COLUMN */
void printRandomTrack(){
 int i, row=20, randCols, randRows;
 int trackDelay;

 /* Set Track Speed i.e. Delay */
 trackDelay = TRACK_DELAY;

 /* Set a Random Track Color */
 setColor();

 /* Get a Column Randomly */
 randCols = random(20);

 /* Get a Row Randomly */
 randRows = random(10);

 /* Clear Column Track */
 clearColumnTrack(cols[randCols]);

 /* Print Track Bar */
 for (i=row; i<=rows[randRows]; i++){
   gotoxy(cols[randCols], row--);
   cprintf("%c", trackChar);
   /* Delay */
   delay( trackDelay );
 }
}

/* Clear Specific Column */
void clearColumnTrack(int column){
 int i, row=20;
 for (i=1;i<=10;i++){
   gotoxy(column, row--);
   printf(" ");
 }
}

/* Set a Track Color Randomly */
void setColor(){
  int color;
  color = random(15);
  /* Avoid BLACK color */
  if (color == 0) color = 1;
  /* Set Color */
  textcolor(color);
}

/* Get Random Track Character */
int getTrackCharacter(){
  int rands, trackChars[]={176, 177, 178, 179, 220, 223};
  randomize();
  /* Get a random Character */
  rands = random(6);
  /* Set Random Track Characters */
  return trackChars[rands];
}

/* Get Track Character */
void setTrackCharacter(){
  trackChar = getTrackCharacter();
}

/* Set Column Position */
void setColumnPosition(){
 int i, randCols=0;
 /* Column Array values */
  for (i=31; i<=51; i++){
    cols[randCols]=i;
    randCols++;
  }
}

/* Set Row Position */
void setRowPosition(){
 int i, randRows=0;
 /* Row Array values */
  for (i=20; i<=30; i++){
    rows[randRows]=i;
    randRows++;
  }
}

/* Draw Base Line */
void printBaseLine(){
  int i, colVal=26;
  for (i=1; i<=30; i++){
    gotoxy(colVal++, 20);
    printf("-");
  }
}






Friday, December 11, 2015

Simple Animation to Fill Box color using C Program



Program #18

Description:
Dynamically plotting dots on a specific area in the screen using multi-colors.  Once all positions plotting is done.  Program will come to an end.

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

/* Global Array Declaration */
int Box[50][50];

int main(){
  int counter=0, rowValue=1, colValue=1;
  int boxStatus, colorValue;

  /* function prototype declaration */
  int getRow();
  int getColumn();
  int checkBoxCompletion();
 
/* Clear the Screen */
  clrscr();

 /* Iterate Indefinite loop */
  for(;!kbhit();){
    rowValue = getRow();
    colValue = getColumn();
    /* set Box position using Currrent Row,Column */
    if (Box[rowValue][colValue] != 1){
      Box[rowValue][colValue] = 1;
    } else {

 /* avoid overwritting plotted color
      get a new blank position.
      If you wish, just comment below "continue"
      and see the difference
      */
      continue;
    }

  /* Re-initialize counter as 0 once it reaches INT max value */
    if (counter == 32766) counter = 0;

  /* Increase the Counter */
    counter++;

 /* get random color */
    colorValue = getColor();

   /* set color using randow value */
    textcolor(colorValue);
    /* Move the cursor position */
    gotoxy(colValue, rowValue);

   /* do color print */
    cprintf("*");
   
/* set some delay in Milliseconds
    as much you decrease, that much fast system will
    fill the color + add mild-sound
    */
    sound(200*rowValue);
    delay(10);
   
/* after delay, mute the sound */
    nosound();
   
/* check box completion station after every dot plot */
    boxStatus = checkBoxCompletion();
    if (boxStatus == 1) {
      gotoxy(18, 18);

 /* print the success message using last dot color, Interesting!! */
      cprintf("Box Color Fill: Completed Successfully !!");
      getch();

  /* stop the execution */
      return 1;
    }
   }
   return 0;
}

int getRow(){
  int rowNum;

  /* getting a randow row */
   rowNum = random(25);
  if (rowNum<8 || rowNum>15){

 /* get next random */
    getRow();
  } else {
    return rowNum;
  }

  /* worst case, default return value */
  return 8;
}

int getColumn(){
  int colNum;

 /* getting a randow column */
   colNum = random(80);
   if (colNum<25 || colNum>50){

  /* get Next Column */
      getColumn();
   } else {
      return colNum;
   }
   /* worst case, default return value */
  return 25;
}

int getColor(){
   int color;

 /* getting a randow color */
   color = random(15);
   if (color == 0){

   /* 0 means BLACK color, it will spoil the Spot */
     getColor();
   } else {
     return color;
   }

  /* worst case, default return value */
   return 1;
}

int checkBoxCompletion(){
  int i,j;
  for (i=8;i<=15;i++){
    for (j=25; j<=50; j++){
      if(Box[i][j] != 1){

/* Color fill not yet completed */
 return 0;
      }
    }
  }
 
/* Color fill Finished */
  return 1;
}

 

Popular Posts