Sunday, October 9, 2011

Description of functions used in Slot Machine

Sound Generation in Turbo C ++

If you are creating graphical programs in turbo c++ then adding sound to the the program makes it more compelling experience for the viewer in another sense.Adding sound in the C++ program is very easy.In this guide you will learn to use sound for your programs.
Sound generation function:
The steps that involve to generate the sound in C++ are:
(1) Turning the sound on.
(2) Delay-ing for an appropriate amount of time.
(3) Turn-off the sound.
To perform these steps three standard functions are used :
sound( );
delay( );
nosound( );
Sound( ); function :-
The sound( ); function is used to set the sound generator to a specific frequency.You can specify the frequency from 15 to about 3000.
e.g. sound(100);
After execution of this function sound is turned on.So please note that sound remains on till it is specifically stopped.
delay( ); function :-
To delay the sound for perticular amount of time this function is used.
e.g.  delay(1000);
This function accepts single argument,and the time specified here is in the miliseconds.You can use the value 1000 for one second.
nosound( );:-
To turn off the sound started by the sound( ); function this function is used. This immediately turns off the sound generator.
Example:
 #include"dos.h" 
int main(void) { 
 sound(800); 
delay(1500); 
nosound(); 
 }  
Code explaination:
#include "dos.h"
To use the sound generating function we have to specify the “dos.h” file.

int main(void)

If you use the void main instead of this line then sound generating function may not able to return a value.
sound(800); delay(1500); nosound( );

Here the sound with frequency 800 hz is delayed for one and half seconds then nosound(); is used to turn off the sound generator.
These mentioned sound generating functions can be used to suspend the excution of program for perticular time period. You can use another function called sleep( ); to suspend the execution of the program for some time.
sleep( );
This function is used to suspend the program for perticular interval.
e.g. sleep(n);
Here value n is used to specify the time interval in seconds.

Functions included in Graphic.h Header file
In c++ we can use graphics. There is a pre defined header file that include the functions which help in drawing different shapes.

The header file is: graphics.h

These graphics are BGI graphics. They may not run on present version laptops in normal mode. They may work in safe mode and safe mode with command prompt.

Here are a few functions that are present under graphics.h

1.
initgraph()

syntax: initgraph(&gdriver,&gmode,PATH);
ex: initgraph(&gdriver,&gmode,"c:\\tc\\bgi");

This initgraph() initializes BGI graphics to be used in the program. It used the PATH as argument to search for the location where the BGI graphics are avialable.

If this PATH is simply specified as " ", then it understands as Auto Detect and searches for the BGI graphics. It may not work in some computers.


2.
line()
This is used to draw a line
syntax: line(x1,y1,x2,y2);
(x1,y1) and (x2,y2) are the two end points of the line





3.circle()
This is used to draw a circle
syntax:  circle(x,y,r)
Here x,y are the coordinates of the centre of the circle and is the radius

4.
rectangle()
This is used to draw a circle
syntax:  rectangle(x1,y1,x2,y2)
here (x1,y1) and (x2,y2) are the coordinates of diagonally opposite vertices of the rectangle.

5.drawpoly()
This is used to draw a polygon of n no. of sides. (given n)
syntax:  drawpoly(number_of_points,*points);
Here *points may be an array consisting of all the coordinates of the polygon.


6.fillpoly()
void far fillpoly (int numpoints, int far *polypoints);
 
Remarks: fillpoly draws the outline of a polygon using the current
line style and color, then fills the polygon using the current fill
pattern and fill color.
numpoints   - Specifies number of points
*polypoints - Points to a sequence of ("numpoints" x 2) integers.
 Each pair of integers gives the x and y coordinates
  of a point on the polygon.
 
7. floodfill()
void far floodfill (int x, int y, int border);
 
Remarks: floodfill flood-fills a bounded region. The area bounded 
by the color "border" is flooded  with the current fill pattern 
and fill color.  
(x,y) is the "seed point". If the seed is inside an enclosed area,
the interior will be filled.
If the seed is outside the enclosed area, the exterior will be filled.
8.Setfillstyle()  
setfillstyle()          Set the Fill Pattern and Fill Color
#include   <graphics.h>  
void far   setfillstyle(pattern,color);
int        pattern;
int        color;
setfillstyle() sets the current fill pattern and fill color used by bar(),
bar3d(), fillpoly(), floodfill() and pieslice().  There
are 11 predefined fill patterns. In addition you can fill a shape in with
the background color or a user-defined pattern. The names for the predefined
patterns are found in 'fill_patterns' in <graphics.h>:
 
     Name           Value     Description
     EMPTY_FILL       0       Fill with background color
     SOLID_FILL       1       Solid fill
     LINE_FILL        2       Fill with horizontal lines
     LTSLASH_FILL     3       Fill with ///, regular lines
     SLASH_FILL       4       Fill with ///, thick lines
     BKSLASH_FILL     5       Fill with \\\, thick lines
     LTBKSLASH_FILL   6       Fill with \\\, regular lines
     HATCH_FILL       7       Fill with hatch fill
     XHATCH_FILL      8       Fill with heavy hatch fill
     INTERLEAVE_FILL  9       Interleaving line fill
     WIDE_DOT_FILL   10       Widely spaced dot fill
     CLOSE_DOT_FILL  11       Closely spaced dot fill
     USER_FILL       12       User-defined fill pattern
 
    All patterns except EMPTY_FILL use the current fill color.
 
 Returns: Nothing. If coded, graphresult() returns -11 (graphics
        error) if invalid input was passed. The current fill
        pattern and fill color remain the same.
 
Note:To set a user-designed pattern, use setfillpattern(). Do
     not use setfillstyle() with a 'upattern' of USER_FILL.
 
 9.setcolor

 
  void far setcolor (int color);
 
 Remarks: setcolor sets the current drawing color to "color".
 The drawing color is the value that pixels are set to when the program draws lines, etc.

Note:- All the definations are noted from Net....

 

No comments:

Post a Comment