Tuesday, November 16, 2010

The Gayatri Mantra....

The Gayatri Mantra is a highly revered mantra in Hinduism. Written in Sanskrit, it consists of the prefix :oṃ bhūr bhuvaḥ svaḥ ॐ भूर्भुवस्वः, a formula taken from the Yajurveda, and the verse 3.62.10 of the Rigveda (which is an example of the Gayatri metre, whence the mantra's name). Since the other three Vedas contain material from the Rigveda, the Gayatri mantra is found in all four Vedas. The deva invoked in this mantra is Savitr, so the mantra is also called Sāvitrī. A personification of this mantra has come to be worshiped as a goddess in her own right, Gayatri. The Gayatri Mantra is praised in several other Hindu scriptures, including Manusmṛti, Atharvaveda, and the Bhagavad Gita.

The Gayatri Mantra is an important part of the upanayanam (sacred thread) ceremony for Brahmins, and was traditionally chanted only by Brahmin males, generally as part of their daily rituals. In modern times, chanting of the Gayatri Mantra is more widespread, such as at cultural celebrations, and its use has spread to include non-Brahmins and women.

"Aum Bhur Bhuvah Swah, Tat Savitur Varenyam
Bhargo Devasya Dhimahi, Dhiyo Yo Nah Prachodayat."

" ॐ भूर्भुव: स्व: तत्सवितुर्वरेण्यं । भर्गो देवस्य धीमहि, धीयो यो न: प्रचोदयात् ।। "

Sunday, November 7, 2010

Installing JDK and JRE in UBUNTU Linux



You need to follow some simple steps for installing Sun Java Development Kit(JDK) & Java Runtime Environment(JRE) in Ubuntu Linux. They are:

Step 1: At the initial stage ,check whether the MULTIVERSE repository is enabled or not.
For this Click on 
System->Administration->Software Sources->Select Multiverse->Close.

Step 2: Open TERMINAL and type the following to install JDK and JRE :sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk
Note: (1):
If you want to use red hat interface , press Ctrl+Alt+F1 and enter the user name and password. For returning to the previous interface , press Ctrl+Alt+F7.(2):You may need to update the runtime or development kit for the java language. For updation typesudo update-java-alternatives -s java-6-sun at the terminal.


Step 3: Set up the environment variable.
For this , do the following:
Type the following at the terminal:
vi $HOME/.bash_profile
Type the following in the opened text file:
export JAVA_home=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin
Save and close the file. For this , press 
ESC and type :wq and press enter.
Warning: Linux is case-sensitive.So,take care of the case of the command entered.

Note: If you want to know the version of JRE installed , use the following command :
java -versionFOR COMPILING THE JAVA PROGRAM , GO TO THE SPECIFIED DIRECTORY AND TYPE
JAVAC FILENAME.JAVAFOR EXECUTING THE PROGRAM , TYPE
JAVA FILENAME

C Graphics Programming in UBUNTU


The solution for doing graphics programming in ubuntu is:
libgraph - library providing the TurboC graphics API ( graphics.h) in Linux using SDL.
For using this , you need to follow some simple steps as mentioned below:
First of all, you need to install the dependencies so that all the required compiler tools gets installed.For that you need to run the given command on the terminal:
sudo apt-get install build-essential
Next you need to install some packages. They are: libsdl-image1.2,libsdl-image1.2-dev,guile-1.8 and guile-1.8-dev. For that run the given command at the terminal:
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev
Now, download and install libgraph-1.0.2.tar.gz from the link :
http://mirror.veriportal.com/savannah/libgraph/
Download this file in any folder and extract it in the home folder or on the desktop wherever you want.
Open the terminal and navigate to the folder where you have extracted libgraph-1.0.2 with the help of cd command. Install this using the commands given below:
./configure (Return)
sudo make (Return)
sudo make install (Return)
After this you can start your C graphics programming in linux. Now try writing a simple C graphics program by including the header file "graphics.h". You can do the programs as you in TURBO C.
For writing the programs you can use the "gedit" tool in ubuntu. For compiling the programs, navigate to the source program folder and use the following command:
gcc filename.c -lgraph
For executing the program, use the command ./a.out
The error “./a.out: error while loading shared libraries: libgraph.so.1: cannot open shared object file: No such file or directory” can be solved by
sudo cp /usr/local/lib/libgraph.* /usr/lib
If you still have any further doubts, then plz post here...hope i'll answer

Thursday, October 28, 2010

Graphics program for Bouncing-ball

#include"stdio.h"

#include"math.h"

#include"graphics.h"



#define ROUND(a) ((int) (a+0.5))

void paracircle(int xcen, int ycen, int r);

//////////////////////////////////////////////////////////////////////

void ddaline2(int xa, int ya, int xb, int yb)

{

int dx = xb - xa, dy = yb - ya, steps, k ;

float xinc,yinc,x = xa,y = ya;

if (abs (dx) > abs (dy) )

steps = abs(dx);

else

steps = abs(dy);

xinc = dx/(float) steps;

yinc = dy/(float) steps;

putpixel( ROUND(x), ROUND(y),RED);

for(k = 0; k < steps ; k++)

{

x += xinc;

y += yinc;

putpixel(ROUND(x),ROUND(y),BROWN);

}

}

//////////////////////////////////////////////////////////////////////

void ddaline(int xa, int ya, int xb, int yb)

{

int dx = xb - xa, dy = yb - ya, steps, k ;

float xinc,yinc,x = xa,y = ya;

if (abs (dx) > abs (dy) )

steps = abs(dx);

else

steps = abs(dy);

xinc = dx/(float) steps;

yinc = dy/(float) steps;

putpixel( ROUND(x), ROUND(y),RED);

for(k = 0; k < steps ; k++)

{

x += xinc;

y += yinc;

ddaline2(0,400,getmaxx(),400);

paracircle(ROUND(x),ROUND(y),30);

delay(5);

if(k % 2 == 0)

cleardevice();

}

}

///////////////////////////////////////////////////////////////////

void paracircle(int xcen, int ycen, int r)

{

float x = 0;

float y;

int theta = 0;

static int i;

for(; theta <= 360; theta++)

{

x = xcen + r * cos( (theta * 3.14) / 180);

y = ycen + r * sin( (theta * 3.14) / 180);

putpixel( (int)x,(int)y, BROWN);

}

putpixel(xcen,ycen,RED);

ddaline2(xcen,ycen,xcen + r*cos((i+120)*3.1415/180),ycen + r*sin((i+120)*3.1415/180) );

ddaline2(xcen,ycen,xcen + r*cos((i+240)*3.1415/180),ycen + r*sin((i+240)*3.1415/180) );

ddaline2(xcen,ycen,xcen + r*cos((i+360)*3.1415/180),ycen + r*sin((i+360)*3.1415/180) );

i++;

}

///////////////////////////////////////////////////////////////////////////

void main()

{

int i,j;

int gd = DETECT,gm;

initgraph(&gd,&gm,"C:\\TC\\BGI");



ddaline(30,30,180,370);

ddaline(180,370,330,130);

ddaline(330,130,480,370);

ddaline(480,370,550,230);

ddaline(550,230,600,370);

ddaline(600,370,getmaxx(),370);

getch();

closegraph();

}

Graphics program for polygon clipping

//Polygon clipping

#include"stdio.h"
#include"graphics.h"
struct point
{
int x;
int y;
}wmin,wmax,p1,p2,ipt,pin[50],pout[50];
int np=0,n;
void newpin();
void drawpolygon();
void showpoints();
void clippolygon()
{
float m=0.0;
int i,j;
np=0;

for(i=0,j=0;i=wmin.x||p1.x>=wmin.x&&p2.x<=wmin.x) { if(p1.x!=p2.x) m=(float)(p1.y-p2.y)/(float)(p1.x-p2.x); ipt.x=wmin.x; ipt.y=p1.y+(wmin.x-p1.x)*m; if(p1.xwmin.x) || (p1.x==wmin.x && p2.x==wmin.x))
{
pout[j]=p2;
j++;
np++;
}
else if(p1.x==wmin.x && p2.xwmin.x&&p2.x>wmin.x)
{
pout[j]=p2;
np++;
j++;
}
}
newpin();
cleardevice();
outtextxy(220,10,"After left clip");
drawpolygon();
showpoints();
getch();
// while (!kbhit());
// closegraph();
// initgraph(&gd,&gm,"NULL");
np=0;
for(i=0,j=0;i=wmax.x&&p2.x<=wmax.x||p1.x<=wmax.x&&p2.x>=wmax.x)
{
if(p1.x!=p2.x)
m=(float)(p1.y-p2.y)/(float)(p1.x-p2.x);
ipt.x=wmax.x;
ipt.y=p1.y+(wmax.x-p1.x)*m;
if(p1.x>wmax.x)
{
pout[j]=ipt;
pout[j+1]=p2;
np=np+2;
j=j+2;
}
else if((p1.x==wmax.x && p2.xwmax.x)
{
}
else
{
p2=ipt;
pout[j]=ipt;
np++;
j++;
}
}
else if(p1.x=wmin.y||p1.y>=wmin.y&&p2.y<=wmin.y) { if(p1.x!=p2.x) m=(float)(p1.y-p2.y)/(float)(p1.x-p2.x); ipt.y=wmin.y; if(m!=0) ipt.x=p1.x+(float)(wmin.y-p1.y)*(float)(1/m); else ipt.x=p1.x; if(p1.ywmin.y) || (p1.y==wmin.y && p2.y==wmin.y))
{
pout[j]=p2;
j++;
np++;
}
else if(p1.y==wmin.y && p2.ywmin.y&&p2.y>wmin.y)
{
pout[j]=p2;
np++;
j++;
}
}
newpin();

cleardevice();
outtextxy(220,10,"After bottom clip");
drawpolygon();
showpoints();
getch();
// while (!kbhit());
// closegraph();
// initgraph(&gd,&gm,"NULL");
np=0;
for(i=0,j=0;i=wmax.y&&p2.y<=wmax.y||p1.y<=wmax.y&&p2.y>=wmax.y)
{
if(p1.x!=p2.x)
m=(float)(p1.y-p2.y)/(float)(p1.x-p2.x);
ipt.y=wmax.y;
if(m!=0)
ipt.x=p1.x+(float)(wmax.y-p1.y)*(float)(1/m);
else
ipt.x=p1.x;
if(p1.y>wmax.y)
{
pout[j]=ipt;
pout[j+1]=p2;
np=np+2;
j=j+2;
}
else if((p1.y==wmax.y && p2.ywmax.y)
{
}
else
{
p2=ipt;
pout[j]=ipt;
np++;
j++;
}
}
else if(p1.y {
pout[j]=p2;
np++;
j++;
}
}
newpin();
cleardevice();
outtextxy(220,10,"clipped Polygon");
showpoints();
drawpolygon();
}
void newpin()
{
int i,j;
for(j=0,i=0;j pin[i]=pout[j];
n=i;
}
void showpoints()
{
int j;
printf("Vertex");
for(j=0;j printf("\n%d.(%d,%d)",j+1,pin[j].x,pin[j].y);
}
void drawpolygon()
{
int j;
setcolor(10);
rectangle(wmin.x,wmin.y,wmax.x,wmax.y);
setcolor(6);
for(j=0;j line(pin[j].x,pin[j].y,pin[(j+1)%n].x,pin[(j+1)%n].y);
}
int main()
{
int c,j;
int gd=DETECT,gm;
initgraph(&gd,&gm,"..//BGI");
printf("Enter the window minimum coordinates");
scanf("%d%d",&wmin.x,&wmin.y);
printf("Enter the window max coordinates");
scanf("%d%d",&wmax.x,&wmax.y);
printf("Enter the no of sides in polygon:\n");
scanf("%d",&n);
printf("Enter the coordinates(x,y)\n");
for(j=0;j{
printf("Enter the coordinate %d\n",j+1);
scanf("%d%d",&pin[j].x,&pin[j].y);
}
initgraph(&gd,&gm,"NULL");
outtextxy(220,10,"Orginal Polygon");
drawpolygon();
getch();
// while (!kbhit());
// closegraph();
// initgraph(&gd,&gm,"NULL");
clippolygon();
while (!kbhit());
closegraph();
return 0;
}

Computer Graphics program for line-clipping

//Line-clipping

#include"stdio.h"
#include"math.h"
#include"graphics.h"

#define ROUND(a) (int)(a + 0.5)
#define TOP 1
#define BOT 2
#define RT 4
#define LT 8
void lineclip(int x1,int y1,int x2,int y2);
void ddaline(int xa, int ya, int xb, int yb);
int xmin,xmax,ymin,ymax;
void main ()
{
int cho,x1,y1,x2,y2;
char ch;
int gd = DETECT, gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
clrscr();
do{
printf("\nENTER X-COORD. & Y-COORD. OF STARTING POINT OF LINE: ");
scanf("%d %d",&x1,&y1);
putpixel(x1,y1,3); //3 IS COLOR CODE OF CYAN
printf("\nENTER X-COORD. & Y-COORD. OF END POINT OF LINE: ");
scanf("%d %d",&x2,&y2);
putpixel(x2,y2,3);
printf("\nENTER X-min & Y-min OF CLIPPING WINDOW: ");
scanf("%d %d",&xmin,&ymin);
putpixel(xmin,ymin,5); //5 IS COLOR CODE OF RED
printf("\nENTER X-max & Y-max OF CLIPPING WINDOW: ");
scanf("%d %d",&xmax,&ymax);
putpixel(xmax,ymax,5);
clrscr();
ddaline(x1, y1, x2, y2);
delay(500);
ddaline(xmin, ymin, xmax, ymin);
delay(500);
ddaline(xmax, ymin, xmax, ymax);
delay(500);
ddaline(xmax, ymax, xmin, ymax);
delay(500);
ddaline(xmin, ymax, xmin, ymin);
delay(500);
getch();
lineclip(x1,y1,x2,y2);
getch();
printf("\nIF YOU WISH TO CONTINUE PRESS Y/y , ELSE ANY OTHER CHAR TO EXIT: ");
scanf(" %c",&ch);
}while(ch == 'y' || ch == 'Y');
getch();
closegraph();
}
////////////////////////////////////////////////////////////////////////////
void ddaline(int xa, int ya, int xb, int yb)
{
int dx = xb - xa, dy = yb - ya, steps, k ;
float xinc,yinc,x = xa,y = ya;
if (abs (dx) > abs (dy) )
steps = abs(dx);
else
steps = abs(dy);
xinc = dx/(float) steps;
yinc = dy/(float) steps;
putpixel( ROUND(x), ROUND(y),RED);
for(k = 0; k < steps ; k++)
{
x += xinc;
y += yinc;
putpixel( ROUND(x), ROUND(y),BROWN);
}
}
/////////////////////////////////////////////////////////////////////////
int findcode(int x, int y)
{
int code = 0;
if(y > ymax)
code |= TOP;
if(y < ymin)
code |= BOT;
if(x > xmax)
code |= RT;
if(x < xmin)
code |= LT;

return code;
}
/////////////////////////////////////////////////////////////////////////
void lineclip(int x1,int y1,int x2,int y2)
{
int code1,code2,t;
int done = 0,accept = 0;
float m,c;
m = (y2 - y1) / (x2 - x1);
c = y1 - m * x1;
while(!done)
{
code1 = findcode(x1,y1);
code2 = findcode(x2,y2);
if( (code1 | code2) == 0 )
{ accept = 1; done = 1; }
else
{
if( (code1 & code2) != 0 )
{ done = 1; }
else
{
if( code1 == 0 )
{
t = x1; x1 = x2; x2 = t;
t = y1; y1 = y2; y2 = t;
t = code1; code1 = code2; code2 = t;
}
if( (code1 & TOP) != 0)
{ y1 = ymax; x1 = (y1 - c) / m; }
else if( (code1 & BOT) != 0 )
{ y1 = ymin; x1 = (y1 - c) / m; }
else if( (code1 & LT) != 0)
{ x1 = xmin; y1 = m * x1 + c; }
else if( (code1 & RT) != 0)
{ x1 = xmax; y1 = m * x1 + c; }
}
}
}
clrscr();
if(accept)
ddaline(x1, y1, x2, y2);
ddaline(xmin, ymin, xmax, ymin);
delay(500);
ddaline(xmax, ymin, xmax, ymax);
delay(500);
ddaline(xmax, ymax, xmin, ymax);
delay(500);
ddaline(xmin, ymax, xmin, ymin);
delay(500);
}

Computer graphics lab// Transformation

// TRANSFORMATION

#include"stdio.h"
#include"math.h"
#include"graphics.h"

#define ROUND(a) ((int) (a+0.5))
void putpixelby(int x, int y, int col,int);
void paracircle(int xcen, int ycen, int r,int);
void circle1(int x, int y, int xcen, int ycen,int);
void rotation(int sx, int sy, float ang);
void translate(int tx, int ty);
void scaling(int sx, int sy, int px, int py);
void ddaline(int xa, int ya, int xb, int yb);
float transfm[3][3] = { {1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0} } ;
float translt[3][3] = { {1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0} } ;
float rotate[3][3] = { {1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0} } ;
float scale[3][3] = { {1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0} } ;
///////////////////////////////////////////////////////////////////////////
void main()
{
int cho1,cho2,xc,yc,r,n,i,x[10],y[10],u[10],v[10],tx,ty,sx,sy,px,py,temp;
float ang;
int gd = DETECT,gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
printf("\n ******");
printf("\n*********************** MENU *************************");
printf("\n ******");
printf("\n1.CIRCLE\n2.POLYGON\nENTER YOUR CHOICE: ");
scanf("%d",&cho1);
switch(cho1)
{
case 1:
printf("\nENTER X & Y COORD. OF CENTER & RADIUS: ");
scanf("%d %d %d",&xc,&yc,&r);
break;
case 2:
printf("\nENTER NO. OF SIDES OF THE POLYGON: ");
scanf("%d",&n);
for(i = 0; i < n ; i++)
{
printf("\nENTER X & Y COORD. OF SIDE %d : ",i+1);
scanf("%d %d",&x[i],&y[i]);
u[i] = x[i]; v[i] = y[i];
}
x[n] = x[0]; y[n] = y[0];
u[n] = x[0]; v[n] = y[0];

for(i = 0; i < n ; i++)
{ ddaline(x[i],y[i],x[i+1],y[i+1]); delay(500); }
break;
default:
printf("\nINVALID CHOICE.....");
}
//////////////////////////////////////////////////////
do{
printf("\n ******");
printf("\n*********************** MENU *************************");
printf("\n ******");
printf("\n1.TRANSLATE\n2.ROTATE\n3.SACLE\n4.EXIT\n\nENTER YOUR CHOICE: ");
scanf("%d",&cho2);
switch(cho2)
{
case 1:
printf("\nENTER X & Y COORD OF POINT OF TRANSLATION: ");
scanf("%d %d",&tx,&ty);
translate(tx,ty);
break;
case 2:
printf("\nENTER ANGLES IN DEGREE: ");
scanf("%f",&ang);
printf("\nENTER COORD. X & Y OF PIVOT POINT: ");
scanf("%d %d",&px,&py);
rotation(px,py,(ang*3.14)/180);
break;
case 3:
printf("\nENTER SCALING FACTOR X & Y: ");
scanf("%d %d",&sx,&sy);
printf("\nENTER COORD. X & Y OF PIVOT POINT: ");
scanf("%d %d",&px,&py);
scaling(sx,sy,px,py);
break;
case 4:
break;
default:
printf("\nINVALID CHOICE.....");
}
}while(cho2 == 1 || cho2 == 2 || cho2 == 3);
///////////////////////////////////////////////
cleardevice();
getch();
ddaline( (getmaxx()/2),0,(getmaxx()/2),(getmaxy()) );
ddaline( 0,(getmaxy()/2),(getmaxx()),(getmaxy()/2) );
if(cho1 == 2)
{
for(i = 0; i < n; i++)
{ //TO SVAE THE VALUE OF x[i]
temp = transfm[0][0]*x[i] + transfm[0][1]*y[i] + transfm[0][2] ;
y[i] = transfm[1][0]*x[i] + transfm[1][1]*y[i] + transfm[1][2] ;

x[i] = temp; //RESTORE THE VALUE OF x[i]
}
x[n] = x[0]; y[n] = y[0];
for(i = 0; i < n; i++)
{
v[i] = (-1) * v[i];
y[i] = (-1) * y[i];
}
x[n] = x[0]; y[n] = y[0];
u[n] = u[0]; v[n] = v[0];
for(i = 0; i < n; i++)
{
u[i] = (getmaxx()/2) + u[i];
v[i] = (getmaxy()/2) + v[i];
x[i] = (getmaxx()/2) + x[i];
y[i] = (getmaxy()/2) + y[i];
}
x[n] = x[0]; y[n] = y[0];
u[n] = u[0]; v[n] = v[0];
for(i = 0; i < n ; i++)
{ ddaline(u[i],v[i],u[i+1],v[i+1]); delay(500); }
for(i = 0; i < n ; i++)
{ ddaline(x[i],y[i],x[i+1],y[i+1]); delay(500); }
}
///////////////////////////////////////////////////////////////////
else if(cho1 == 1)
{
paracircle(xc,yc,r,1);
paracircle(xc,yc,r,2);
}
getch();
closegraph();
}
///////////////////////////////////////////////////////////////////////////
void translate(int tx, int ty)
{
float temp[3][3];
int i,j;
translt[0][2] = tx;
translt[1][2] = ty;
for(i = 0; i < 3; i++)
for(j = 0; j < 3 ; j++)
temp[i][j] = transfm[i][0]*translt[0][j] + transfm[i][1]*translt[1][j] + transfm[i][2]*translt[2][j];
for(i = 0; i < 3; i++)
for(j = 0; j < 3 ; j++)
transfm[i][j] = temp[i][j];
}
///////////////////////////////////////////////////////////////////////////
void rotation(int px, int py, float ang)
{
float temp[3][3];
int i,j;
float c,s,p,q;
c = cos(ang); s = sin(ang);
p = px*(1 - c) + py * s;
q = py*(1 - c) - px * s;
rotate[0][0] = c;
rotate[0][1] = (-1) * s;
rotate[0][2] = p;
rotate[1][0] = s;
rotate[1][1] = c;
rotate[1][2] = q;
for(i = 0; i < 3; i++)
for(j = 0; j < 3 ; j++)
temp[i][j] = transfm[i][0]*rotate[0][j] + transfm[i][1]*rotate[1][j] + transfm[i][2]*rotate[2][j];
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++)
transfm[i][j] = temp[i][j];
}
///////////////////////////////////////////////////////////////////////////
void scaling(int sx, int sy, int px, int py)
{
float temp[3][3];
int i,j;
scale[0][0] = sx;
scale[0][2] = px*(1 - sx);
scale[1][1] = sy;
scale[1][2] = py*(1 - sy);
for(i = 0; i < 3; i++)
for(j = 0; j < 3 ; j++)
temp[i][j] = transfm[i][0]*scale[0][j] + transfm[i][1]*scale[1][j] + transfm[i][2]*scale[2][j];
for(i = 0; i < 3; i++)
for(j = 0; j < 3 ; j++)
transfm[i][j] = temp[i][j];
}
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
void ddaline(int xa, int ya, int xb, int yb)
{
int dx = xb - xa, dy = yb - ya, steps, k ;
float xinc,yinc,x = xa,y = ya;
if (abs (dx) > abs (dy) )
steps = abs(dx);
else
steps = abs(dy);
xinc = dx/(float) steps;
yinc = dy/(float) steps;
putpixel( ROUND(x), ROUND(y),RED);
for(k = 0; k < steps ; k++)
{
x += xinc;
y += yinc;
putpixel( ROUND(x), ROUND(y),BROWN);
}
}
////////////////////////////////////////////////////////////////////////////
void paracircle(int xcen, int ycen, int r, int position)
{
float x = 0;
float y;
int theta = 0;
//circle1((int)x,(int)y,xcen,ycen,position);
for(; theta <= 45; theta++)
{
x = r * cos( (theta * 3.14) / 180);
y = r * sin( (theta * 3.14) / 180);
circle1(x, y, xcen, ycen,position);
}
putpixel(xcen,ycen,RED);
}
///////////////////////////////////////////////////////////////////////////
void circle1(int x, int y, int xcen, int ycen,int position)
{
putpixelby(xcen + x, ycen + y, BROWN,position);
putpixelby(xcen - x, ycen + y, BROWN,position);
putpixelby(xcen + x, ycen - y, BROWN,position);
putpixelby(xcen - x, ycen - y, BROWN,position);
putpixelby(xcen + y, ycen + x, BROWN,position);
putpixelby(xcen - y, ycen + x, BROWN,position);
putpixelby(xcen + y, ycen - x, BROWN,position);
putpixelby(xcen - y, ycen - x, BROWN,position);
}
//////////////////////////////////////////////////////////////////////////
void putpixelby(int x, int y, int col,int position)
{
float temp;
if(position == 2)
{
temp = transfm[0][0]*x + transfm[0][1]*y + transfm[0][2] ;
y = transfm[1][0]*x + transfm[1][1]*y + transfm[1][2] ;
x = temp;
}
y = (-1) * y;
x = (getmaxx()/2) + x;
y = (getmaxy()/2) + y;
putpixel(x,y,col);
}
///////////////////////////////////////////////////////////////////////////

Computer graphics// Program to fill water in a bucket from pipe

//program to fill water in a bucket

#include"stdio.h"
#include"graphics.h"
#include"math.h"

void main()
{
int gd=DETECT,gm=DETECT,i,j;
initgraph(&gd,&gm,"c:\\tc\\bgi");
ellipse(300,200,0,360,50,25);
ellipse(300,300,0,360,50,25);
line(250,200,250,300);
line(350,200,350,300);
ellipse(300,100,180,360,5,2);
line(295,100,295,80);
line(305,100,305,86);
arc(300,80,90,180,5);
putpixel(306,85,15);
putpixel(307,84,15);
line(308,84,630,84);
line(300,75,303,75);
line(314,75,630,75);
putpixel(304,74,15);
putpixel(305,73,15);
line(306,72,306,65);
line(311,72,311,65);
putpixel(312,73,15);
putpixel(313,74,15);
pieslice(309,62,0,360,5);
setfillstyle(SOLID_FILL,BLUE);
setcolor(BLUE);
for(i=0;i<7;i++)
{
line(297+i,103,297+i,300);
}
for(i=1;i<100;i++)
{
setcolor(LIGHTBLUE);
ellipse(300,300-i,180,360,4,2);
delay(30);
fillellipse(300,300-i,49,25);
setcolor(1);
line(297,275-i,303,275-i);
setcolor(15);
ellipse(300,200,180,360,50,25);
delay(50);
}
ellipse(300,200,0,360,50,25);
setcolor(0);
for(i=0;i<7;i++)
line(297+i,103,297+i,174);
getch();
}

What does double precision variable mean in C?

If you know what float is, then double is like an advanced version of float. It can hold a larger number value because the variable can hold more bytes of memory.
Now if you don't know what a float is then read this:
if you notice. If you name a variable with the type "int" you can only put in whole numbers and not decimal numbers (Ex: 1 , -1 , 100 , -100 , etc)

With double you can store any type of number in the variable Ex: 1.0 , 2.56783 , 2.192
Now float is a lower version of double and can still store any number but it can't store very large numbers. Most times people use double instead of float , but there's some good situations when you'd use float over double for example. Say the variable won't be a large value then you'd use float because it takes up less space and therefore the program will run faster.

So to sum it all up
1.Double means that the number stored in the variable is a real number , meaning you can store numbers with decimals and what not.
2. Double can hold a larger number value than int or float because it can hold more bytes of memory.
3. Double is most commonly used , rather than float.

diff between exit(0) and return(0)

Returning a value from main() and calling exit() with
that value are almost perfectly equivalent. The subtle
difference is that the local `auto' variables in main()
cease to exist when main() returns, so if any program
cleanup code -- atexit() routines, the automatic flushing
and closing of open I/O streams, and so on -- tries to
use these variables, there will probably be trouble that
wouldn't occur if exit() had been called instead.

Why return 0 gives in end of main function in c language?

The return code from a c program does not have to be zero.
Zero is a value that happens to indicate a successful completion of the program.

The use of this return code can be seen in this link for batch processing.

A return code of 4 usually indicates a warning has occurred.
A return code of 8 or more indicates an error.

Monday, October 25, 2010

computer graphics lab

//PROGRAM FOR FAN


#include

#include

#include


#define pi 3.142857

#define ROUND(a) ((int)(a+0.5))

void pie(int sa,int ea,int xc,int yc,int r)

{

double a1,a2;
int x,y;

a1=(pi*sa)/180;

x=xc+r*cos(a1);

y=yc+r*sin(a1);

line(xc,yc,x,y);

a2=-(pi*ea)/180;

x=xc+r*cos(a2);

y=yc+r*sin(a2);

line(xc,yc,x,y);

}


///////////////////////////////////////////////////


void runfan(int d)

{
int i=0,sa=0,ea=1;


while(!kbhit())

{
delay(d);

cleardevice();

circle(100,100,50);

line(90,150,90,250);

line(110,150,110,250);

line(40,250,40,300);

line(160,250,160,300);

line(40,300,160,300);

line(40,250,160,250);

outtextxy(45,275,"0");

outtextxy(75,275,"1");

outtextxy(105,275,"2");

outtextxy(135,275,"3");


pie(sa,ea,100,100,50);

pie(sa+150,ea+150,100,100,50);

pie(sa+300,ea+300,100,100,50);

i++;

sa=sa-10;
ea=ea+10;

}

}

/////////////////////////////////////////////////


int main()

{

int d=0,cho;

int gd=DETECT,gm;

initgraph(&gd,&gm," ");

runfan(0);

do
{

//runfan(0);

printf("\n enter the speed of regulator");

scanf("%d",&d);

switch(d)

{

case 0:

runfan(d);

break;

case 1:

runfan(70);
break;

case 2:

runfan(50);
break;

case 3:

runfan(20);
break;

}

printf("\n press 1 to continue");

scanf("%d",&cho);

}
while(cho==1);

getch();

return (0);

}

computer graphics lab //PROGRAM OF CIRCUM-CIRCLE

//PROGRAM OF CIRCUM-CIRCLE



#include

#include
#include
void main()
{
int n,i,x[10],y[10],a[10],b[10];
float m[10],c[10],xc,yc,r;
int gd=DETECT,gm;
initgraph(&gd,&gm,"..//bgi");
printf("enterd no of sides: ");
scanf("%d",&n);
for(i=0;i
{
printf(" Enter the x and y cordinates: ");
scanf("%d %d",&x[i],&y[i]);
}
x[n]=x[0]; y[n]=y[0];
for(i=0;i
{
line(x[i],y[i],x[i+1],y[i+1]);
delay(500);
}
for(i=0;i
{
a[i]=(x[i]+x[i+1])/2;
b[i]=(y[i]+y[i+1])/2;
}
for(i=0;i
{
if(y[i]!=y[i+1])
{
m[i]=-(float)(x[i]-x[i+1])/(y[i]-y[i+1]);
c[i]=b[i]-m[i]*a[i];
}
else
m[i]=0;
}
i=0;
if(y[i]==y[i+1])
{
xc=a[i];
yc=(float)(m[i+1]*xc+c[i+1]);
}
else if(y[i+1]==y[i+2])
{
xc=a[i+1];
yc=(float)(m[i+2]*xc+c[i+2]);
}
else
{
xc=(c[i+1]-c[i])/(m[i]-m[i+1]);
yc=m[i]*xc+c[i];
}
printf("%f %f %d %d\n",xc,yc,x[1],y[1]);
r=sqrt((xc-x[1])*(xc-x[1])+(yc-y[1])*(yc-y[1]));
putpixel((int)xc,(int)yc,2);
setcolor(3);
printf("%f %f %f",xc,yc,r);
circle((int)xc,(int)yc,r);
setcolor(5);
getch();
}

computer graphics lab



//PROGRAM TO DRAW A CAR

#include
#include
#define round(x) ((int)(x+0.5))
void parametric(int x,int y)
{ int i;
float r=40,x2,y2;
for(i=180;i<360;i++)
{
x2=(float)(x)+r*cos((i*3.1415)/180);
y2=(float)(y)+r*sin((i*3.1415)/180);
putpixel(round(x2),round(y2),15);
}
}
void car()
{
int x1=0,x2=20,x3=40,x4=50,x5=60,x6=70,x7=100,x8=120,x9=130,x10=180,x11=200,x12=205,x13=210,x14=220,x15=240,x16=260,x17=300;
while(x17<600)
{
cleardevice();
line(x1,250,x1,350);
line(x1,350,x3,350);
line(x1,250,x3,150);
line(x2,250,x4,250);
line(x2,250,x4,175);
line(x4,250,x4,175);
line(x5,250,x5,175);
circle(x6,350,38);
circle(x6,350,25);
parametric(x6,350);
line(0,388,650,388);
line(x5,175,x8,175);
line(x5,250,x8,250);
line(x8,175,x8,250);
line(x9,175,x9,250);
line(x9,175,x11,175);
line(x9,250,x11,250);
line(x11,175,x11,250);
line(x7,350,x10,350);
line(x12,175,x12,250);
line(x12,175,x15,250);
line(x12,250,x15,250);
line(x3,150,x14,150);
line(x14,150,x16,225);
circle(x13,350,38);
circle(x13,350,25);
parametric(x13,350);
line(x16,225,x17,250);
line(x15,350,x17,350);
line(x17,250,x17,350);
delay(20);
x1++; x2++;x3++;x4++;x5++; x6++; x7++; x8++; x9++; x10++; x11++; x12++; x13++;
x14++; x15++; x16++; x17++;
}
}
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"..//bgi");
car();
getch();
}