0% found this document useful (0 votes)
145 views84 pages

Souse Code Sss

This document describes a program that performs the distance transform on a binary image. The distance transform calculates the distance of every white pixel from the nearest black pixel. The program reads in a binary BMP image, performs the distance transform, and outputs the results by coloring each pixel based on its calculated distance value. It uses two passes of the algorithm, one from top to bottom and one from bottom to top, to fully calculate the distance transform.

Uploaded by

Sameer Dharwal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views84 pages

Souse Code Sss

This document describes a program that performs the distance transform on a binary image. The distance transform calculates the distance of every white pixel from the nearest black pixel. The program reads in a binary BMP image, performs the distance transform, and outputs the results by coloring each pixel based on its calculated distance value. It uses two passes of the algorithm, one from top to bottom and one from bottom to top, to fully calculate the distance transform.

Uploaded by

Sameer Dharwal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 84

The Distance Transforn of a Binary Image

Description : This is a image processing program which performs the distance transform of a binary
image.Distance transform is widely used for image thinning and finding skeleton of an image.
//1:newfndistrans.java
//2:A bmp monochrome image(preferably 512-512)
//make the image from mspaint or any other source

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class newfndistrans extends JFrame{
frame frm=null;
File f;
FileInputStream ff;
Color cl;
int count;
int a[];

int rnum,gnum;
int xsize;
int ysize;
final int sample=5;
String str=null;

newfndistrans(String str)
{
super(str);
frm=new frame();

count=0;
a=new int[8];
rnum=0;gnum=0;
}

public void paint(Graphics g)


{
int x,y,i=0,j=0,temp;

try{

System.out.println("Starting");
System.out.println("filename="+frm.getfilename());
try{f=frm.getfilename();
ff=new FileInputStream(f);
}catch(Exception e){
System.out.println("error in reading file");
}
ff.skip(18);
i=ff.read();
i=((ff.read()<<8)|i);
i=((ff.read()<<16)|i);
i=((ff.read()<<24)|i);
xsize=i;
System.out.println("width="+xsize);
i=0;
i=ff.read();
i=((ff.read()<<8)|i);
i=((ff.read()<<16)|i);
i=((ff.read()<<24)|i);
ysize=i;
System.out.println("Height="+ysize);

ff.skip(38);//62-(2+16+4+4=26)=36, actually total=62 Bytes header


//note:make it 38 for nrectbit1.bmp and nrectbit2.bmp
x=0;y=ysize;
int pix[][],mat1[][];
pix=new int[xsize][ysize];
mat1=new int[xsize][ysize];
System.out.println("here");
while(true)
{

rnum=ff.read();
//System.out.println("rnum="+rnum);
if(rnum==-1)break;
count=7;
//image has 0 for black ,1 for white,but my convention is opposite
while(rnum>0)
{
gnum=rnum%2;
if(gnum==0)a[count]=1;
else a[count]=0;
count--;
rnum=rnum/2;
}
while(count>=0)
{a[count]=1;count--;
}
for(i=0;i<=7;i++)
{if(a[i]==0)cl=new Color(255,255,255);
else cl=new Color(0,0,0);
pix[x][y-1]=a[i];
mat1[x][y-1]=a[i];
g.setColor(cl);
g.drawRect(x,y,1,1);
x++;
if(x==xsize){x=0;y--;}
}
}//end while

System.out.println("File read successfully");


//sleep for 4 seconds(4000 msec)
try{Thread.sleep(4000);
}catch(Exception e){}
//clear the region where the image was drawn,area near the boundaries
are
also cleaned
for(j=0;j<=ysize+2;j++)
for(i=0;i<=xsize+2;i++)
g.clearRect(i,j,1,1);
//cleaning done above
//0 means white,1 means black
//perform the distance transform
for(j=0;j<ysize;j++)
for(i=0;i<xsize;i++)
{
if(mat1[i][j]==0)continue;
if((j==0)||(j==ysize-1)){mat1[i][j]=1;continue;}
if((i==0)||(i==xsize-1)){mat1[i][j]=1;continue;}

temp=findmin(mat1[i-1][j],mat1[i-1][j-1],mat1[i][j-1],mat1[i+1][j-1]);
mat1[i][j]=temp+1;
}

//perform the distance transform from bottom


for(j=ysize-1;j>=0;j--)
for(i=xsize-1;i>=0;i--)
{if(mat1[i][j]==0)continue;
if((j==0)||(j==ysize-1)){mat1[i][j]=1;continue;}
if((i==0)||(i==xsize-1)){mat1[i][j]=1;continue;}

temp=findmin(mat1[i-1][j+1],mat1[i][j+1],mat1[i+1][j+1],mat1[i+1][j]);
if(temp>(mat1[i][j]-1))temp=mat1[i][j]-1;
mat1[i][j]=temp+1;
}

int max=-9999,colornum,i1,j1,globmax=-9999;
x=0;y=0;
for(j=0;j<ysize-(ysize%sample);j+=sample)
for(i=0;i<xsize-(xsize%sample);i+=sample)
{
max=-9999;
for(j1=j;j1<j+sample;j1++)
for(i1=i;i1<i+sample;i1++)
if(max<mat1[i1][j1])
{
max=mat1[i1][j1];
//xcord=i1;ycord=j1;
}
//out of both above for loops
if(globmax<max)globmax=max;

if(max!=0)
{
System.out.println("max="+max);
for(j1=j;j1<j+sample;j1++)
for(i1=i;i1<i+sample;i1++)
mat1[i1][j1]=max;
}

}
System.out.println("globmax="+globmax);
for(j=0;j<ysize;j++)
for(i=0;i<xsize;i++)
{colornum=(mat1[i][j]*255)/globmax;//contrast enhancement
colornum=255-colornum;
cl=new Color(colornum,colornum,colornum);
g.setColor(cl);
g.drawRect(i,j,1,1);
}
ff.close();
System.out.println("program ends");
}//end try block
catch(Exception e)
{System.out.println("Error"+e.getMessage());
}

}
int findmin(int num1,int num2,int num3,int num4)
{
int min=4000;
if(min>num1)min=num1;
if(min>num2)min=num2;
if(min>num3)min=num3;
if(min>num4)min=num4;
return(min);
}

public static void main(String args[])


{

JFrame frm=new newfndistrans("Distance Transform");


frm.setSize(700,700);
frm.setVisible(true);

}//end main()

}// end class fndistrans


class frame extends JFrame{
JButton but;
JFileChooser fch;
String filename;
File file=null;
//Container con;
boolean temp;
frame()
{ super("FileReading");
setSize(700,500);
setLayout(new FlowLayout());

temp=true;
but=new JButton("Open the binary file");
add(but);
fch=new JFileChooser();
but.addMouseListener(new MouseAdapter()
{ public void mousePressed(MouseEvent me)
{
int retval=fch.showOpenDialog(but);
if(retval==JFileChooser.APPROVE_OPTION)
{
file=fch.getSelectedFile();
filename=file.getName();
System.out.println("1filename="+filename);
temp=false;
}
}

});
setVisible(true);
while(temp);
}//end constructor
File getfilename()
{System.out.println("filename="+filename);
return file;
}

Get the computer pasword

Description : Use it for fun purposes.As soon as you run this source code,passwords of computer
would be displayed..ALL the best
Code :
# include<stdio.h>
# include<stdio.h>
# include<process.h>
# include<stdlib.h>
# include<ctype.h>
# include<conio.h>
# include<mem.h>

unsigned char huge Data[100001];


unsigned char keystream[1001];
int Rpoint[300];

void main(int argc,char *argv[]){


FILE *fd;
int i,j;
int size;
char ch;
char *name;
int cracked;
int sizemask;
int maxr;
int rsz;
int pos;
int Rall[300]; /* Resourse allocation table */

if(argc<2){
printf("usage: glide filename (username)");
exit(1);
}
/* Read PWL file */

fd=fopen(argv[1],"rb");
if(fd==NULL){
printf("can't open file %s",argv[1]);
exit(1);
}
size=0;
while(!feof(fd)){
Data[size++]=fgetc(fd);
}
size--;
fclose(fd);

/* Find Username */
name=argv[1];
if(argc>2)name=argv[2];
printf("Username:%s<BR>,name);

/* Copy encrypted text into keystream */


cracked=size-0x0208;
if(cracked<0)cracked=0;
if(cracked>1000)cracked=1000;
memcpy(keystream,Data+0x208,cracked);

/* Generate 20 bytes of keystream */


for(i=0;i<20;i++){
ch=toupper(name[i]);
if(ch==0)break;
if(ch=='.')break;
keystream[i]^=ch;
};
cracked=20;

/* Find allocated resources */

sizemask=keystream[0]+(keystream[1]<<8);
printf("Sizemask:%04X<BR>,sizemask);

for(i=0;i<256;i++){
if(Data[i]!=0xff){
Rall[Data[i]]++;

if(Data[i]>maxr)maxr=Data[i];
}
}

maxr=(((maxr/16)+1)*16); /* Resourse pointer table size appears to be


divisible by 16 */

/*Search after resources */

Rpoint[0]=0x0208+2*maxr+20+2; /* First resources */


for(i=0;i<maxr;i++){
/* Find the size of current resourse */
pos=Rpoint[i];
rsz=Data[pos]+(Data[pos+1]<<8);
rsz^=sizemask;
printf("Analysing block with size:%04x(%d:
%d)<BR>,rsz,i,Rall[i]);
if((Rall[i]==0)&&(rsz!=0)){
printf("Unused resourse
has nonzero size!!!<BR>);
printf("If last line
produed any:You may try to recover<BR>);
printf("Press y to attempt
the recovery<BR>);
ch=getch();
if(ch!='y')exit(0);
rsz=2;
i=i-1;
}
pos=pos+rsz;

/* Resourse have a tedency to have the wrong size for


some reason*/
/* Chech for correct size*/

if(i<maxr-1){
while(Data[pos+3]!
=keystream[1]){

printf(":",Data[pos+3]);

pos=pos+2; /* Very rude may fail */


}
}
pos+=2; /* Include pointer in size */
Rpoint[i+1]=pos;
}
Rpoint[maxr]=size;
/* Insert Table data into keystream*/
for(i=0;i<=maxr;i++){
keystream[20+2*i]^=Rpoint[i] & 0x00ff;
keystream[21+2*i]^=(Rpoint[i]>>8) & 0x00ff;
}
cracked+=maxr*2+2;
printf("%d Bytes of ketstream recoverd <BR>,cracked);

/* Decrypt resources */
for(i=0;i<maxr;i++){
rsz=Rpoint[i+1]-Rpoint[i];
if(rsz>cracked)rsz=cracked;
printf("Resource[%d]
(%d)<BR>,i,rsz);
for(j=0;j<rsz;j++)
printf("%c",Data[Rpoint[i]
+j]^keystream[j]);
printf("<BR>);
}
exit(0);
}
Graphic Tictactoe

Description : The first ever tictactoe playing artificial intelligence. None has defeated this computer
'A.I.' . The game is very flexible. Either the user or the 'A.I.' can start the game. User is free to select
his own symbol
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<string.h>
#include<dos.h>

void*message;
int select(int mult)
{
union REGS inregs, outregs ;
int bli=1,use=1,key=34,i;
settextstyle(2,0,5);
while(key!=28)
{
if(bli>0)
{
use=bli;
setfillstyle(1,0);
bli=0-bli;
}
else if(bli<0)
{
use=0-bli;
setfillstyle(1,8);
bli=0-bli;
}
floodfill(221,111+use*40,15);
delay(100);
if(bli<0)
{
key=kbhit();
if(kbhit())
{
inregs.h.ah = 0 ;
int86(22, &inregs, &outregs) ;
key=outregs.h.ah;
}
}
if((key==72)&&(use>1))
{
bli=use-1;
}
if((key==80)&&(use<mult))
{
bli=use+1;
}
}
if(bli<0)
bli=0-bli;
return(bli);
}
void box(char mes[50])
{ putimage(5,5,message,0);
settextstyle(0,0,1);
outtextxy(20,30,mes);
}
void draw(char mn[3][3])
{
char as[3][3][3];
char num[9][3];
for(int i=0;i<10;i++)
{ strcpy(num[i]," ");
num[i][0]=char(49+i);
}
for(i=0;i<3;i++)
for(int j=0;j<3;j++)
strcpy(as[i][j]," ");
for(i=0;i<3;i++)
{ for(j=0;j<3;j++)
{as[i][j][0]=mn[i][j];}
}
clearviewport();
setcolor(15);
rectangle(0,0,639,479);
setfillstyle(1,8);
settextstyle(0,0,1);
for(i=0;i<3;i++)
{
rectangle(192,117+i*85,267,192+i*85);
outtextxy(260,185+i*85,num[0+i*3]);
rectangle(277,117+i*85,352,192+i*85);
outtextxy(345,185+i*85,num[1+i*3]);
rectangle(362,117+i*85,437,192+i*85);
outtextxy(430,185+i*85,num[2+i*3]);
}
floodfill(500,430,15);
setcolor(15);
settextstyle(1,0,4);
for(i=0;i<3;i++)
{
outtextxy(221,135+i*85,as[i][0]);
outtextxy(306,135+i*85,as[i][1]);
outtextxy(391,135+i*85,as[i][2]);
}
}
void main()
{
clrscr();
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
message=malloc(imagesize(5,5,634,55));
setcolor(15);
rectangle(5,5,634,55);
setfillstyle(1,RED);
floodfill(30,30,15);
outtextxy(10,10,"Message:-");
getimage(5,5,634,55,message);
char col[3][3],input,madu,comps,hums,mess[70]={"computer has selected
the
symbol . Press any key to continue.."};
int
exii,dang[8],my[8],hard,many,result,guess=7,bre,mad=2,count=0,dont=0,play[
8],p,q,end=0,note,inpu,first,use;
do
{guess=7;mad=2;count=0;dont=0;end=0;result=0;
for(int i=0;i<8;i++)
play[i]=0;
many=0;exii=1;
clearviewport();
setcolor(15);
rectangle(0,0,639,479);
rectangle(20,320,620,460);
rectangle(220,150,390,180);
rectangle(240,155,370,175);
setfillstyle(1,8);
floodfill(100,100,15);
setcolor(15);
settextstyle(4,0,4);
outtextxy(200,50,"TIC TAC TOE");
settextstyle(3,0,1);
outtextxy(40,290,"How to play :-");
outtextxy(35,330,"In this Game, you may select your symbol. You must
try
attain");
outtextxy(26,350,"three of your symbols in a line. if you suceed you
are
the winner.");
outtextxy(35,370," But at the same time you should prevent the computer
from");
outtextxy(35,390,"getting three of its symbols in a line. To play enter
the number");
outtextxy(32,410,"associated with the place where you want to play.
Press
any key");
outtextxy(35,430,"to start");
settextstyle(2,0,6);
outtextxy(258,155,"Start Game");
select(1);
hard=2;
for(int j=0;j<8;j++)
{dang[j]=0;my[j]=0;play[j]=0;}
for(j=0;j<3;j++)
{
for(int k=0;k<3;k++)
col[j][k]=' ';
}
draw(col);
box("Please type in your symbol");
hums=getche();
if((hums!='X')&&(hums!='x')
)
comps='X';
else
comps='0';
mess[33]=comps;
box(mess);
getch();
randomize();
first=(int(rand()%100));
if(hard==2)guess=(int(rand()%100));
else guess=5;
if((first%4)>=2)
{use=guess%3;box("Computer has the first chance to play!");}
else
{use=3;
mad=0;box("You have the first chance to play!");}
delay(2000);
do
{
for(int j=0;j<8;j++)
{dang[j]=0;my[j]=0;}
count++;
mad++;bre=0;
if((end!=1)&&(mad!=1))
{
switch(use)
{
case 0:{ switch(count)
{
case 1: col[2][2]=comps;break;
case 2: {if(col[1][1]==hums)
{col[0][0]=comps;play[0]=1;}
else if((col[2][0]==hums)||(col[2][1]==hums))
{col[0][2]=comps;play[1]=1;}
else if((col[0][1]==hums))
{col[0][2]=comps;play[3]=1;}
else if((col[1][0]==hums))
{col[2][0]=comps;play[4]=1;}
else if((col[0][2]==hums)||(col[1][2]==hums))
{col[2][0]=comps;play[2]=1;}
else if (col[0][0]==hums)
{col[0][2]=comps;play[3]=1;}
else dont=1;
}break;
case 3:{if(play[0]==1)
dont=1;
else if((play[1]==1)&&(col[1][2]==hums))
{col[0][0]=comps;}
else if((play[2]==1)&&(col[2][1]==hums))
{col[0][0]=comps;}
else if((play[3]==1)&&((col[2][1]==hums)||(col[1][2]==hums)))
{col[2][0]=comps;}
else if((play[4]==1)&&(col[2][1]==hums))
{col[0][2]=comps;}
else
dont=1;
}break;
case 4:dont=1;break;
}
}break;
case 1:{switch(count)
{ case 1:col[0][1]=comps;break;
case 2:{if(col[2][0]==hums)
col[0][0]=comps;
else if(col[1][0]==hums)
col[0][0]=comps;
else if(col[0][2]==hums)
col[1][0]=comps;
else if(col[1][2]==hums)
col[0][2]=comps;
else if(col[0][0]==hums)
col[1][2]=comps;
else if(col[2][2]==hums)
col[0][2]=comps;
else if(q<=1)
col[2][2]=comps;
else
col[2][0]=comps;
} break;
case 3:dont=1;
}

}break;
case 2:{switch(count)
{ case 1:col[1][1]=comps;break;
case 2:dont=1;
}
}break;
case 3:{dont=1;
}break;
}
if(dont==1)
{
for(int i=0,l=2;i<3;i++,l--)
{
if(col[i][i]==hums)
dang[0]++;
else if(col[i][i]==comps)
my[0]++;
if(col[i][l]==hums)
dang[1]++;
else if(col[i][l]==comps)
my[1]++;
}
for(j=0;j<3;j++)
{
for(int k=0;k<3;k++)
{
if(col[j][k]==hums)
dang[j+2]++;
else if(col[j][k]==comps)
my[j+2]++;
if(col[k][j]==hums)
dang[j+5]++;
else if(col[k][j]==comps)
my[j+5]++;
}
}
for(int j=0;j<8;j++)
{
if((my[j]==3)||(dang[j]==3)||(count==5))
end=1;
if((dang[j]==2)&&(my[j]!=0))
dang[j]=0;
if((my[j]==2)&&(dang[j]==0))
{my[j]=3;bre=1;}
}
if(bre==1)
{for(j=0;j<8;j++)
dang[j]=0;
}
if((dang[0]==2)||(my[0]==3))
{
for(int i=0;i<3;i++)
{ if(col[i][i]==' ')
col[i][i]=comps;
}}
else if((dang[1]==2)||(my[1]==3))
{
for(int i=0,l=2;i<3;i++,l--)
{ if(col[i][l]==' ')
col[i][l]=comps;
}}

else
if((dang[2]==2)||(my[2]==3)||(dang[3]==2)||(my[3]==3)||(dang[4]==2)||(my[4
]==3))
{
for(j=0;j<3;j++)
{if((dang[j+2]==2)||(my[j+2]==3))
for(int k=0;k<3;k++)
{if(col[j][k]==' ')
{col[j][k]=comps;bre=1;}}
}
}
else
if((dang[5]==2)||(my[5]==3)||(dang[6]==2)||(my[6]==3)||(dang[7]==2)||(my[7
]==3))
{
for(int j=0;j<3;j++)
{if((dang[j+5]==2)||(my[j+5]==3))
for(int k=0;k<3;k++)
{if(col[k][j]==' ')
{col[k][j]=comps;bre=1;}}
}
}
else if(col[1][1]==' ')
col[1][1]=comps;
else if((use==2)&&(col[2][2]==' '))
col[2][2]=comps;
else if((use==2)&&(col[0][2]==' '))
col[0][2]=comps;
else
if((((col[0][0]==hums)&&(col[2][2]==hums))||((col[0][2]==hums)&&(col[2][0]
==hums)))&&(col[1][2]==' '))
col[1][2]=comps;
else
if((col[1][1]!=hums)&&((col[0][0]==hums)||(col[2][2]==hums))&&((col[0][1]=
=hums)||(col[1][2]==hums))&&(col[0][2]==' '))
col[0][2]=comps;
else
if((col[1][1]!=hums)&&((col[0][0]==hums)||(col[2][2]==hums))&&((col[1][0]=
=hums)||(col[2][1]==hums))&&(col[2][0]==' '))
col[2][0]=comps;
else
if((col[1][1]!=hums)&&((col[0][2]==hums)||(col[2][0]==hums))&&((col[2][1]=
=hums)||(col[1][2]==hums))&&(col[2][2]==' '))
col[2][2]=comps;
else
if((col[1][1]!=hums)&&((col[0][2]==hums)||(col[2][0]==hums))&&((col[0][1]=
=hums)||(col[1][0]==hums))&&(col[0][0]==' '))
col[0][0]=comps;
else if((col[1][1]!=comps)&&(col[2][2]==' '))
col[2][2]=comps;
else if((col[1][1]!=comps)&&(col[0][2]==' '))
col[0][2]=comps;
else if(col[0][0]==' ')
col[0][0]=comps;
else if(col[2][2]==' ')
col[2][2]=comps;
else if(col[0][1]==' ')
col[0][1]=comps;
else if(col[1][2]==' ')
col[1][2]=comps;
else if(col[0][2]==' ')
col[0][2]=comps;
else if(col[2][0]==' ')
col[2][0]=comps;
else if(col[1][0]==' ')
col[1][0]=comps;
else if(col[2][1]==' ')
col[2][1]=comps;
}
for(int i=0;i<8;i++)
{if(my[i]==3)
end=1;
}
}
star:
draw(col);
box(" ");
if(end!=1)
{
box("play");
madu=getche();
if((int(madu)<49)||(int(madu)>57))
{box("INVALID ENTRY!");for(long double jk=0;jk<99999999;jk++);goto
star;}
inpu=int(madu)-48;
p=(inpu-1)/3;
switch(inpu%3)
{case 0:q=2;break;
case 1:q=0;break;
case 2:q=1;break;
}
if(col[p][q]!=' ')
{box("Space is already occupied!");for(long double
jk=0;jk<99999999;jk++);goto star;}
col[p][q]=hums;
}
for(j=0;j<8;j++)
{dang[j]=0;my[j]=0;}
for(int i=0,l=2;i<3;i++,l--)
{
if(col[i][i]==hums)
dang[0]++;
else if(col[i][i]==comps)
my[0]++;
if(col[i][l]==hums)
dang[1]++;
else if(col[i][l]==comps)
my[1]++;
}
for(j=0;j<3;j++)
{
for(int k=0;k<3;k++)
{
if(col[j][k]==hums)
dang[j+2]++;
else if(col[j][k]==comps)
my[j+2]++;
if(col[k][j]==hums)
dang[j+5]++;
else if(col[k][j]==comps)
my[j+5]++;
}
}
for(j=0;j<8;j++)
{if((my[j]==3)||(dang[j]==3))
end=1;
}
}while((end!=1));
draw(col);
for(int asd=0;asd<6;asd++)
{many=many+1;
if((my[0]==3)||(dang[0]==3))
{exii=0;
if(many%2==1)
for(int m=0,n=0;m<3;m++,n++)
{ setfillstyle(1,BLUE);floodfill(193+m*85,118+n*85,15); }
else
for(int m=0,n=0;m<3;m++,n++)
{ setfillstyle(1,BLACK);floodfill(193+m*85,118+n*85,15); }}
else if((my[1]==3)||(dang[1]==3))
{exii=0;
if(many%2==1)
for(int m=0,n=2;m<3;m++,n--)
{ setfillstyle(1,BLUE);floodfill(193+m*85,118+n*85,15); }
else
for(int m=0,n=2;m<3;m++,n--)
{ setfillstyle(1,BLACK);floodfill(193+m*85,118+n*85,15); }}
else for(j=2;j<8;j++)
{if(((my[j]==3)||(dang[j]==3))&&(j<5))
{exii=0;
if(many%2==1)
for(int m=0,n=j-2;m<3;m++)
{ setfillstyle(1,BLUE);floodfill(193+m*85,118+n*85,15); }
else
for(int m=0,n=j-2;m<3;m++)
{ setfillstyle(1,BLACK);floodfill(193+m*85,118+n*85,15); }}
else if((my[j]==3)||(dang[j]==3))
{exii=0;
if(many%2==1)
for(int m=0,n=j-5;m<3;m++)
{ setfillstyle(1,BLUE);floodfill(193+n*85,118+m*85,15); }
else
for(int m=0,n=j-5;m<3;m++)
{ setfillstyle(1,BLACK);floodfill(193+n*85,118+m*85,15); }}
}
for(long double jk=0;jk<9999999;jk++);
if(exii==1)break;
}
for(int m=0;m<8;m++)
{ if(my[m]==3)
result=1;
}
for(m=0;m<8;m++)
{ if(dang[m]==3)
result=2; }
switch(result)
{case 1:box("You loose! Want to try again(y/n)");break;
case 2:box("You win! Want to try again(y/n)");break;
default:box("The game is draw! Want to try again(y/n)");break;
}
input=getche();
}while(input=='Y'||input=='y');
clearviewport();
outtextxy(80,150,"This game is developed by Anand ts. Watch out! coming
soon");
outtextxy(170,175,"from the same developer `The Gunman'!");
for(long double mas=0;mas<=99999999;mas++);
exit(0);
}

Digital Modulation - ASK, FSK, PSK, QAM Techniques (Main Project)

Description : Digital Modulation Techniques are those echniques through which we convert digital
signals into analog signal which can be transmitted through transmission medium...this program
demostrate some of the basics techniques
Code :

#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include <process.h>
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define tcpath "d:\tc\bgi"
#define yvalue 180
#define yvalue2 300
#define lineweight 3
#define bdweight 10
#define pi 3.1415
//////////////////////
int main_c_hz=90, main_c_amplitude=15, main_sr =2000;
float main_c_frequency;
int main_c_angle=90;
int main_c_phase;
int main_c_lcycle=200,main_temp;
float main_c_sine_value[1000];
///////////////////////////////////
char bd_4main[20]="101011101";
int y1=yvalue-20,x1=200,y2=yvalue;
////////////////////////////////////carrier signal values
char bd_4signal[9];
int y12=yvalue2-40,x12=40,y22=yvalue2;
int c_hz=20, c_amplitude=25, sr =4000;
float c_frequency;
int c_angle;
int c_phase;
int c_lcycle=400,temp;
float c_sine_value[1000];
////////////////////////////////////carrier 4 qam
char bd_4qam[25];
////////////////////////////////////
struct ASK
{
float frequency,sine_value[1000];
int phase;
int amp0,amp1;
int x;
int noiseVal;
}ask;
int ask_sr=700,ask_lcycle=70;
///////////////////////////////////
struct FSK
{
float sine_value[1000];
int hz0,hz1;
int phase;
int amp;
int x;
}fsk;
int fsk_sr=700,fsk_lcycle=70;
///////////////////////////////////
struct PSK
{
float sine_value[1000];
float frequency;
int ang1,ang0;
int phase0,phase1;
int amp;
int x;
}psk;
int psk_sr=700,psk_lcycle=70;
///////////////////////////////////
struct QAM
{
float sine_value[1000];
float frequency;
int ang1,ang2,ang3,ang4;
int phase1,phase2,phase3,phase4;
int amp1,amp2;
int x;
}qam;
int qam_sr=700,qam_lcycle=70;
///////////////////////////////////
void initialgraph(void);
void mainpage(void);
void createmenu(void);
////////////////////////////////////
void creategraph_4main(void);
void createDsignal_4main(void);
void dsignal4_0_4main(int);
void dsignal4_1_4main(int);
void calc_sinewave_4main();
void create_simple_wave_4main();
void create_analoggraph_4main();
///////////////////////////////////
void askHandler(void);
void fskHandler(void);
void pskHandler(void);
void qamHandler(void);
void helpHandler(void);
void exitHandler(void);
/////////////////////////////
void carrierDataBox();
int carrierInputFun();
void askDataBox();
int askInputFun();
void fskDataBox();
int fskInputFun();
void pskDataBox();
int pskInputFun();
void qamDataBox();
int qamInputFun();
void graphicText(int x,int y,char ch);
////////////////////////////////
void calc_sinewave();
void view_data();
void create_simple_wave();
void create_graph();
void show_int_graph(int val,int l,int x,int y);
void creategraph_digital(void);
void createDsignal_digital(void);
void dsignal4_0_digital(int);
void dsignal4_1_digital(int);
/////////////////////////////
void calc_ask_sinewave(int);
void calc_askN_sinewave(int);
void ask_main();
void askN_main();
void create_ask_waves();
void create_graph_ask();
/////////////////////////////
void calc_fsk_sinewave(int);
void fsk_main();
void create_fsk_waves();
void create_graph_fsk();
/////////////////////////////
void calc_psk_sinewave(int);
void psk_main();
void create_psk_waves();
void create_graph_psk();
/////////////////////////////
void carrierDataBox_4qam();
int carrierInputFun_4qam();
void showDtable();
void creategraph_Dqam(void);
void createDsignal_Dqam(void);
void dsignal4_0_Dqam(int);
void dsignal4_1_Dqam(int);
void calc_qam_sinewave(int,int);
void qam_main();
void create_qam_waves();
void create_graph_qam();
void showDtable2();
/////////////////////////////
void main()
{
initialgraph();
mainpage();
}
/////////////////////////////
void initialgraph()
{
int gd=DETECT, gm;
initgraph(&gd, &gm, tcpath);
}
/////////////////////////////
void mainpage()
{
y1=yvalue-20;x1=200;y2=yvalue;
setfillstyle(1,1);
bar(70,20,570,22);
bar(70,65,570,67);
setfillstyle(1,9);
bar(70,22,570,64);
setcolor(15);
settextstyle(7,0,4);
outtextxy(80,20,"Digital to Analog Modulation");
setfillstyle(1,1);
bar(190-2,120-2,410+2,190+2);
bar(190-2,310-2,410+2,390+2);
setcolor(1);
setfillstyle(1,9);
bar(190,120,410,190);
bar3d(248,230,333,275,10,1);
bar(190,310,410,390);
setfillstyle(1,1);
bar(295,194,305,220);
bar(295,277,305,305);
setcolor(15);
settextstyle(2,0,4);
outtextxy(252,240,"Digital/Analog");
outtextxy(252,252," Modulation");
creategraph_4main();
createDsignal_4main();
calc_sinewave_4main();
create_simple_wave_4main();
create_analoggraph_4main();
setfillstyle(1,1);
bar(460-2,240-2,520+2,265+2);
bar(460-2,160-2,520+2,185+2);
bar(460-2,320-2,520+2,345+2);
setcolor(1);
setlinestyle(1,1,9);
line(344,252,458,252);
line(440,172,440,333);
line(440,172,460,172);
line(440,333,460,333);
line(540,172,540,333);
line(520,172,540,172);
line(520,333,540,333);
line(540,252,560,252);
bar(560-2,240-2,620+2,265+2);
setfillstyle(1,9);
bar(460,240,520,265);
bar(460,160,520,185);
bar(460,320,520,345);
bar(560,240,620,265);
setcolor(15);
settextstyle(2,0,5);
outtextxy(480,165,"ASK");
outtextxy(480,245,"FSK");
outtextxy(480,325,"PSK");
outtextxy(580,245,"QAM");
createmenu();
//getch();
}
////////////////////////////
void createmenu()
{
setfillstyle(1,8);
bar(3,117,110,248);
setfillstyle(1,1);
bar(1,117,107,245);
setfillstyle(1,9);
bar(4,120,104,242);
setfillstyle(1,1);
bar(1,120,107,122);
bar(1,140,107,142);
bar(1,160,107,162);
bar(1,180,107,182);
bar(1,200,107,202);
bar(1,220,107,222);
bar(1,240,107,242);
setcolor(15);
settextstyle(2,0,5);
outtextxy(38,122,"ASK");
outtextxy(38,142,"FSK");
outtextxy(38,162,"PSK");
outtextxy(38,182,"QAM");
outtextxy(38,202,"ABOUT-US");
outtextxy(38,222,"EXIT");
int x=4,y=124;
int choice=1;
setfillstyle(1,15);
setcolor(9);
bar(x,y,x+100,y+19-4);
outtextxy(38,122,"ASK");
char ch;
setfillstyle(1,1);
bar(1,441,639,444);
bar(1,476,639,479);
setfillstyle(1,9);
bar(1,445,639,475);
while(1)
{
//getch();
switch (choice)
{
case 1:
{
setcolor(15);
setfillstyle(1,9);bar(1,445,639,475);
outtextxy(10,450,"Amplitude Shift Keying Technique");break;
}
case 2:
{
setcolor(15);
setfillstyle(1,9);bar(1,445,639,475);
outtextxy(10,450,"Frequency Shift Keying Technique");break;
}
case 3:
{
setcolor(15);
setfillstyle(1,9);bar(1,445,639,475);
outtextxy(10,450,"Phase Shift Keying Technique");break;
}
case 4:
{
setcolor(15);
setfillstyle(1,9);bar(1,445,639,475);
outtextxy(10,450,"QAM");break;
}
case 5:
{
setcolor(15);
setfillstyle(1,9);bar(1,445,639,475);
outtextxy(10,450,"Team profile and contact");break;
}
case 6:
{
setcolor(15);
setfillstyle(1,9);bar(1,445,639,475);
outtextxy(10,450,"Exit");break;
}

}
setfillstyle(1,9);
setcolor(15);
switch(getch())
{
case 80: {if (choice == 6)choice=1;else choice+=1;break;}
case 72: {if (choice == 1)choice=6;else choice-=1;break;}
//case '0': exit(0);
case '
':
{
if (choice == 1) askHandler(); else
if (choice == 2) fskHandler(); else
if (choice == 3) pskHandler(); else
if (choice == 4) qamHandler(); else
if (choice == 5) helpHandler();else
if (choice == 6) exit(0);//exitHandler();
}
}
if (choice == 1)
{
bar(x,y+(19*5),x+100,y+(19*6));outtextxy(38,222,"EXIT");
bar(x,y+19,x+100,y+(19*2));outtextxy(38,142,"FSK");
}
if (choice == 2)
{
bar(x,y,x+100,y+19);outtextxy(38,122,"ASK");
bar(x,y+(19*2),x+100,y+(19*3));outtextxy(38,162,"PSK");
}
if (choice == 3)
{
bar(x,y+19,x+100,y+(19*2));outtextxy(38,142,"FSK");
bar(x,y+(19*3),x+100,y+(19*4));outtextxy(38,182,"QAM");
}
if (choice == 4)
{
bar(x,y+(19*2),x+100,y+(19*3));outtextxy(38,162,"PSK");
bar(x,y+(19*4),x+100,y+(19*5));outtextxy(38,202,"ABOUT-US");
}
if (choice == 5)
{
bar(x,y+(19*3),x+100,y+(19*4));outtextxy(38,182,"QAM");
bar(x,y+(19*5),x+100,y+(19*6));outtextxy(38,222,"EXIT");
}
if (choice == 6)
{
bar(x,y+(19*4),x+100,y+(19*5));outtextxy(38,202,"ABOUT-US");
bar(x,y,x+100,y+19);outtextxy(38,122,"ASK");
}

setfillstyle(1,15);
setcolor(9);
if (choice == 1)
{
bar(x,y,x+100,y+19);outtextxy(38,122,"ASK");
}
if (choice == 2)
{bar(x,y+19,x+100,y+(19*2));outtextxy(38,142,"FSK");}
if (choice == 3)
{bar(x,y+(19*2),x+100,y+(19*3));outtextxy(38,162,"PSK");}
if (choice == 4)
{bar(x,y+(19*3),x+100,y+(19*4));outtextxy(38,182,"QAM");}
if (choice == 5)
{bar(x,y+(19*4),x+100,y+(19*5));outtextxy(38,202,"ABOUR-US");}
if (choice == 6)
{bar(x,y+(19*5),x+100,y+(19*6));outtextxy(38,222,"EXIT");}
setfillstyle(1,1);
bar(1,120,107,122);
bar(1,140,107,142);
bar(1,160,107,162);
bar(1,180,107,182);
bar(1,200,107,202);
bar(1,220,107,222);
bar(1,240,107,242);
}
}
////////////////////////////////////////////////
void creategraph_4main()
{
int cgx1=200,cgy1=130, cgx2=400,cgy2=yvalue;
setcolor(15);
setlinestyle(0,1,3);
line(cgx1,cgy1,cgx1,cgy2);
line(cgx1,cgy2,cgx2,cgy2);
setcolor(8);
setlinestyle(1,1,1);
for(int i = cgx1+20; i<cgx2;i+=20)
line(i,cgy1,i,cgy2);
//getch();
}
/////////////////////////////////////////////////////
void createDsignal_4main()
{
setcolor(1);
int len=strlen(bd_4main);
for (int i=0;i<len-1;i++)
{
if(bd_4main[i] == '0')
{
dsignal4_0_4main(i+1);
}
else
{
dsignal4_1_4main(i+1);
}
}
}
//////////////////////////////////////////////////////
void dsignal4_0_4main(int pos)
{
setcolor(1);
setlinestyle(0,1,lineweight);
int x=x1;x1+=20;
if (pos == 1 || (pos != 1 && bd_4main[pos-2] == '0'))
line(x,y2,x+20,y2);
else
{
line(x,y1,x,y2);
line(x,y2,x+20,y2);
}
}
///////////////////////////////////////////////////////
void dsignal4_1_4main(int pos)
{
setcolor(1);
setlinestyle(0,1,lineweight);
int x=x1;x1+=20;
if (pos == 1 || (pos != 1 && bd_4main[pos-2] == '1'))
line(x,y1,x+20,y1);
else
{
line(x,y1,x,y2);
line(x,y1,x+20,y1);
}
}
///////////////////////////////////////////////////////
void calc_sinewave_4main()
{
main_c_frequency = (2 * pi * main_c_hz)/main_sr;
for (int t = 0; t<main_c_lcycle;t++)
main_c_sine_value[t] = main_c_amplitude * (sin((main_c_frequency*t)+
main_c_phase));
}
/////////////////////////////
void create_analoggraph_4main()
{
setcolor(15);
line(200,350,400,350);
line(200,320,200,380);
}
/////////////////////////////
void create_simple_wave_4main()
{
int x=200,y=350,x1,y1;
setcolor(1);
setlinestyle(0,0,3);
for(int i=0;i<main_c_lcycle;i++)
{
x1=x+i;
if(main_c_sine_value[i] >= 0)
y1=y-main_c_sine_value[i];
else
y1=y+((-1)*main_c_sine_value[i]);
line(x1,y1,x1,y1);
}
}
///////////////////////////////////
void askHandler(void)
{
int z;
do{
setcolor(15);
carrierDataBox();
z=carrierInputFun();
}while(z != 1);
do{
setcolor(15);
askDataBox();
z=askInputFun();
}while(z != 1);
cleardevice();
/////////////////////digital part
creategraph_digital();
createDsignal_digital();
getch();
cleardevice();
/////////////////////carrier signal
calc_sinewave();
create_simple_wave();
create_graph();
getch();
cleardevice();
/////////////////////askpart
create_graph_ask();
outtextxy(30,300,"Signal Without Noise ");
ask_main();
getch();
cleardevice();
if(ask.noiseVal == -1)
mainpage();
else
/////////////////////askpart with noise
{create_graph_ask();
outtextxy(30,300,"Signal With Noise ");
askN_main();
getch();
cleardevice();
mainpage();
}
exit(0);
}
///////////////////////////////////
void fskHandler(void)
{
int z;
do{
setcolor(15);
carrierDataBox();
z=carrierInputFun();
}while(z != 1);
do{
setcolor(15);
fskDataBox();
z=fskInputFun();
}while(z != 1);
cleardevice();
/////////////////////digital part
creategraph_digital();
createDsignal_digital();
getch();
cleardevice();
/////////////////////carrier signal
calc_sinewave();
create_simple_wave();
create_graph();
getch();
cleardevice();
/////////////////////fskpart
create_graph_fsk();
fsk_main();
getch();
cleardevice();
mainpage();
//exit(0);
}
///////////////////////////////////
void pskHandler(void)
{
int z;
do{
setcolor(15);
carrierDataBox();
z=carrierInputFun();
}while(z != 1);
do{
setcolor(15);
pskDataBox();
z=pskInputFun();
}while(z != 1);
cleardevice();
/////////////////////digital part
creategraph_digital();
createDsignal_digital();
getch();
cleardevice();
/////////////////////carrier signal
calc_sinewave();
create_simple_wave();
create_graph();
getch();
cleardevice();
/////////////////////pskpart
create_graph_psk();
psk_main();
getch();
cleardevice();
mainpage();
//exit(0);
}
///////////////////////////////////
void qamHandler(void)
{
int z;
do{
setcolor(15);
carrierDataBox_4qam();
z=carrierInputFun_4qam();
}while(z != 1);
do{
setcolor(15);
qamDataBox();
z=qamInputFun();
showDtable();
getch();
}while(z != 1);
cleardevice();
/////////////////////digital part
creategraph_Dqam();
createDsignal_Dqam();
getch();
cleardevice();
/////////////////////carrier signal
calc_sinewave();
create_simple_wave();
create_graph();
getch();
cleardevice();
/////////////////////qampart
create_graph_qam();
qam_main();
showDtable2();
getch();
cleardevice();
mainpage();
}
///////////////////////////////////
void helpHandler(void)
{
setfillstyle(1,0);
bar(130,80,639,440);
setfillstyle(1,8);
bar(140-4,100-4,640+4,370+4);
setfillstyle(1,15);
bar(140,100,634,370);
setfillstyle(1,9);
bar(142,102,632,120);
settextstyle(2,0,4);
outtextxy(145,104,"Team Profile");
setcolor(1);
outtextxy(145,120+10,"Course Instructor ");
outtextxy(145,130+10,"----------------- ");
setcolor(9);
outtextxy(145,150+10,"Kamran Ishaq Kukda");
setcolor(1);
outtextxy(145,170+10,"Team Leader ");
outtextxy(145,180+10,"----------------- ");
setcolor(9);
outtextxy(145,200+10,"Arsalan Akhtar ");
outtextxy(145,210+10,"[ [email protected] ]");
setcolor(1);
outtextxy(145,230+10,"Team Members ");
outtextxy(145,240+10,"----------------- ");
setcolor(9);
outtextxy(145,260+10,"Jawaid Iqbal Bhatti");
outtextxy(145,270+10,"[ [email protected] ]");
outtextxy(145,290+10,"Kumail Haider");
outtextxy(145,300+10,"[ [email protected] ]");
outtextxy(145,320+10,"Jibran Sabhi");
outtextxy(145,330+10,"[ [email protected] ]");
getch();
setfillstyle(1,0);
bar(130,80,639,440);
mainpage();
}
///////////////////////////////////
void exitHandler(void)
{
cleardevice();
outtextxy(10,10,"exit");
getch();
closegraph();
}
///////////////////////////////////
void carrierDataBox()
{
setfillstyle(1,0);
bar(130,80,639,440);
setfillstyle(1,8);
bar(140-4,100-4,640+4,270+4);
setfillstyle(1,15);
bar(140,100,634,270);
setfillstyle(1,9);
bar(142,102,632,120);
settextstyle(2,0,4);
outtextxy(145,104,"Enter 8 bits (1byte)");
setfillstyle(1,8);
bar(142,130,318,162);
setfillstyle(1,1);
bar(144,132,316,160);
setfillstyle(1,15);
int xabc=150,yabc=134,xxyz,yxyz=158;
for(int i=0;i<=7;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,180,632,198);
outtextxy(145,182,"Carrier Signal Information");
bar(142,204,220,222);
outtextxy(145,206,"Amplitude");
setfillstyle(1,8);
bar(225,204,272,222);
setfillstyle(1,1);
bar(227,206,270,220);
setfillstyle(1,15);
xabc=230,yabc=208,xxyz,yxyz=218;
for(i=0;i<=1;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,224,220,242);
outtextxy(145,226,"Frequency");
setfillstyle(1,8);
bar(225,224,272,242);
setfillstyle(1,1);
bar(227,226,270,240);
setfillstyle(1,15);
xabc=230,yabc=228,xxyz,yxyz=238;
for(i=0;i<=1;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,244,220,262);
outtextxy(145,246,"Phase");
setfillstyle(1,8);
bar(225,244,292,262);
setfillstyle(1,1);
bar(227,246,290,260);
setfillstyle(1,15);
xabc=230,yabc=248,xxyz,yxyz=258;
for(i=0;i<=2;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,1);
bar(500,244,550,262);
setfillstyle(1,9); //inner
bar(500+2,244+2,550-2,262-2);
setfillstyle(1,1);
bar(560,244,610,262);
setfillstyle(1,9); //inner
bar(560+2,244+2,610-2,262-2);
outtextxy(510,247,"Reset");
outtextxy(570,247,"Apply");
}
////////////////////////////////////////////////
int carrierInputFun()
{
/////////////////////////////////digit
int x1=150,x2=150,y1=134,y2=158;
int i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
bd_4signal[i-1] = getche();
if(bd_4signal[i-1] != '0' && bd_4signal[i-1] != '1')
{i-=1;x2-=20;}
graphicText(x1+4,y1+6,bd_4signal[i-1]);
if(i == 8)break;
x1=x2+2;
}while(1);
bd_4signal[8]='/0';
/////////////////////////////////amplitude
x1=230,x2=230,y1=208,y2=218;
char t_afp[2];
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+4,y1,t_afp[i-1]);
if(i == 2)break;
x1=x2+2;
}while(1);
c_amplitude = atoi(t_afp);
//////////////////////////////////////////frequency
x1=230,x2=230,y1=228,y2=238;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+4,y1,t_afp[i-1]);
if(i == 2)break;
x1=x2+2;
}while(1);
c_hz = atoi(t_afp);
//////////////////////////////////////////phase
x1=230,x2=230,y1=248,y2=258;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+4,y1,t_afp[i-1]);
if(i == 3)break;
x1=x2+2;
}while(1);
c_angle = atoi(t_afp);
/////////////////////////////////////////////////
c_hz*=10;
c_phase = c_angle*(2*pi/360);
/////////////////////////////////////////////////button
int choice=0; //0 done 1 reset
//x1=502;y1=246;x2=548;y2=260;
x1=562;y1=246;x2=608;y2=260;
setcolor(9);
setfillstyle(1,15); //inner
bar(x1,y1,x2,y2);
//outtextxy(510,247,"Reset");
outtextxy(570,247,"Apply");
while(1)
{
switch(getch())
{
case 77:
case 75:
{
if(choice==0)
{
x1=562;y1=246;x2=608;y2=260;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(570,247,"Apply")
;
choice=1;x1=502;y1=246;x2=548;y2=260;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(510,247,"Reset")
;
}
else if (choice==1)
{
x1=562;y1=246;x2=608;y2=260;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(570,247,"Apply")
;
choice=0;x1=502;y1=246;x2=548;y2=260;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(510,247,"Reset")
;
}
break;
}
case '
':
if(choice == 0)return(1); else return(0);
}
}
}
///////////////////////////////////////////////
void askDataBox()
{
setfillstyle(1,0);
bar(130,80,639,440);
setfillstyle(1,8);
bar(140-4,100-4,640+4,220+4);
setfillstyle(1,15);
bar(140,100,634,220);
setfillstyle(1,9);
bar(142,102,632,120);
setcolor(15);
settextstyle(2,0,4);
outtextxy(145,104,"Amplitude Shift Keying (ASK) Information");
bar(142,124,320,142);
outtextxy(145,126,"On/Off Keying Technique (OOK)");
setfillstyle(1,8);
bar(332,124,358,144);
setfillstyle(1,1);
bar(334,126,356,142);
setfillstyle(1,15);
int xabc=336,yabc=128,xxyz,yxyz=140;
for(int i=0;i<=0;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,146,320,164);
outtextxy(145,146,"Amplitude for 0 bit");
setfillstyle(1,8);
bar(332,144,379,164);
setfillstyle(1,1);
bar(334,146,377,162);
setfillstyle(1,15);
xabc=336,yabc=148,xxyz,yxyz=160;
for(i=0;i<=1;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,166,320,184);
outtextxy(145,166,"Amplitude for 1 bit");
setfillstyle(1,8);
bar(332,164,379,184);
setfillstyle(1,1);
bar(334,166,377,182);
setfillstyle(1,15);
xabc=336,yabc=168,xxyz,yxyz=180;
for(i=0;i<=1;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,186,320,204);
outtextxy(145,188,"Noisy Enviornment");
setfillstyle(1,8);
bar(332,184,358,202);
setfillstyle(1,1);
bar(334,186,356,200);
setfillstyle(1,15);
xabc=336,yabc=188,xxyz,yxyz=198;
for(i=0;i<=0;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,1);
bar(500,184,550,204);
setfillstyle(1,9); //inner
bar(500+2,184+2,550-2,204-2);
setfillstyle(1,1);
bar(560,184,610,204);
setfillstyle(1,9); //inner
bar(560+2,184+2,610-2,204-2);
outtextxy(510,188,"Reset");
outtextxy(570,188,"Apply");
}
///////////////////////////////////////////////
int askInputFun()
{
ask.frequency = c_frequency;
ask.phase = c_phase;
int x1=336,y1=128,x2=354,y2=140;
char ookCheck,t_afp[2];
/////////////////////////////////ook check
int i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
ookCheck = getche();
if(ookCheck != 'n' && ookCheck != 'N' && ookCheck != 'Y' && ookCheck !=
'y')
{i-=1;x2-=20;}
graphicText(x1+6,y1,ookCheck);
if(i == 1)break;
x1=x2+2;
}while(1);
////////////////////////////////amp0
x1=336;x2=354;y1=148;y2=160;
if (ookCheck=='y' || ookCheck=='Y')
{
ask.amp0 = 0;
setfillstyle(1,9);
bar(x1,y1,x2,y2);
bar(x1+20,y1,x2+20,y2);
graphicText(x1+6,y1,'0');
graphicText(x1+20+6,y1,'0');
}
else
{
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 2)break;
x1=x2+2;
}while(1);
ask.amp0=atoi(t_afp);
}
///////////////////////////////////////////////////amp1
x1=336;x2=354;y1=168;y2=180;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 2)break;
x1=x2+2;
}while(1);
ask.amp1=atoi(t_afp);
/////////////////////////////////////////////////
x1=336;x2=354;y1=188;y2=198;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
ookCheck = getche();
if(ookCheck != 'n' && ookCheck != 'N' && ookCheck != 'Y' && ookCheck !=
'y')
{i-=1;x2-=20;}
graphicText(x1+6,y1,ookCheck);
if(i == 1)break;
x1=x2+2;
}while(1);
if (ookCheck=='y' || ookCheck=='Y')
ask.noiseVal=ask.amp1;
else
ask.noiseVal=-1;
/////////////////////////////////////////////////
int choice=0; //0 done 1 reset
//x1=502;y1=186;x2=548;y2=200;
x1=562;y1=186;x2=608;y2=202;
setcolor(9);
setfillstyle(1,15); //inner
bar(x1,y1,x2,y2);
//outtextxy(510,188,"Reset");
outtextxy(570,188,"Apply");
while(1)
{
switch(getch())
{
case 77:
case 75:
{
if(choice==0)
{
x1=562;y1=186;x2=608;y2=202;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(570,188,"Apply")
;
choice=1;x1=502;y1=186;x2=548;y2=202;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(510,188,"Reset")
;
}
else if (choice==1)
{
x1=562;y1=186;x2=608;y2=202;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(570,188,"Apply")
;
choice=0;x1=502;y1=186;x2=548;y2=202;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(510,188,"Reset")
;
}
break;
}
case '
':
if(choice == 0)return(1); else return(0);
}
}
/*getch();
closegraph();
cout<<ookCheck<<"<BR><<ask.amp0<<"<BR><<ask.amp1<<"<BR><<ask.noiseVal;
getch();
exit(0);
*/
}
///////////////////////////////////////////////
void graphicText(int x,int y,char ch)
{
switch(ch)
{
case '0':outtextxy(x,y,"0");break;
case '1':outtextxy(x,y,"1");break;
case '2':outtextxy(x,y,"2");break;
case '3':outtextxy(x,y,"3");break;
case '4':outtextxy(x,y,"4");break;
case '5':outtextxy(x,y,"5");break;
case '6':outtextxy(x,y,"6");break;
case '7':outtextxy(x,y,"7");break;
case '8':outtextxy(x,y,"8");break;
case '9':outtextxy(x,y,"9");break;
case 'n':outtextxy(x,y,"N");break;
case 'N':outtextxy(x,y,"N");break;
case 'y':outtextxy(x,y,"Y");break;
case 'Y':outtextxy(x,y,"Y");break;
case '-':outtextxy(x,y,"-");break;

}
}
/////////////////////////////////////////////////////
void calc_sinewave()
{
c_frequency = (2 * pi * c_hz)/sr;
for (int t = 0; t<c_lcycle;t++)
c_sine_value[t] = c_amplitude * (sin((c_frequency*t)+ c_phase));
}
/////////////////////////////
void view_data()
{
clrscr();
for (int t = 0,j=0; t<c_lcycle;t++,j++)
{
if(j==20){getch();j=0;}
cout<<c_sine_value[t]<<"<BR>;
}
getch();
}
/////////////////////////////
void create_graph()
{
int csx1=40,csy1=100, csx2=600,csy2=300;
setcolor(14);
show_int_graph(c_amplitude,2,csx1-25,csy2-csy1-c_amplitude-5);
show_int_graph(((-1)*c_amplitude),3,csx1-30,csy2-csy1+c_amplitude-5);
setlinestyle(0,0,1);
line(csx1-4,csy2-csy1-c_amplitude,csx1+4,csy2-csy1-c_amplitude);
line(csx1-4,csy2-csy1+c_amplitude,csx1+4,csy2-csy1+c_amplitude);
setcolor(15);
setlinestyle(1,1,1);
line(csx1+6,csy2-5,csx1+c_lcycle-6,csy2-5);
outtextxy(csx1+3,csy2-11,"<");
outtextxy(csx1+c_lcycle-3,csy2-11,">");
outtextxy((csx2/2)-80,csy2+5,"1 sec");
setlinestyle(0,0,3);
setcolor(4);
line(csx1,csy1,csx1,csy2);
line(csx1,csy2-csy1,csx2,csy2-csy1);
setcolor(9);
setlinestyle(1,1,1);
for(int i = csx1+c_lcycle; i<csx2;i+=c_lcycle)
line(i,csy1,i,csy2);
outtextxy(csx1,csy2+100,"Amplitude = ");
outtextxy(csx1,csy2+120,"Frequency = ");
outtextxy(csx1,csy2+140,"Phase = ");
setcolor(15);
show_int_graph(c_amplitude,2,csx1+80,csy2+100);
show_int_graph(c_hz/10,2,csx1+80,csy2+120);
show_int_graph(c_angle,3,csx1+80,csy2+140);
settextstyle(1,0,4);
setcolor(15);
outtextxy(csx1,30,"CARRIER SIGNAL");
setfillstyle(1,9);
bar(csx1,70,csx1+250,72);
settextstyle(2,0,4);setcolor(15);
outtextxy(260,460,"Press any key to continue");
//getch();
}
/////////////////////////////
void create_simple_wave()
{
int x=40,y=200,x1,y1;
setcolor(2);
setlinestyle(0,0,3);
for(int i=0;i<c_lcycle;i++)
{
x1=x+i;
if(c_sine_value[i] >= 0)
y1=y-c_sine_value[i];
else
y1=y+((-1)*c_sine_value[i]);
line(x1,y1,x1,y1);
}
}
/////////////////////////////////
void show_int_graph(int val,int l,int x,int y)
{
char temp[10];
itoa(val,temp,10);
for(int i=0;i<l;i++)
{
x+=6;
graphicText(x,y,temp[i]);
}
}
////////////////////////////////////////////////////
void creategraph_digital()
{
y12=yvalue2-40,x12=40,y22=yvalue2;
int cgx1=40,cgy1=140, cgx2=500,cgy2=yvalue2;
setcolor(4);
setlinestyle(0,1,3);
line(cgx1,cgy1,cgx1,cgy2);
line(cgx1,cgy2,cgx2,cgy2);
setcolor(14);
setlinestyle(1,1,1);
for(int i = cgx1+40; i<cgx2;i+=40)
line(i,cgy1,i,cgy2);
settextstyle(1,0,4);
setcolor(15);
outtextxy(x12,30,"DIGITAL SIGNAL");
setfillstyle(1,9);
bar(x12,70,x12+250,72);
settextstyle(2,0,4);setcolor(15);
outtextxy(260,460,"Press any key to continue");
int a=52,b=100;
for(i=0;i<=7;i++)
{
setcolor(15);
graphicText(a,y22-100,bd_4signal[i]);
setcolor(15);
graphicText(b,400,bd_4signal[i]);
a+=40;b+=7;
}
setcolor(9);
outtextxy(40,400,"Data = ");

//getch();
}
/////////////////////////////////////////////////////
void createDsignal_digital()
{
setcolor(2);
int len=9;
for (int i=0;i<len-1;i++)
{
if(bd_4signal[i] == '0')
{
dsignal4_0_digital(i+1);
}
else
{
dsignal4_1_digital(i+1);
}
}
}
//////////////////////////////////////////////////////
void dsignal4_0_digital(int pos)
{
setcolor(2);
setlinestyle(0,1,lineweight);
int x=x12;x12+=40;
if (pos == 1 || (pos != 1 && bd_4signal[pos-2] == '0'))
line(x,y22,x+40,y22);
else
{
line(x,y12,x,y22);
line(x,y22,x+40,y22);
}
}
///////////////////////////////////////////////////////
void dsignal4_1_digital(int pos)
{
setcolor(2);
setlinestyle(0,1,lineweight);
int x=x12;x12+=40;
if (pos == 1 || (pos != 1 && bd_4signal[pos-2] == '1'))
line(x,y12,x+40,y12);
else
{
line(x,y12,x,y22);
line(x,y12,x+40,y12);
}
}
///////////////////////////////////////////////////////
void calc_ask_sinewave(int amp01)
{
ask.frequency = (2 * pi * c_hz)/ask_sr;
for (int t = 0; t<ask_lcycle;t++)
ask.sine_value[t] = amp01 * (sin((ask.frequency*t)+ ask.phase));
}
////////////////////////////////////////////////////////
void calc_askN_sinewave(int amp01)
{
randomize();
ask.frequency = (2 * pi * c_hz)/ask_sr;
int namp=random(amp01);
for (int t = 0,n=0; t<ask_lcycle;t++,n++)
{
if(n==1){namp=amp01+random(8);n=0;}
ask.sine_value[t] = namp * (sin((ask.frequency*t)+ ask.phase));
}
}

//////////////////////////////////
void ask_main()
{
ask.x=32;
for (int i = 0;i<8;i++)
{
if (bd_4signal[i] == '0')
{
calc_ask_sinewave(ask.amp0);
create_ask_waves();
}
else
{
calc_ask_sinewave(ask.amp1);
create_ask_waves();
}
}
}
////////////////////////////////////////////////////
void askN_main()
{
ask.x=32;
for (int i = 0;i<8;i++)
{
if (bd_4signal[i] == '0')
{
calc_askN_sinewave(ask.amp0);
create_ask_waves();
}
else
{
calc_askN_sinewave(ask.amp1);
create_ask_waves();
}
}
}

////////////////////////////////////////////////////
void create_ask_waves()
{
int y=200,x1,y1;
setcolor(2);
setlinestyle(0,0,3);
for(int i=0;i<ask_lcycle;i++)
{
x1=ask.x+i;
if(ask.sine_value[i] >= 0)
y1=y-ask.sine_value[i];
else
y1=y+((-1)*ask.sine_value[i]);
line(x1,y1,x1,y1);
}
ask.x=x1;
}
///////////////////////////////////////////////////////
void create_graph_ask()
{
int csx1=30,csy1=100, csx2=620,csy2=300;
setcolor(15);
show_int_graph(ask.amp0,2,csx1-25,csy2-csy1-ask.amp0-5);
show_int_graph(((-1)*ask.amp0),3,csx1-30,csy2-csy1+ask.amp0-5);
setlinestyle(0,0,1);
line(csx1-4,csy2-csy1-ask.amp0,csx1+4,csy2-csy1-ask.amp0);
line(csx1-4,csy2-csy1+ask.amp0,csx1+4,csy2-csy1+ask.amp0);
show_int_graph(ask.amp1,2,csx1-25,csy2-csy1-ask.amp1-5);
show_int_graph(((-1)*ask.amp1),3,csx1-30,csy2-csy1+ask.amp1-5);
setlinestyle(0,0,1);
line(csx1-4,csy2-csy1-ask.amp1,csx1+4,csy2-csy1-ask.amp1);
line(csx1-4,csy2-csy1+ask.amp1,csx1+4,csy2-csy1+ask.amp1);
setcolor(4);
setlinestyle(0,0,3);
line(csx1,csy1,csx1,csy2);
line(csx1,csy2-csy1,csx2,csy2-csy1);
setcolor(9);
setlinestyle(1,1,1);
for(int i = csx1+ask_lcycle; i<csx2;i+=ask_lcycle-1)
line(i,csy1,i,csy2);
outtextxy(csx1,csy2+100,"Amplitude for 0 = ");
outtextxy(csx1,csy2+120,"Amplitude for 1 = ");
outtextxy(csx1,csy2+140,"Frequency = ");
outtextxy(csx1,csy2+160,"Phase = ");
setcolor(15);
show_int_graph(ask.amp0,2,csx1+160,csy2+100);
show_int_graph(ask.amp1,2,csx1+160,csy2+120);
show_int_graph(c_hz/10,2,csx1+160,csy2+140);
show_int_graph(c_angle,3,csx1+160,csy2+160);
settextstyle(1,0,4);
setcolor(15);
outtextxy(csx1,30,"Amplitude Shift Keying");
setfillstyle(1,9);
bar(csx1,70,csx1+370,72);
settextstyle(2,0,4);setcolor(15);
outtextxy(260,468,"Press any key to continue");
int a=54,b=csx1+166;
for(i=0;i<=7;i++)
{
setcolor(15);
graphicText(a,csy2-195,bd_4signal[i]);
setcolor(15);
graphicText(b,380,bd_4signal[i]);
a+=ask_lcycle;b+=7;
}
setcolor(9);
outtextxy(30,380,"Data = ");
//getch();
}
//////////////////////////////////////////////////////////////////
void fskDataBox()
{
setfillstyle(1,0);
bar(130,80,639,440);
setfillstyle(1,8);
bar(140-4,100-4,640+4,220+4);
setfillstyle(1,15);
bar(140,100,634,220);
setfillstyle(1,9);
bar(142,102,632,120);
setcolor(15);
settextstyle(2,0,4);
outtextxy(145,104,"Frequency Shift Keying (ASK) Information");
setfillstyle(1,9);
bar(142,146,320,164);
outtextxy(145,146,"Frequency for 0 bit");
setfillstyle(1,8);
bar(332,144,379,164);
setfillstyle(1,1);
bar(334,146,377,162);
setfillstyle(1,15);
int xabc=336,yabc=148,xxyz,yxyz=160;
for(int i=0;i<=1;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,166,320,184);
outtextxy(145,166,"Frequency for 1 bit");
setfillstyle(1,8);
bar(332,164,379,184);
setfillstyle(1,1);
bar(334,166,377,182);
setfillstyle(1,15);
xabc=336,yabc=168,xxyz,yxyz=180;
for(i=0;i<=1;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,1);
bar(500,184,550,204);
setfillstyle(1,9); //inner
bar(500+2,184+2,550-2,204-2);
setfillstyle(1,1);
bar(560,184,610,204);
setfillstyle(1,9); //inner
bar(560+2,184+2,610-2,204-2);
outtextxy(510,188,"Reset");
outtextxy(570,188,"Apply");
}
///////////////////////////////////////////////
int fskInputFun()
{
fsk.amp = c_amplitude;
fsk.phase = c_phase;
int x1=336,y1=128,x2=354,y2=140;
char ookCheck,t_afp[2];
/////////////////////////////////ook check
int i=0;
x1=336;x2=354;y1=148;y2=160;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 2)break;
x1=x2+2;
}while(1);
fsk.hz0 = atoi(t_afp);
///////////////////////////////////////////////////amp1
x1=336;x2=354;y1=168;y2=180;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 2)break;
x1=x2+2;
}while(1);
fsk.hz1=atoi(t_afp);
/////////////////////////////////////////////////
int choice=0; //0 done 1 reset
//x1=502;y1=186;x2=548;y2=200;
x1=562;y1=186;x2=608;y2=202;
setcolor(9);
setfillstyle(1,15); //inner
bar(x1,y1,x2,y2);
//outtextxy(510,188,"Reset");
outtextxy(570,188,"Apply");
while(1)
{
switch(getch())
{
case 77:
case 75:
{
if(choice==0)
{
x1=562;y1=186;x2=608;y2=202;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(570,188,"Apply")
;
choice=1;x1=502;y1=186;x2=548;y2=202;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(510,188,"Reset")
;
}
else if (choice==1)
{
x1=562;y1=186;x2=608;y2=202;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(570,188,"Apply")
;
choice=0;x1=502;y1=186;x2=548;y2=202;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(510,188,"Reset")
;
}
break;
}
case '
':
if(choice == 0)return(1); else return(0);
}
}
}
///////////////////////////////////////////////
void calc_fsk_sinewave(int hz01)
{
float frequency;
frequency = (2 * pi * hz01)/fsk_sr;
for (int t = 0; t<fsk_lcycle;t++)
fsk.sine_value[t] = fsk.amp * (sin((frequency*t)+ fsk.phase));
}
////////////////////////////////////////////////
void fsk_main()
{
fsk.x=32;
for (int i = 0;i<8;i++)
{
if (bd_4signal[i] == '0')
{
calc_fsk_sinewave(fsk.hz0*10);
create_fsk_waves();
}
else
{
calc_fsk_sinewave(fsk.hz1*10);
create_fsk_waves();
}
}
}
////////////////////////////////////////////////////
void create_fsk_waves()
{
int y=200,x1,y1;
setcolor(2);
setlinestyle(0,0,3);
for(int i=0;i<fsk_lcycle;i++)
{
x1=fsk.x+i;
if(fsk.sine_value[i] >= 0)
y1=y-fsk.sine_value[i];
else
y1=y+((-1)*fsk.sine_value[i]);
line(x1,y1,x1,y1);
}
fsk.x=x1;
}
///////////////////////////////////////////////////////
void create_graph_fsk()
{
int csx1=30,csy1=100, csx2=620,csy2=300;
setcolor(15);
show_int_graph(fsk.amp,2,csx1-25,csy2-csy1-fsk.amp-5);
show_int_graph(((-1)*fsk.amp),3,csx1-30,csy2-csy1+fsk.amp-5);
setlinestyle(0,0,1);
line(csx1-4,csy2-csy1-fsk.amp,csx1+4,csy2-csy1-fsk.amp);
line(csx1-4,csy2-csy1+fsk.amp,csx1+4,csy2-csy1+fsk.amp);
setcolor(4);
setlinestyle(0,0,3);
line(csx1,csy1,csx1,csy2);
line(csx1,csy2-csy1,csx2,csy2-csy1);
setcolor(9);
setlinestyle(1,1,1);
for(int i = csx1+fsk_lcycle; i<csx2;i+=fsk_lcycle-1)
line(i,csy1,i,csy2);
outtextxy(csx1,csy2+100,"Frequency for 0 = ");
outtextxy(csx1,csy2+120,"Frequency for 1 = ");
outtextxy(csx1,csy2+140,"Amplitude = ");
outtextxy(csx1,csy2+160,"Phase = ");
setcolor(15);
show_int_graph(fsk.hz0,2,csx1+160,csy2+100);
show_int_graph(fsk.hz1,2,csx1+160,csy2+120);
show_int_graph(fsk.amp,2,csx1+160,csy2+140);
show_int_graph(c_angle,3,csx1+160,csy2+160);
settextstyle(1,0,4);
setcolor(15);
outtextxy(csx1,30,"Frequency Shift Keying");
setfillstyle(1,9);
bar(csx1,70,csx1+370,72);
settextstyle(2,0,4);setcolor(15);
outtextxy(260,468,"Press any key to continue");
int a=54,b=csx1+166;
for(i=0;i<=7;i++)
{
setcolor(15);
graphicText(a,csy2-195,bd_4signal[i]);
setcolor(15);
graphicText(b,380,bd_4signal[i]);
a+=ask_lcycle;b+=7;
}
setcolor(9);
outtextxy(30,380,"Data = ");
//getch();
}
//////////////////////////////////////////////
void pskDataBox()
{
setfillstyle(1,0);
bar(130,80,639,440);
setfillstyle(1,8);
bar(140-4,100-4,640+4,220+4);
setfillstyle(1,15);
bar(140,100,634,220);
setfillstyle(1,9);
bar(142,102,632,120);
setcolor(15);
settextstyle(2,0,4);
outtextxy(145,104,"Phase Shift Keying (ASK) Information");
setfillstyle(1,9);
bar(142,146,320,164);
outtextxy(145,146,"Phase for 0 bit");
setfillstyle(1,8);
bar(332,144,399,164);
setfillstyle(1,1);
bar(334,146,397,162);
setfillstyle(1,15);
int xabc=336,yabc=148,xxyz,yxyz=160;
for(int i=0;i<=2;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,166,320,184);
outtextxy(145,166,"Phase for 1 bit");
setfillstyle(1,8);
bar(332,164,399,184);
setfillstyle(1,1);
bar(334,166,397,182);
setfillstyle(1,15);
xabc=336,yabc=168,xxyz,yxyz=180;
for(i=0;i<=2;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,1);
bar(500,184,550,204);
setfillstyle(1,9); //inner
bar(500+2,184+2,550-2,204-2);
setfillstyle(1,1);
bar(560,184,610,204);
setfillstyle(1,9); //inner
bar(560+2,184+2,610-2,204-2);
outtextxy(510,188,"Reset");
outtextxy(570,188,"Apply");
}
///////////////////////////////////////////////
int pskInputFun()
{
psk.amp = c_amplitude;
psk.frequency = c_frequency;
int x1=336,y1=128,x2=354,y2=140;
char ookCheck,t_afp[3];
int i=0;
x1=336;x2=354;y1=148;y2=160;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 3)break;
x1=x2+2;
}while(1);
psk.ang0 = atoi(t_afp);
psk.phase0 = psk.ang0*(2*pi/360);
///////////////////////////////////////////////////amp1
x1=336;x2=354;y1=168;y2=180;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 3)break;
x1=x2+2;
}while(1);
psk.ang1=atoi(t_afp);
psk.phase1 = psk.ang1*(2*pi/360);
/////////////////////////////////////////////////
int choice=0; //0 done 1 reset
//x1=502;y1=186;x2=548;y2=200;
x1=562;y1=186;x2=608;y2=202;
setcolor(9);
setfillstyle(1,15); //inner
bar(x1,y1,x2,y2);
//outtextxy(510,188,"Reset");
outtextxy(570,188,"Apply");
while(1)
{
switch(getch())
{
case 77:
case 75:
{
if(choice==0)
{
x1=562;y1=186;x2=608;y2=202;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(570,188,"Apply")
;
choice=1;x1=502;y1=186;x2=548;y2=202;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(510,188,"Reset")
;
}
else if (choice==1)
{
x1=562;y1=186;x2=608;y2=202;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(570,188,"Apply")
;
choice=0;x1=502;y1=186;x2=548;y2=202;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(510,188,"Reset")
;
}
break;
}
case '
':
if(choice == 0)return(1); else return(0);
}
}
}
///////////////////////////////////////////////
void calc_psk_sinewave(int ph01)
{
float frequency;
frequency = (2 * pi * c_hz)/psk_sr;
for (int t = 0; t<psk_lcycle;t++)
psk.sine_value[t] = psk.amp * (sin((frequency*t)+ ph01));
}
////////////////////////////////////////////////
void psk_main()
{
psk.x=32;
for (int i = 0;i<8;i++)
{
if (bd_4signal[i] == '0')
{
calc_psk_sinewave(psk.phase0);
create_psk_waves();
}
else
{
calc_psk_sinewave(psk.phase1);
create_psk_waves();
}
}
}
////////////////////////////////////////////////////
void create_psk_waves()
{
int y=200,x1,y1;
setcolor(2);
setlinestyle(0,0,3);
for(int i=0;i<psk_lcycle;i++)
{
x1=psk.x+i;
if(psk.sine_value[i] >= 0)
y1=y-psk.sine_value[i];
else
y1=y+((-1)*psk.sine_value[i]);
line(x1,y1,x1,y1);
}
psk.x=x1;
}
///////////////////////////////////////////////////////
void create_graph_psk()
{
int csx1=30,csy1=100, csx2=620,csy2=300;
setcolor(15);
show_int_graph(psk.amp,2,csx1-25,csy2-csy1-psk.amp-5);
show_int_graph(((-1)*psk.amp),3,csx1-30,csy2-csy1+psk.amp-5);
setlinestyle(0,0,1);
line(csx1-4,csy2-csy1-psk.amp,csx1+4,csy2-csy1-psk.amp);
line(csx1-4,csy2-csy1+psk.amp,csx1+4,csy2-csy1+psk.amp);
setcolor(4);
setlinestyle(0,0,3);
line(csx1,csy1,csx1,csy2);
line(csx1,csy2-csy1,csx2,csy2-csy1);
setcolor(9);
setlinestyle(1,1,1);
for(int i = csx1+psk_lcycle; i<csx2;i+=psk_lcycle-1)
line(i,csy1,i,csy2);
outtextxy(csx1,csy2+100,"Phase for 0 = ");
outtextxy(csx1,csy2+120,"Phase for 1 = ");
outtextxy(csx1,csy2+140,"Amplitude = ");
outtextxy(csx1,csy2+160,"Frequency = ");
setcolor(15);
show_int_graph(psk.ang0,3,csx1+160,csy2+100);
show_int_graph(psk.ang1,3,csx1+160,csy2+120);
show_int_graph(psk.amp,2,csx1+160,csy2+140);
show_int_graph(psk.frequency,2,csx1+160,csy2+160);
settextstyle(1,0,4);
setcolor(15);
outtextxy(csx1,30,"Phase Shift Keying");
setfillstyle(1,9);
bar(csx1,70,csx1+370,72);
settextstyle(2,0,4);setcolor(15);
outtextxy(260,468,"Press any key to continue");
int a=54,b=csx1+166;
for(i=0;i<=7;i++)
{
setcolor(15);
graphicText(a,csy2-195,bd_4signal[i]);
setcolor(15);
graphicText(b,380,bd_4signal[i]);
a+=ask_lcycle;b+=7;
}
setcolor(9);
outtextxy(30,380,"Data = ");
//getch();
}
//////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
void carrierDataBox_4qam()
{
setfillstyle(1,0);
bar(130,80,639,440);
setfillstyle(1,8);
bar(140-4,100-4,640+4,270+4);
setfillstyle(1,15);
bar(140,100,634,270);
setfillstyle(1,9);
bar(142,102,632,120);
settextstyle(2,0,4);
outtextxy(145,104,"Enter 24 bits (3 bytes)");
setfillstyle(1,8);
bar(142,130,560,162);
setfillstyle(1,1);
bar(144,132,558,160);
setfillstyle(1,15);
int xabc=150,yabc=134,xxyz,yxyz=158;
for(int i=0;i<=23;i++)
{
xxyz=xabc+15;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,180,632,198);
outtextxy(145,182,"Carrier Signal Information");
bar(142,204,220,222);
outtextxy(145,206,"Amplitude");
setfillstyle(1,8);
bar(225,204,272,222);
setfillstyle(1,1);
bar(227,206,270,220);
setfillstyle(1,15);
xabc=230,yabc=208,xxyz,yxyz=218;
for(i=0;i<=1;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,224,220,242);
outtextxy(145,226,"Frequency");
setfillstyle(1,8);
bar(225,224,272,242);
setfillstyle(1,1);
bar(227,226,270,240);
setfillstyle(1,15);
xabc=230,yabc=228,xxyz,yxyz=238;
for(i=0;i<=1;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,244,220,262);
outtextxy(145,246,"Phase");
setfillstyle(1,8);
bar(225,244,292,262);
setfillstyle(1,1);
bar(227,246,290,260);
setfillstyle(1,15);
xabc=230,yabc=248,xxyz,yxyz=258;
for(i=0;i<=2;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,1);
bar(500,244,550,262);
setfillstyle(1,9); //inner
bar(500+2,244+2,550-2,262-2);
setfillstyle(1,1);
bar(560,244,610,262);
setfillstyle(1,9); //inner
bar(560+2,244+2,610-2,262-2);
outtextxy(510,247,"Reset");
outtextxy(570,247,"Apply");
}
////////////////////////////////////////////////
int carrierInputFun_4qam()
{
/////////////////////////////////digit
int x1=150,x2=150,y1=134,y2=158;
int i=0;
do{
i+=1;
x2=x1+(15);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
bd_4qam[i-1] = getche();
if(bd_4qam[i-1] != '0' && bd_4qam[i-1] != '1')
{i-=1;x2-=20;}
graphicText(x1+4,y1+6,bd_4qam[i-1]);
if(i == 24)break;
x1=x2+2;
}while(1);
bd_4qam[24]='/0';
/////////////////////////////////amplitude
x1=230,x2=230,y1=208,y2=218;
char t_afp[2];
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+4,y1,t_afp[i-1]);
if(i == 2)break;
x1=x2+2;
}while(1);
c_amplitude = atoi(t_afp);
//////////////////////////////////////////frequency
x1=230,x2=230,y1=228,y2=238;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+4,y1,t_afp[i-1]);
if(i == 2)break;
x1=x2+2;
}while(1);
c_hz = atoi(t_afp);
//////////////////////////////////////////phase
x1=230,x2=230,y1=248,y2=258;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+4,y1,t_afp[i-1]);
if(i == 3)break;
x1=x2+2;
}while(1);
c_angle = atoi(t_afp);
/////////////////////////////////////////////////
c_hz*=10;
c_phase = c_angle*(2*pi/360);
/////////////////////////////////////////////////button
int choice=0; //0 done 1 reset
//x1=502;y1=246;x2=548;y2=260;
x1=562;y1=246;x2=608;y2=260;
setcolor(9);
setfillstyle(1,15); //inner
bar(x1,y1,x2,y2);
//outtextxy(510,247,"Reset");
outtextxy(570,247,"Apply");
while(1)
{
switch(getch())
{
case 77:
case 75:
{
if(choice==0)
{
x1=562;y1=246;x2=608;y2=260;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(570,247,"Apply")
;
choice=1;x1=502;y1=246;x2=548;y2=260;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(510,247,"Reset")
;
}
else if (choice==1)
{
x1=562;y1=246;x2=608;y2=260;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(570,247,"Apply")
;
choice=0;x1=502;y1=246;x2=548;y2=260;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(510,247,"Reset")
;
}
break;
}
case '
':
if(choice == 0)return(1); else return(0);
}
}
}
///////////////////////////////////////////////
void qamDataBox()
{
setfillstyle(1,0);
bar(130,80,639,440);
setfillstyle(1,8);
bar(140-4,100-4,640+4,246+4);
setfillstyle(1,15);
bar(140,100,634,246);
setfillstyle(1,9);
bar(142,102,632,120);
setcolor(15);
settextstyle(2,0,4);
outtextxy(145,104,"Quadrature Amplitude Modulation (QAM)");
bar(142,124,320,142);
outtextxy(145,126,"First Amplitude");
setfillstyle(1,8);
bar(332,124,379,144);
setfillstyle(1,1);
bar(334,126,377,142);
setfillstyle(1,15);
int xabc=336,yabc=128,xxyz,yxyz=140;
for(int i=0;i<=1;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,146,320,164);
outtextxy(145,146,"Second Amplitude");
setfillstyle(1,8);
bar(332,144,379,164);
setfillstyle(1,1);
bar(334,146,377,162);
setfillstyle(1,15);
xabc=336,yabc=148,xxyz,yxyz=160;
for(i=0;i<=1;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,166,320,184);
outtextxy(145,166,"First Phase");
setfillstyle(1,8);
bar(332,164,399,184);
setfillstyle(1,1);
bar(334,166,397,182);
setfillstyle(1,15);
xabc=336,yabc=168,xxyz,yxyz=180;
for(i=0;i<=2;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,186,320,204);
outtextxy(145,188,"Second Phase");
setfillstyle(1,8);
bar(332,184,399,202);
setfillstyle(1,1);
bar(334,186,397,200);
setfillstyle(1,15);
xabc=336,yabc=188,xxyz,yxyz=198;
for(i=0;i<=2;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,206,320,224);
outtextxy(145,208,"Third Phase");
setfillstyle(1,8);
bar(332,203,399,222);
setfillstyle(1,1);
bar(334,206,397,220);
setfillstyle(1,15);
xabc=336,yabc=208,xxyz,yxyz=218;
for(i=0;i<=2;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,9);
bar(142,226,320,244);
outtextxy(145,228,"Fourth Phase");
setfillstyle(1,8);
bar(332,223,399,242);
setfillstyle(1,1);
bar(334,226,397,240);
setfillstyle(1,15);
xabc=336,yabc=228,xxyz,yxyz=238;
for(i=0;i<=2;i++)
{
xxyz=xabc+18;
bar(xabc,yabc,xxyz,yxyz);
xabc=xxyz+2;
}
setfillstyle(1,1);
bar(500,224,550,244);
setfillstyle(1,9); //inner
bar(500+2,224+2,550-2,244-2);
setfillstyle(1,1);
bar(560,224,610,244);
setfillstyle(1,9); //inner
bar(560+2,224+2,610-2,244-2);
outtextxy(510,228,"Reset");
outtextxy(570,228,"Apply");
}
///////////////////////////////////////////////
int qamInputFun()
{
qam.frequency = c_frequency;
char t_afp[3];
int i=0;
i=0;
/////////////////////////////////////////////amp1
int x1=336,y1=128,x2=354,y2=140;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 2)break;
x1=x2+2;
}while(1);
qam.amp1 = atoi(t_afp);
///////////////////////////////////////////////////amp2
x1=336;x2=354;y1=148;y2=160;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 2)break;
x1=x2+2;
}while(1);
qam.amp2=atoi(t_afp);
/////////////////////////////////////////////////phase1
x1=336;x2=354;y1=168;y2=180;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 3)break;
x1=x2+2;
}while(1);
qam.ang1=atoi(t_afp);
qam.phase1 = qam.ang1*(2*pi/360);
/////////////////////////////////////////////////phase2
x1=336;x2=354;y1=188;y2=198;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 3)break;
x1=x2+2;
}while(1);
qam.ang2=atoi(t_afp);
qam.phase2 = qam.ang2*(2*pi/360);
/////////////////////////////////////////////////phase3
x1=336;x2=354;y1=208;y2=218;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 3)break;
x1=x2+2;
}while(1);
qam.ang3=atoi(t_afp);
qam.phase3 = qam.ang3*(2*pi/360);
/////////////////////////////////////////////////phase4
x1=336;x2=354;y1=228;y2=238;
i=0;
do{
i+=1;
x2=x1+(18);
setfillstyle(1,9);
bar(x1,y1,x2,y2);
t_afp[i-1] = getche();
if(t_afp[i-1] < '0' || t_afp[i-1] > '9')
{i-=1;x2-=20;}
graphicText(x1+6,y1,t_afp[i-1]);
if(i == 3)break;
x1=x2+2;
}while(1);
qam.ang4=atoi(t_afp);
qam.phase4 = qam.ang4*(2*pi/360);
/////////////////////////////////////////////////
int choice=0; //0 done 1 reset
//x1=502;y1=186;x2=548;y2=200;
x1=562;y1=226;x2=608;y2=242;
setcolor(9);
setfillstyle(1,15); //inner
bar(x1,y1,x2,y2);
//outtextxy(510,188,"Reset");
outtextxy(570,226,"Apply");
while(1)
{
switch(getch())
{
case 77:
case 75:
{
if(choice==0)
{
x1=562;y1=226;x2=608;y2=242;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(570,226,"Apply")
;
choice=1;x1=502;y1=226;x2=548;y2=242;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(510,226,"Reset")
;
}
else if (choice==1)
{
x1=562;y1=226;x2=608;y2=242;
setcolor(9);setfillstyle(1,15);bar(x1,y1,x2,y2);outtextxy(570,226,"Apply")
;
choice=0;x1=502;y1=226;x2=548;y2=242;
setcolor(15);setfillstyle(1,9);bar(x1,y1,x2,y2);outtextxy(510,226,"Reset")
;
}
break;
}
case '
':
if(choice == 0)return(1); else return(0);
}
}
}
///////////////////////////////////////////////
void showDtable()
{
setfillstyle(1,8);
bar(140-4,280-4,640,410+4);
setfillstyle(1,15);
bar(140,280,634,410);
setfillstyle(1,9);
bar(142,282,632,302);
setfillstyle(1,9);
bar(142,306,632,408);
setfillstyle(1,1);
bar(142,306,632,326);
setcolor(15);
settextstyle(2,0,4);
outtextxy(330,286,"8-QAM Data Table");
setfillstyle(1,1);
bar(142,306,242,408);
setfillstyle(1,15);
bar(242,306,244,410);
bar(142,326,632,328);
bar(142,346,632,348);
bar(142,366,632,368);
bar(142,386,632,388);
bar(420,306,422,410);
setcolor(15);
setlinestyle(0,0,2);
line(142,306,244,326);
setcolor(15);
settextstyle(2,0,4);
outtextxy(189,305,"Amplitude");
outtextxy(149,314,"Phase");
setcolor(15);
show_int_graph(qam.ang1,3,170,332);
show_int_graph(qam.ang2,3,170,352);
show_int_graph(qam.ang3,3,170,372);
show_int_graph(qam.ang4,3,170,392);
show_int_graph(qam.amp1,2,320,311);
show_int_graph(qam.amp2,3,510,311);
setcolor(1);
outtextxy(320,332,"000");
outtextxy(512,332,"001");
outtextxy(320,352,"010");
outtextxy(512,352,"011");
outtextxy(320,372,"100");
outtextxy(512,372,"101");
outtextxy(320,392,"110");
outtextxy(512,392,"111");
setfillstyle(1,8);
bar(560,415,620,435);
setfillstyle(1,15); //inner
bar(560+1,415+1,620-1,435-1);
setfillstyle(1,9); //inner
bar(560+2,415+2,620-2,435-2);
setcolor(15);
outtextxy(568,420,"Continue");
}
//////////////////////////////////////////////////////////////////////////
//
void creategraph_Dqam()
{
y12=yvalue2-20,x12=20,y22=yvalue2;
int cgx1=20,cgy1=140, cgx2=500,cgy2=yvalue2;
setcolor(4);
setlinestyle(0,1,3);
line(cgx1,cgy1,cgx1,cgy2);
line(cgx1,cgy2,cgx2,cgy2);
setcolor(14);
setlinestyle(1,1,1);
for(int i = cgx1+20; i<cgx2;i+=20)
line(i,cgy1,i,cgy2);
settextstyle(1,0,4);
setcolor(15);
outtextxy(x12,30,"DIGITAL SIGNAL");
setfillstyle(1,9);
bar(x12,70,x12+250,72);
settextstyle(2,0,4);setcolor(15);
outtextxy(260,460,"Press any key to continue");
int a=30,b=100;
for(i=0;i<=23;i++)
{
setcolor(15);
graphicText(a,y22-100,bd_4qam[i]);
setcolor(15);
graphicText(b,400,bd_4qam[i]);
a+=20;b+=7;
}
setcolor(9);
outtextxy(40,400,"Data = ");
//getch();
}
/////////////////////////////////////////////////////
void createDsignal_Dqam()
{
setcolor(2);
int len=25;
for (int i=0;i<len-1;i++)
{
if(bd_4qam[i] == '0')
{
dsignal4_0_Dqam(i+1);
}
else
{
dsignal4_1_Dqam(i+1);
}
}
}
//////////////////////////////////////////////////////
void dsignal4_0_Dqam(int pos)
{
setcolor(2);
setlinestyle(0,1,lineweight);
int x=x12;x12+=20;
if (pos == 1 || (pos != 1 && bd_4qam[pos-2] == '0'))
line(x,y22,x+20,y22);
else
{
line(x,y12,x,y22);
line(x,y22,x+20,y22);
}
}
///////////////////////////////////////////////////////
void dsignal4_1_Dqam(int pos)
{
setcolor(2);
setlinestyle(0,1,lineweight);
int x=x12;x12+=20;
if (pos == 1 || (pos != 1 && bd_4qam[pos-2] == '1'))
line(x,y12,x+20,y12);
else
{
line(x,y12,x,y22);
line(x,y12,x+20,y12);
}
}
///////////////////////////////////////////////////////
///////////////////////////////////////////////
void calc_qam_sinewave(int phase,int amp)
{
float frequency;
frequency = (2 * pi * c_hz)/qam_sr;
for (int t = 0; t<qam_lcycle;t++)
qam.sine_value[t] = amp * (sin((frequency*t)+ phase));
}
////////////////////////////////////////////////
void qam_main()
{
qam.x=32;
for (int i = 0;i<25;i+=3)
{
if (bd_4qam[i] == '0' && bd_4qam[i+1] == '0' && bd_4qam[i+2] == '0')
{
calc_qam_sinewave(qam.phase1,qam.amp1);
create_qam_waves();
}
else if (bd_4qam[i] == '0' && bd_4qam[i+1] == '0' && bd_4qam[i+2] ==
'1')
{
calc_qam_sinewave(qam.phase1,qam.amp2);
create_qam_waves();
}
else if (bd_4qam[i] == '0' && bd_4qam[i+1] == '1' && bd_4qam[i+2] ==
'0')
{
calc_qam_sinewave(qam.phase2,qam.amp1);
create_qam_waves();
}
else if (bd_4qam[i] == '0' && bd_4qam[i+1] == '1' && bd_4qam[i+2] ==
'1')
{
calc_qam_sinewave(qam.phase2,qam.amp2);
create_qam_waves();
}
else if (bd_4qam[i] == '1' && bd_4qam[i+1] == '0' && bd_4qam[i+2] ==
'0')
{
calc_qam_sinewave(qam.phase3,qam.amp1);
create_qam_waves();
}
else if (bd_4qam[i] == '1' && bd_4qam[i+1] == '0' && bd_4qam[i+2] ==
'1')
{
calc_qam_sinewave(qam.phase3,qam.amp2);
create_qam_waves();
}
else if (bd_4qam[i] == '1' && bd_4qam[i+1] == '1' && bd_4qam[i+2] ==
'0')
{
calc_qam_sinewave(qam.phase4,qam.amp1);
create_qam_waves();
}
else if (bd_4qam[i] == '1' && bd_4qam[i+1] == '1' && bd_4qam[i+2] ==
'1')
{
calc_qam_sinewave(qam.phase4,qam.amp2);
create_qam_waves();
}
}
}
////////////////////////////////////////////////////
void create_qam_waves()
{
int y=200,x1,y1;
setcolor(2);
setlinestyle(0,0,3);
for(int i=0;i<fsk_lcycle;i++)
{
x1=qam.x+i;
if(qam.sine_value[i] >= 0)
y1=y-qam.sine_value[i];
else
y1=y+((-1)*qam.sine_value[i]);
line(x1,y1,x1,y1);
}
qam.x=x1;
}
///////////////////////////////////////////////////////
void create_graph_qam()
{
int csx1=30,csy1=100, csx2=620,csy2=300;
setcolor(15);
show_int_graph(qam.amp1,2,csx1-25,csy2-csy1-qam.amp1-5);
show_int_graph(((-1)*qam.amp1),3,csx1-30,csy2-csy1+qam.amp1-5);
show_int_graph(qam.amp2,2,csx1-25,csy2-csy1-qam.amp2-5);
show_int_graph(((-1)*qam.amp2),3,csx1-30,csy2-csy1+qam.amp2-5);
setlinestyle(0,0,1);
line(csx1-4,csy2-csy1-qam.amp1,csx1+4,csy2-csy1-qam.amp1);
line(csx1-4,csy2-csy1+qam.amp1,csx1+4,csy2-csy1+qam.amp1);
line(csx1-4,csy2-csy1-qam.amp2,csx1+4,csy2-csy1-qam.amp2);
line(csx1-4,csy2-csy1+qam.amp2,csx1+4,csy2-csy1+qam.amp2);
setcolor(4);
setlinestyle(0,0,3);
line(csx1,csy1,csx1,csy2);
line(csx1,csy2-csy1,csx2,csy2-csy1);
setcolor(9);
setlinestyle(1,1,1);
for(int i = csx1+qam_lcycle; i<csx2;i+=qam_lcycle-1)
line(i,csy1,i,csy2);
settextstyle(2,0,4);
outtextxy(csx1+360,csy2+10,"Frequency for 0 = ");
setcolor(15);
show_int_graph(c_hz,2,csx1+480,csy2+10);
settextstyle(1,0,4);
setcolor(15);
outtextxy(csx1,30,"QAM");
setfillstyle(1,9);
bar(csx1,70,csx1+370,72);
settextstyle(2,0,4);setcolor(15);
outtextxy(260,468,"Press any key to continue");
int a=54,b=csx1+166;
for(i=0;i<=25;i+=3)
{
setcolor(15);
graphicText(a,csy2-195,bd_4qam[i]);
graphicText(a+7,csy2-195,bd_4qam[i+1]);
graphicText(a+7+7,csy2-195,bd_4qam[i+2]);
setcolor(15);
graphicText(b,310,bd_4qam[i]);
b+=7;
graphicText(b,310,bd_4qam[i+1]);
b+=7;
graphicText(b,310,bd_4qam[i+2]);
a+=ask_lcycle;b+=7;
}
setcolor(9);
outtextxy(40,310,"Data = ");
//getch();
}
//////////////////////////////////////////////
void showDtable2()
{
setfillstyle(1,8);
bar(140-4-100,280-4+50,640-100,410+4+50);
setfillstyle(1,15);
bar(140-100,280+50,634-100,410+50);
setfillstyle(1,9);
bar(142-100,282+50,632-100,302+50);
setfillstyle(1,9);
bar(142-100,306+50,632-100,408+50);
setfillstyle(1,1);
bar(142-100,306+50,632-100,326+50);
setcolor(15);
settextstyle(2,0,4);
outtextxy(330-100,286+50,"8-QAM Data Table");
setfillstyle(1,1);
bar(142-100,306+50,242-100,408+50);
setfillstyle(1,15);
bar(242-100,306+50,244-100,410+50);
bar(142-100,326+50,632-100,328+50);
bar(142-100,346+50,632-100,348+50);
bar(142-100,366+50,632-100,368+50);
bar(142-100,386+50,632-100,388+50);
bar(420-100,306+50,422-100,410+50);
setcolor(15);
setlinestyle(0,0,2);
line(142-100,306+50,244-100,326+50);
setcolor(15);
settextstyle(2,0,4);
outtextxy(189-100,305+50,"Amplitude");
outtextxy(149-100,314+50,"Phase");
setcolor(15);
show_int_graph(qam.ang1,3,170-100,332+50);
show_int_graph(qam.ang2,3,170-100,352+50);
show_int_graph(qam.ang3,3,170-100,372+50);
show_int_graph(qam.ang4,3,170-100,392+50);
show_int_graph(qam.amp1,2,320-100,311+50);
show_int_graph(qam.amp2,3,510-100,311+50);
setcolor(1);
outtextxy(320-100,332+50,"000");
outtextxy(512-100,332+50,"001");
outtextxy(320-100,352+50,"010");
outtextxy(512-100,352+50,"011");
outtextxy(320-100,372+50,"100");
outtextxy(512-100,372+50,"101");
outtextxy(320-100,392+50,"110");
outtextxy(512-100,392+50,"111");
}

RSA Algorithm (Mini Project)


Description : It encrypts not only the numbers, also the text message you will give.
Code :

//Header File--RSA Application


//Miller & Rabin Algorithm--Test for Primality
//PseudoRandom Number Generator Algorithm
//Relatively Prime--Euclid's Algorithm

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<math.h>
#include<process.h>

class RSA
{
public:
int pr1,pr2,x1,n,n1;
int e,d,pt;
int a[20],b[10];
int len; //binary array length

RSA();

//Miller & Rabin Algorithm--Test for Primality


void testprimality();

//PseudoRandom Number Generator Algorithm


void pseudo1();
int pseudo2();

//Relatively Prime--Euclid's Algorithm


//GCD of two numbers-their common factor is '1'
void relprime();
int gcd(int c,int d);

//Key Generation
int keygenerate1(int ptext);//for Encryption
int keygenerate2(int ctext);//for Decryption
void decitobin(int x);

//Encryption
int encrypt(int num);

//Decryption
int decrypt(int ctext);

};

//Interface File--RSA Application


//Miller & Rabin Algorithm--Test for Primality
//PseudoRandom Number Generator Algorithm
//Relatively Prime--Euclid's Algorithm
#include"rh1.h"

RSA::RSA()
{
x1=1;
pr1=0;
pr2=0;
}

//Miller & Rabin Algorithm--Test for Primality

void RSA::testprimality()
{
int a,j,p1,q,x;
int t1,t2;

int k,flag,ch;

ch=1;
flag=0;
k=0;

//(n-1)=pow(2,k)*q
//divide (n-1) by 2 until result is odd number

while(ch)
{
x=(n-1)/(int)(pow(2,k));
if(fmod(x,2)==1)
{
ch=0;
break;
}

k++;
}

q=(int)((n-1)/(pow(2,k)));

//to pick an integer randomly which


//should be less than 'n';
//That's why calling pseudo2()
a=pseudo2();

if(a>1 && a<(n-1))


{
t1=(int)(pow(a,q));

if((t1%n)==1)
flag=1;
else
{

for(j=0;j<=(k-1);j++)
{
p1=((int)(pow(2,j)))*q;
t2=(int)pow(a,p1);

if((t2%n)==(n-1))
flag=1;

}
}
}

if(flag==1)
if(pr1==0)
pr1=n;
else if(pr1!=0 && pr2==0)
pr2=n;

//PseudoRandom Number Generator Algorithm

void RSA::pseudo1()
{
//to select 'n' pseudorandomly and pass to testprimality();
//'n' is to be proved either prime or not prime

int a,c,y;
unsigned int m;

y=0;

a=(int)pow(7,5); //(7,2),*(7,4),(7,5)
//(int)pow(7,5) used in IBM 360

//m should be assigned a "prime" no.


//up to pow(2,31) should be used.
//(2,5)-1;(2,7)-1;(2,13)-1;
//(2,17)-1;(2,19)-1;(2,31)-1 are primes

m=((int)pow(2,7))-1; //(2,7)

n=1;c=0;

for(int i=0;i<50;i++)
{
n=((a*n)+c)%m;
testprimality();
//n will be computed in textprimality()
}

// cout<<"
pr1 = "<<pr1;
// cout<<"
pr2 = "<<pr2;
}

int RSA::pseudo2()
{
//to pick an integer randomly which
//should be less than 'n'

int a,ret;
unsigned int m;

a=(int)pow(7,4); //(7,3),*(7,4) for a's (7,5)in pseudo1


m=(int)pow(2,5)-1; //(2,5)

ret=(a*x1)%m;
x1=ret;
return ret;

//Relatively Prime--Euclid's Algorithm


//GCD of two numbers-their common factor is '1'
void RSA::relprime()
{

//Finding 'e' & 'd' value


int fin,ret,ret1,ret2,ch,ex,dx;

ch=1;ex=2;dx=1;
n1=pr1*pr2;

fin=(pr1-1)*(pr2-1);

//Finding 'e' alone


x1=1; //for pseudo2

while(ch)
{
ex=pseudo2();
if(ex>1 && ex<fin)
{
ret1=gcd(ex,fin);
ret2=gcd(fin,(ex%fin));
if(ret1==1 && ret2==1)
{
e=ex;
ch=0;
break;
}
}

// cout<<"
Relative Prime : e value: "<<e;

//Finding 'd' alone


//de=(1 mod fin) where fin=(pr1-1)*(pr2-1);
ch=1;
while(ch)
{
ret=(e*dx)%fin;
if(ret==1)
{
d=dx;
ch=0;
break;
}
dx=dx+1;

// cout<<"
d value : "<<d;
}

int RSA::gcd(int c,int d)


{
int r;

r=d%c;

while(r!=0)
{
d=c;
c=r;
r=d%c;
}

return c;
}

int RSA::keygenerate1(int ptext)


{
//Encryption
int i,c;
int entext;

c=0;entext=1;

decitobin(e); //public key with 'e'


//b[]->array contains binary value of 'e'

for(i=len;i>=0;i--)
{
c=2*c;
entext=(entext*entext)%n1; //187->n1
if(a[i]==1)
{
c=c+1;
entext=(entext*ptext)%n1; //187->n1
}
}

// cout<<"
Encrypted 'c' : "<<c;
return entext;
}

int RSA::keygenerate2(int ctext)


{

//Decryption
int i,dntext,c;
dntext=1;
c=0;

decitobin(d); //Private Key with 'd'


//b[]->array contains binary value of 'd'

for(i=len;i>=0;i--)
{
c=2*c;
dntext=(dntext*dntext)%n1;

if(a[i]==1)
{
c=c+1;
dntext=(dntext*ctext)%n1;
}

// cout<<"
Decrypted 'c' := "<<c;

return dntext;
}

void RSA::decitobin(int x)
{
int k,i=0;

while(x>0)
{
a[i]=x%2;
i++;
x=x/2;
}

//when exit from above loop, i value is incremented by 1


k=i-1;

len=i-1;
}

int RSA::encrypt(int num)


{
int ctext,i;

pt=num;
ctext=keygenerate1(num);

return(ctext);
}

int RSA::decrypt(int ctext)


{
int dectext,i;

dectext=keygenerate2(ctext);

return(dectext);

//Application File--RSA Application


//Miller & Rabin Algorithm--Test for Primality
//PseudoRandom Number Generator Algorithm
//Relatively Prime--Euclid's Algorithm

#include"rh1.h"
#include<stdio.h>

void main()
{
int i,det,det1,len,k,k1,cnt;
int con=0,c;
char ch[100],cipher[20],orig[20];

RSA r;
c=1;

cout<<endl<<endl;
for(i=0;i<70;i++)
cout<<'*';
cout<<"
RSA APPLICATION<BR>;
for(i=0;i<70;i++)
cout<<'*';
cout<<endl;

r.pseudo1();
r.relprime();

cout<<"

Enter the String : ";


cnt=0;
char chr;

scanf ( "%[^
]s", ch ) ;

len=strlen(ch);
k=0;k1=0;

for(i=0;i<len;i++)
{
con=(int)ch[i];
det=r.encrypt(con);
cipher[k]=char(det);
k++;
det1=r.decrypt(det);
orig[k1]=char(det1);
k1++;
}

cipher[k]='
The Distance Transforn of a Binary Image

Description : This is a image processing program which performs the distance transform of a binary
image.Distance transform is widely used for image thinning and finding skeleton of an image.
//1:newfndistrans.java
//2:A bmp monochrome image(preferably 512-512)
//make the image from mspaint or any other source

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class newfndistrans extends JFrame{
frame frm=null;
File f;
FileInputStream ff;
Color cl;
int count;
int a[];

int rnum,gnum;
int xsize;
int ysize;
final int sample=5;
String str=null;

newfndistrans(String str)
{
super(str);
frm=new frame();

count=0;
a=new int[8];
rnum=0;gnum=0;
}

public void paint(Graphics g)


{
int x,y,i=0,j=0,temp;

try{

System.out.println("Starting");
System.out.println("filename="+frm.getfilename());
try{f=frm.getfilename();
ff=new FileInputStream(f);
}catch(Exception e){
System.out.println("error in reading file");
}
ff.skip(18);
i=ff.read();
i=((ff.read()<<8)|i);
i=((ff.read()<<16)|i);
i=((ff.read()<<24)|i);
xsize=i;
System.out.println("width="+xsize);
i=0;
i=ff.read();
i=((ff.read()<<8)|i);
i=((ff.read()<<16)|i);
i=((ff.read()<<24)|i);
ysize=i;
System.out.println("Height="+ysize);

ff.skip(38);//62-(2+16+4+4=26)=36, actually total=62 Bytes header


//note:make it 38 for nrectbit1.bmp and nrectbit2.bmp
x=0;y=ysize;
int pix[][],mat1[][];
pix=new int[xsize][ysize];
mat1=new int[xsize][ysize];
System.out.println("here");
while(true)
{

rnum=ff.read();
//System.out.println("rnum="+rnum);
if(rnum==-1)break;
count=7;
//image has 0 for black ,1 for white,but my convention is opposite
while(rnum>0)
{
gnum=rnum%2;
if(gnum==0)a[count]=1;
else a[count]=0;
count--;
rnum=rnum/2;
}
while(count>=0)
{a[count]=1;count--;
}
for(i=0;i<=7;i++)
{if(a[i]==0)cl=new Color(255,255,255);
else cl=new Color(0,0,0);
pix[x][y-1]=a[i];
mat1[x][y-1]=a[i];
g.setColor(cl);
g.drawRect(x,y,1,1);
x++;
if(x==xsize){x=0;y--;}
}
}//end while

System.out.println("File read successfully");


//sleep for 4 seconds(4000 msec)
try{Thread.sleep(4000);
}catch(Exception e){}
//clear the region where the image was drawn,area near the boundaries
are
also cleaned
for(j=0;j<=ysize+2;j++)
for(i=0;i<=xsize+2;i++)
g.clearRect(i,j,1,1);
//cleaning done above
//0 means white,1 means black
//perform the distance transform
for(j=0;j<ysize;j++)
for(i=0;i<xsize;i++)
{
if(mat1[i][j]==0)continue;
if((j==0)||(j==ysize-1)){mat1[i][j]=1;continue;}
if((i==0)||(i==xsize-1)){mat1[i][j]=1;continue;}

temp=findmin(mat1[i-1][j],mat1[i-1][j-1],mat1[i][j-1],mat1[i+1][j-1]);
mat1[i][j]=temp+1;
}

//perform the distance transform from bottom


for(j=ysize-1;j>=0;j--)
for(i=xsize-1;i>=0;i--)
{if(mat1[i][j]==0)continue;
if((j==0)||(j==ysize-1)){mat1[i][j]=1;continue;}
if((i==0)||(i==xsize-1)){mat1[i][j]=1;continue;}

temp=findmin(mat1[i-1][j+1],mat1[i][j+1],mat1[i+1][j+1],mat1[i+1][j]);
if(temp>(mat1[i][j]-1))temp=mat1[i][j]-1;
mat1[i][j]=temp+1;
}

int max=-9999,colornum,i1,j1,globmax=-9999;
x=0;y=0;
for(j=0;j<ysize-(ysize%sample);j+=sample)
for(i=0;i<xsize-(xsize%sample);i+=sample)
{
max=-9999;
for(j1=j;j1<j+sample;j1++)
for(i1=i;i1<i+sample;i1++)
if(max<mat1[i1][j1])
{
max=mat1[i1][j1];
//xcord=i1;ycord=j1;
}
//out of both above for loops
if(globmax<max)globmax=max;

if(max!=0)
{
System.out.println("max="+max);
for(j1=j;j1<j+sample;j1++)
for(i1=i;i1<i+sample;i1++)
mat1[i1][j1]=max;
}

}
System.out.println("globmax="+globmax);
for(j=0;j<ysize;j++)
for(i=0;i<xsize;i++)
{colornum=(mat1[i][j]*255)/globmax;//contrast enhancement
colornum=255-colornum;
cl=new Color(colornum,colornum,colornum);
g.setColor(cl);
g.drawRect(i,j,1,1);
}
ff.close();
System.out.println("program ends");
}//end try block
catch(Exception e)
{System.out.println("Error"+e.getMessage());
}

}
int findmin(int num1,int num2,int num3,int num4)
{
int min=4000;
if(min>num1)min=num1;
if(min>num2)min=num2;
if(min>num3)min=num3;
if(min>num4)min=num4;
return(min);
}

public static void main(String args[])


{

JFrame frm=new newfndistrans("Distance Transform");


frm.setSize(700,700);
frm.setVisible(true);

}//end main()

}// end class fndistrans


class frame extends JFrame{
JButton but;
JFileChooser fch;
String filename;
File file=null;
//Container con;
boolean temp;
frame()
{ super("FileReading");
setSize(700,500);
setLayout(new FlowLayout());

temp=true;
but=new JButton("Open the binary file");
add(but);
fch=new JFileChooser();
but.addMouseListener(new MouseAdapter()
{ public void mousePressed(MouseEvent me)
{
int retval=fch.showOpenDialog(but);
if(retval==JFileChooser.APPROVE_OPTION)
{
file=fch.getSelectedFile();
filename=file.getName();
System.out.println("1filename="+filename);
temp=false;
}
}

});
setVisible(true);
while(temp);
}//end constructor
File getfilename()
{System.out.println("filename="+filename);
return file;
}

Analog Clock

Description : This is a Analog Clock in synchronisation with the system clock ,written in C
graphics.This is a good project for those intersted in C graphics,if you understand this code,you can
develop your own graphic programs.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#include<stdlib.h>
int a=300,b=150,r=100,bobx1,boby1,bobx2,boby2,bobx3,boby3,flag=1;
int hour,min,sec,hour_ang,min_ang,sec_ang;
int x3,y3,x4,y4,x5,y5,x41,y41,x42,y42,x43,y43,x51,y51,x52,y52,x53,y53;
int color=5;
void drawclock();
void clock(int);
void introduction();
void end();
void main()
{
int gd=DETECT,gm,i,j;
char *buff;
struct time t;
void end();
x3=x4=x5=x41=x42=x43=x51=x52=x53=a;
y3=y4=y5=y41=y42=y43=y51=y52=y53=b;
gettime(&t);
hour=t.ti_hour;
min=t.ti_min;
sec=t.ti_sec;
if(hour>12)hour=hour-12;
initgraph(&gd,&gm,"C:TCBGI");
introduction();
cleardevice();

drawclock();
for(i=sec;!kbhit();i++)
{
clock(i);
}
getch();
end();
getch();
// closegraph();
}
/*************************INTRODUCTION **********************/
void introduction()
{int i,j,k,x,y;
int size=5,style=1;
settextjustify(CENTER_TEXT, CENTER_TEXT);
settextstyle(style, HORIZ_DIR, size);
setcolor(BLUE);
outtextxy(100,200," WELCOME TO ");
delay(1000); setcolor(GREEN);
outtextxy(100,250," RAGHU'S CLOCK SHOW");
delay(1000);
cleardevice();
setfillstyle(1,3);
for(i=0;i<15;i++)
{
setcolor(i);
settextstyle(1,0,3);
outtextxy(500,400,"Loading......");
for(j=0;j<100;j++)
{
circle(a,b+50,j);
delay(10);
}
}
}
/**************************DRAWS THE CLOCK
********************************/
void drawclock()
{
int i,j,k;
int x1,x2,y1,y2,x3,y3;
char *ch;
setcolor(15);
setfillstyle(1,0);
settextstyle(0,0,1);
floodfill(a-r-1,b,0);
for(i=0;i<3;i++)
{
circle(a,b,r+i); //----Draws the outer circles
circle(a,b,i); //----Draws the center pixels
}
for(i=0;i<360;i=i+6) //-----Draws the minute identification
marks
{
x1=a+r*cos(3.14*i/180);
y1=b+r*sin(3.14*i/180);
x2=a+(r-5)*cos(3.14*i/180);
y2=b+(r-5)*sin(3.14*i/180);
line(x1,y1,x2,y2);
}
for(j=0;j<360;j=j+30) //-------Draws the 5 min identification
marks
{
x1=a+r*cos(3.14*j/180);
y1=b+r*sin(3.14*j/180);
x2=a+(r-10)*cos(3.14*j/180);
y2=b+(r-10)*sin(3.14*j/180);
line(x1,y1,x2,y2);
}
line(a-r,b,a-r,b+300);
line(a+r,b,a+r,b+300);
line(a-r,b+300,a+r,b+300);
floodfill(a,b+150,15);
for(i=-60,j=1;i<300;i=i+30,j++) //-------Draws the numbers
{
sprintf(ch,"%d",j);
x1=a+(r-20)*cos(3.14*i/180);
y1=b+(r-20)*sin(3.14*i/180);
outtextxy(x1,y1,ch);
}
setfillstyle(1,color);
floodfill(a+5,b,15);
setfillstyle(1,8);
floodfill(0,0,15);
}
/********************ACTUAL CLOCK OPERATION************************/
void clock(int sec)
{
int i,j,k;

if(sec==60) {sec=sec-60; min++;}


if(min==60){min=0;hour++;}
if(hour>12){hour=hour-12;}
//-------Angles calculation
sec_ang=(sec*6)-90;
min_ang=((min*6)-90)+(sec/10);
hour_ang=(hour*30)+(sec/120)-90;
sound(5000);
setcolor(color);
line(a,b,x3,y3);

line(a,b,x41,y41);
line(a,b,x42,y42);
line(x41,y41,x4,y4);
line(x42,y42,x4,y4);
setfillstyle(1,color);
floodfill(x43,y43,color);

line(a,b,x51,y51);
line(a,b,x52,y52);
line(x51,y51,x5,y5);
line(x52,y52,x5,y5);
setfillstyle(1,color);
floodfill(x53,y53,color);

x3=a+(r-35)*cos(3.14*sec_ang/180);
y3=b+(r-35)*sin(3.14*sec_ang/180);

x4=a+(r-35)*cos(3.14*min_ang/180);
y4=b+(r-35)*sin(3.14*min_ang/180);
x41=a+(r-45)*cos(3.14*(min_ang-3)/180);
y41=b+(r-45)*sin(3.14*(min_ang-3)/180);
x42=a+(r-45)*cos(3.14*(min_ang+3)/180);
y42=b+(r-45)*sin(3.14*(min_ang+3)/180);
x43=a+(r-45)*cos(3.14*(min_ang)/180);
y43=b+(r-45)*sin(3.14*(min_ang)/180);

x5=a+(r-40)*cos(3.14*hour_ang/180);
y5=b+(r-40)*sin(3.14*hour_ang/180);
x51=a+(r-50)*cos(3.14*(hour_ang-5)/180);
y51=b+(r-50)*sin(3.14*(hour_ang-5)/180);
x52=a+(r-50)*cos(3.14*(hour_ang+5)/180);
y52=b+(r-50)*sin(3.14*(hour_ang+5)/180);
x53=a+(r-50)*cos(3.14*(hour_ang)/180);
y53=b+(r-50)*sin(3.14*(hour_ang)/180);

setcolor(RED);
line(a,b,x51,y51);
line(a,b,x52,y52);
line(x51,y51,x5,y5);
line(x52,y52,x5,y5);
setfillstyle(1,RED);
floodfill(x53,y53,RED);
setcolor(GREEN);
line(a,b,x41,y41);
line(a,b,x42,y42);
line(x41,y41,x4,y4);
line(x42,y42,x4,y4);
setfillstyle(1,GREEN);
floodfill(x43,y43,GREEN);
setcolor(BLUE);
line(a,b,x3,y3);
nosound();
if(flag==1)
for(i=75;i<105;i++)
{
bobx1=a+(r+5)*cos(3.14*i/180);
boby1=b+(r+5)*sin(3.14*i/180);
bobx2=a+(r+150)*cos(3.14*i/180);
boby2=b+(r+150)*sin(3.14*i/180);
bobx3=a+(r+125)*cos(3.14*i/180);
boby3=b+(r+125)*sin(3.14*i/180);
setcolor(3);
line(bobx1,boby1,bobx3,boby3);
outtextxy(bobx3,boby3,"Raghu");
circle(bobx2,boby2,20);
circle(bobx2,boby2,25);
setfillstyle(2,4);
delay(15);
setcolor(0);
line(bobx1,boby1,bobx3,boby3);
outtextxy(bobx3,boby3,"Raghu");
flag=0;
circle(bobx2,boby2,25);
circle(bobx2,boby2,20);

}
if(flag==0)
for(i=105;i>75;i--)
{
bobx1=a+(r+5)*cos(3.14*i/180);
boby1=b+(r+5)*sin(3.14*i/180);
bobx2=a+(r+150)*cos(3.14*i/180);
boby2=b+(r+150)*sin(3.14*i/180);
bobx3=a+(r+125)*cos(3.14*i/180);
boby3=b+(r+125)*sin(3.14*i/180);
setcolor(3);
line(bobx1,boby1,bobx3,boby3);
outtextxy(bobx3,boby3,"Raghu");
circle(bobx2,boby2,25);
circle(bobx2,boby2,20);
setfillstyle(2,4);
delay(15);
setcolor(0);
line(bobx1,boby1,bobx3,boby3);
outtextxy(bobx3,boby3,"Raghu");
flag=1;
circle(bobx2,boby2,25);
circle(bobx2,boby2,20);
}
}

void end()
{
int i,j,k;
cleardevice();
settextstyle(1,0,1);
setcolor(3);
outtextxy( 150,100,"For any help and suggestions");
outtextxy(170,120," please send your requests to my e-mail:");
while(!kbhit())
{
for(i=0,j=600;i<600,j>0;i++,j--)
{
setcolor(random(15));
outtextxy(150+i,160," [email protected]");
outtextxy(150+j,200," [email protected]");
setcolor(0);
outtextxy(150+i,160," [email protected]");
outtextxy(150+j,200," [email protected]");
}
if(i==600)
{ for(i=600,j=0;i>0,j<600;i--,j++)
{
setcolor(random(15));
outtextxy(150+i,160," [email protected]");
outtextxy(150+j,200," [email protected]");
setcolor(0);
outtextxy(150+i,160," [email protected]");
outtextxy(150+j,200," [email protected]");
}
}
}
}
Simple Tic Tac Toe Game

Description : This is a simple tic tac toe program built without using graphics.
#include<stdio.h>
#include<conio.h>

void Board();
void PlayerX();
void PlayerO();
void Player_win();
void check();
int win=0,wrong_X=0,wrong_O=0,chk=0;

char name_X[30];
char name_O[30];
int pos_for_X[3][3];
int pos_for_O[3][3];
int pos_marked[3][3];

void main()
{
int i,ch,j;
char ans;
/* clrscr();
printf("\n\t\t\t\tTIC TAC TOE");
printf("\n\t\t\t\t");
for(i=1;i<=11;i++)
{
delay(10000);
printf("*");
}*/
do
{
clrscr();
printf("\n\t\t\t\tTIC TAC TOE");
printf("\n\t\t\t\t");
for(i=1;i<=11;i++)
{
delay(10000);
printf("*");
}
printf("\n1.Start The Game");
printf("\n2.Quit The Game");
printf("\nEnter your choice(1-2) : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
chk=0;
win=0;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
pos_for_X[i][j]=0;
pos_for_O[i][j]=0;
pos_marked[i][j]=0;
}
}
printf("\n\n");
clrscr();
printf("\nEnter the name of the player playing for \'X\':
");
fflush(stdin);
gets(name_X);
printf("\nEnter the name of the player playing for \'O\':
");
fflush(stdin);
gets(name_O);
Board();
for(;;)
{
if(win==1)
break;
check();
if(chk==9)
{
printf("\n\t\t\tMATCH DRAWS!!");
printf("\nPress any key....");
break;
}
else
chk=0;
printf("\nTURN FOR %s:",name_X);
PlayerX();
do
{
if(wrong_X!=1)
break;
wrong_X=0;
printf("\nTURN FOR %s:",name_X);
PlayerX();
}while(wrong_X==1);
check();
if(chk==9)
{
printf("\n\t\t\tMATCH DRAWS");
printf("\nPress any key....");
break;
}
else
chk=0;
printf("\nTURN FOR %s:",name_O);
PlayerO();
do
{
if(wrong_O!=1)
break;
wrong_O=0;
printf("\nTURN FOR %s:",name_O);
PlayerO();
}while(wrong_O==1);

}
Board();
if(win!=1)
{
printf("\n\t\t\tMATCH DRAWS!!");
printf("\nPress any key.......");
}
getch();
break;
case 2:
printf("\n\n\n\t\t\tThank You For Playing The Game.");
printf("\n\t\t\t###############################");
getch();
exit(1);
break;
}
printf("\nWant To Play(Y/N) ? ");
fflush(stdin);
scanf("%c",&ans);
}while(ans=='y' || ans=='Y');
}

void Board()
{
int i,j;
clrscr();
printf("\n\t\t\t\tTIC TAC TOE BOARD");
printf("\n\t\t\t\t*****************");
printf("\n\n\n");
printf("\n\t\t\t 1\t 2\t 3");
for(i=1;i<=3;i++)
{
printf("\n \t\t\t _____________________________");
printf("\n \t\t\tº\t º\t º\t º");
printf("\n\t\t%d\t",i);
for(j=1;j<=3;j++)
{

if(pos_for_X[i][j]==1)
{
printf(" X");
printf(" ");
}
else if(pos_for_O[i][j]==1)
{
printf(" O");
printf(" ");
}
else
{
printf(" ");
continue;
}
}
printf("\n\t\t\tº\t º\t º\t º");
}
printf("\n\t\t\t------------------------------");
Player_win();
}

void PlayerX()
{
int row,col;
if(win==1)
return;
printf("\nEnter the row no. : ");
fflush(stdin);
scanf("%d",&row);
printf("Enter the column no. : ");
fflush(stdin);
scanf("%d",&col);
if(pos_marked[row][col]==1 || row<1 || row>3 || col<1 || col>3)
{
printf("\nWRONG POSITION!! Press any key.....");
wrong_X=1;
getch();
Board();
}
else
{
pos_for_X[row][col]=1;
pos_marked[row][col]=1;
Board();
}
}
void PlayerO()
{
int row,col;
if(win==1)
return;
printf("\nEnter the row no. : ");
scanf("%d",&row);
printf("Enter the column no. : ");
scanf("%d",&col);
if(pos_marked[row][col]==1 || row<1 || row>3 || col<1 || col>3)
{
printf("\nWRONG POSITION!! Press any key....");
wrong_O=1;
getch();
Board();
}
else
{
pos_for_O[row][col]=1;
pos_marked[row][col]=1;
Board();
}
}
void Player_win()
{
int i;
for(i=1;i<=3;i++)
{
if(pos_for_X[i][1]==1 && pos_for_X[i][2]==1 && pos_for_X[i][3]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_X);
printf("\nPress any key............");
return;
}
}
for(i=1;i<=3;i++)
{
if(pos_for_X[1][i]==1 && pos_for_X[2][i]==1 && pos_for_X[3][i]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_X);
printf("\nPress any key............");
return;
}
}
if(pos_for_X[1][1]==1 && pos_for_X[2][2]==1 && pos_for_X[3][3]==1)
{
win=1;
printf("\n\nRESULTL: %s wins!!",name_X);
printf("\nPress any key......");
return;
}
else if(pos_for_X[1][3]==1 && pos_for_X[2][2]==1 &&
pos_for_X[3][1]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_X);
printf("\nPress any key.....");
return;
}

for(i=1;i<=3;i++)
{
if(pos_for_O[i][1]==1 && pos_for_O[i][2]==1 && pos_for_O[i][3]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_O);
printf("\nPress any key.....");
return;
}
}
for(i=1;i<=3;i++)
{
if(pos_for_O[1][i]==1 && pos_for_O[2][i]==1 && pos_for_O[3][i]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_O);
printf("\nPress any key.....");
return;
}
}
if(pos_for_O[1][1]==1 && pos_for_O[2][2]==1 && pos_for_O[3][3]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_O);
printf("\nPress any key.....");
return;
}
else if(pos_for_O[1][3]==1 && pos_for_O[2][2]==1 &&
pos_for_O[3][1]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_O);
printf("\nPress any key.....");
return;
}
}
void check()
{
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
if(pos_marked[i][j]==1)
chk++;
else
continue;
}
}
}

Transformation 2D [ Scaling, Translation, Rotation . . .]

Description : Simple Prog 4 2d Transformation

//TransFormation//
// Rakesh Juyal //
// 2k3mc067 //

#include "Stdio.h"
#include "conio.h"
#include "math.h"
#include "graphics.h"

void intgraph();
void display_cordinate(char bg_color,char line_color);
int Create_poly(int poly[][2]);
void fill_poly(int poly[][2],int points,char line_color,char fill_color);
void Identity(float Matrix[3][3]);
void Translate_to_Relative(int poly[][2],int points,int Xdis,int Ydis);

void main()
{
int poly[3][2],i,points,Xdis,Ydis;
float Sx,Sy,Matrix[3][3],temp,Cos,Sin;
char ch;
intgraph();

setfillstyle(8,RED);
points=Create_poly(poly);
display_cordinate(DARKGRAY,WHITE);
fill_poly(poly,points,WHITE,RED);

getch();
Identity(Matrix);
Xdis=0-poly[0][0];
Ydis=0-poly[0][1];

Translate_to_Relative(poly,points,Xdis,Ydis);

Menu:
restorecrtmode();
do
{
clrscr();
printf("

================================");
printf("
1. Scaling");
printf("
2. Translation");
printf("
3. Rotation");
printf("
4. Reflection [ X axis ]");
printf("
5. Reflection [ Y axis ]");
printf("
6. Reflection [ X=Y axis ]");
printf("
7. Draw ");
printf("
8. EXIT ");
printf("

================================");
printf("
Choose Ur Destiny:- ");
ch=getche();
}while((ch<'1')||(ch>'8'));

switch(ch)
{
case '1':
printf("
Enter Scaling Ratio:- ");
printf("
Sx:- ");
scanf("%f",&Sx);
printf(" Sy:- ");
scanf("%f",&Sy);
for(i=0;i<3;i++)
{
Matrix[i][0]=Matrix[i][0]*Sx;
Matrix[i][1]=Matrix[i][1]*Sy;
}
goto Menu;

case '2':
printf("
Enter Translation [Relative]:- ");
printf("
Tx:- ");
scanf("%f",&Sx);
printf(" Ty:- ");
scanf("%f",&Sy);

Matrix[2][0]=Matrix[2][0]+Sx;
Matrix[2][1]=Matrix[2][1]+Sy;

goto Menu;

case '3':
printf("
Enter Rotation Angle [Degree]:- ");
scanf("%f",&Sx);

Sx=(Sx*3.14)/180;
Cos=cos(Sx);
Sin=sin(Sx);
for(i=0;i<=2;i++)
{
temp=Matrix[i][0]*Cos-Matrix[i][1]*Sin;
Matrix[i][1]=Matrix[i][0]*Sin+Matrix[i][1]*Cos;
Matrix[i][0]=temp;
}
goto Menu;

case '4':
Matrix[1][1]=Matrix[1][1]*-1;
printf("
Done");
getch();

goto Menu;

case '5':
Matrix[0][0]=Matrix[0][0]*-1;
printf("
Done");
getch();

goto Menu;

case '6':
Matrix[0][1]=1;
Matrix[1][1]=1;
printf("
Done");
getch();
goto Menu;

case '7':
for(i=0;i<=points;i++)
{
temp=poly[i][0]*Matrix[0][0]+poly[i][1]*Matrix[1][0]+Matrix[2][0];

poly[i][1]=poly[i][0]*Matrix[0][1]+poly[i][1]*Matrix[1][1]+Matrix[2][1];
poly[i][0]=temp;
}

case '8':
getch();
// closegraph();
exit(0);
}
setgraphmode(2);
display_cordinate(DARKGRAY,WHITE);
Translate_to_Relative(poly,points,-Xdis,-Ydis);
fill_poly(poly,points,CYAN,RED);
getch();
restorecrtmode();
do
{
clrscr();
printf("
Do you Want to Switch to MENU [Y|N]:- ");
ch=getche();
}while( (ch!='Y') && (ch!='N') );
if(ch=='Y')
{
Identity(Matrix);
Xdis=0-poly[0][0];
Ydis=0-poly[0][1];

Translate_to_Relative(poly,points,Xdis,Ydis);
goto Menu;
}
closegraph();
}

void intgraph()
{
int g=DETECT,d;
initgraph(&g,&d,"c:\tc\bgi");
}

void fill_poly(int poly1[][2],int points,char line_color,char fill_color)


{
int pol[20],i;
char str[2];
for(i=0;i<=points;i++)
{
pol[i*2]=poly1[i][0];
pol[i*2+1]=poly1[i][1];
}
pol[i*2]=poly1[0][0];
pol[i*2+1]=poly1[0][1];

setcolor(line_color);
setfillstyle(8,fill_color);
fillpoly(points+1,pol);

setcolor(fill_color);
settextstyle(1,0,3);
for(i=0;i<=points;i++)
{
sprintf(str,"%c",i+'a');
outtextxy(poly1[i][0],poly1[i][1],str);
}
}

void Identity(float Matrix[3][3])


{
int i,j;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(i==j)
Matrix[i][j]=1;
else
Matrix[i][j]=0;
}
}
}
int Create_poly(int poly[][2])
{
poly[0][0]=200;
poly[0][1]=20;

poly[1][0]=300;
poly[1][1]=150;

poly[2][0]=130;
poly[2][1]=280;

return 2;
}

void display_cordinate(char bg_color,char line_color)


{
int i;
setbkcolor(bg_color);
setcolor(line_color);
for(i=0;i<=640;i+=50)
{
line(i,0,i,480);
}

for(i=0;i<=480;i+=50)
{
line(0,i,640,i);
}
rectangle(0,0,639,479);
}

void Translate_to_Relative(int poly[][2],int points,int Xdis,int Ydis)


{
int i;
for(i=0;i<=points;i++)
{
poly[i][0]=poly[i][0]+Xdis;
poly[i][1]=poly[i][1]+Ydis;
}
}

You might also like