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("-");
  }
}






No comments:

Post a Comment

Popular Posts