22/02/12 17:24C Programming
Página 1 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
S U N D A Y , O C T O B E R 2 5 , 2 0 0 9
C++ program to display a calender
A simple C++ graphics program to display a Calender.It also gives anintroduction to mouse programming in graphics. Save the file with a'.cpp' extension and compile it.
#include<iostream.h>#include<conio.h>#include<graphics.h>#include<stdlib.h>#include<dos.h>#include<string.h>union REGS i,o;initmouse();showmouse();hidemouse();void restrictmouse(int x1,int y1,int x2,int y2);void getmousestatus( int *button,int *x,int *y);void findday();void menu();void cal();void main(){clrscr();int gd=EGA,gm=EGAHI;initgraph(&gd,&gm,"c:\\tc\\bgi ");menu();getch();closegraph();}void findday(){int k=1,m=11,mon,D,C,f,i,y,total=0,t,I,d,x1=115,y1=160,q,r,v;static int s=0;char st2[3],st3[9],st4[5];int days[]={31,28,31,30,31,30,31,31,30,31,30,31};char*month[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMEBER"};restorecrtmode();cout<<"Enter year : ";
clock
Labels
Animation (1)
Bezier Curve Drawing Algorithm(1)
Boundary Fill Algorithm (1)
Bresenham Circle Drawingalgorithm (1)
Bresenham line drawingalgorithm (1)
C++ (1)
C++ program to make a pie chart(1)
Calender (1)
Character Generation (1)
Cohen Sutherland Line ClippingAlgorithm (1)
Digital Differential Analyzer Linedrawing algorithm (1)
Flood Fill Algorithm (1)
Install Turbo C (1)
Liang Barsky Line ClippingAlgorithm (1)
Mid-Point Ellipse Drawing
Compartilhar Denunciar abuso Próximo blog» Criar um blog Login
C Programming
22/02/12 17:24C Programming
Página 2 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
cin>>y;cout<<"Enter month : ";cin>>mon;if(mon>12){cout<<" Invalid entry !.....";delay(1000);setgraphmode(getgraphmode());menu();}y-=1;C=y/100;D=y%100;f=(k+((13*m-1)/5)+D+(D/4)+(C/4)-(2*C));i=f%7;if(i< 0)i+=7;y++;if(y%4==0)days[1]=29;for(t=0;t<mon-1;t++){total+=days[t];}I=total%7;d=I+i;if(d>=7)d=d%7;setgraphmode(getgraphmode());cal();v=mon-1;strcpy(st3,month[v]);itoa(y,st4,10);settextstyle(2,0,8);outtextxy(100,90,st3);outtextxy(250,90,st4);q=days[mon-1];settextstyle(1,0,2);setcolor(15);for(r=1;r<=d;r++){x1+=62;s++;}for(r=1;r<=q;r++){itoa(r,st2,10);if(s>=6){outtextxy(x1,y1,st2);y1+=30;x1=112;s=0;continue;
Algorithm (1)
new folder.exe (1)
Oblique projection (1)
Perspective projection (1)
Polygon (1)
regsvr.exe (1)
Rotation (2)
Scaling (2)
Scan Line (1)
The Olympic Symbol (1)
Translation (2)
Virus removal (1)
Advertise onthis site
Powered ByAdBrite
Your Ad Here
22/02/12 17:24C Programming
Página 3 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
}outtextxy(x1,y1,st2);x1+=60;s++;}s=0;getch();menu();}void menu(){cleardevice();int b,xx,yy;initmouse();restrictmouse(0,0,getmaxx(),getmaxy());setbkcolor(0);settextstyle(10,0,2);outtextxy(100,70,"***********MENU***********");outtextxy(100,150,"=> MONTH'S CALENDAR");outtextxy(100,200,"=> EXIT");settextstyle(8,0,1);outtextxy(350,300,"Made By: ANGAD");showmouse();while(!kbhit()){getmousestatus(&b,&xx,&yy);if(xx>=100&&yy>=150&&xx<=500&&yy<=200){getmousestatus(&b,&xx,&yy);if(b&1==1){hidemouse();cleardevice();findday();}}if(xx>=100&&yy>=200&&xx<=300&&yy<=260){getmousestatus(&b,&xx,&yy);if(b&1==1){hidemouse();cleardevice();setbkcolor(0);setcolor(15);settextstyle(10,0,5);outtextxy(100,200,"EXITING");int o=0;for(int n=0;n< 10;n++){outtextxy(380+o,200,".");o+=20;delay(200);}
About Me
AngadMUMBAI,Maharashtra,India
For any questions or difficultiesfeel free to mail me at: [email protected]
View my complete profile
Blog Archive
October (2)
September (2)
June (2)
May (15)
Followers
Join this sitewith Google Friend Connect
Members (45) More »
Already a member? Sign in
22/02/12 17:24C Programming
Página 4 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
exit(0);}}}}void cal(){cleardevice();int l=100,t=125,r=155,b=185,g,x=110,y=127;char *day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};char st1[4];setbkcolor(0);settextstyle(10,0,7);setcolor(15);outtextxy(100,-40,"C");settextstyle(10,0,6);outtextxy(160,-20,"ALENDAR");setfillstyle(1,BLUE);bar(85,115,530,345);setfillstyle(1,0);bar3d(l,t,r,b,0,0);bar3d(l,t+30,r,b+30,0,0);bar3d(l,t+60,r,b+60,0,0);bar3d(l,t+90,r,b+90,0,0);bar3d(l,t+120,r,b+120,0,0);bar3d(l,t+150,r,b+150,0,0);bar3d(l,t+180,r,b+150,0,0);bar3d(l+60,t,r+60,b,0,0);bar3d(l+60,t+30,r+60,b+30,0,0);bar3d(l+60,t+60,r+60,b+60,0,0);bar3d(l+60,t+90,r+60,b+90,0,0);bar3d(l+60,t+120,r+60,b+120,0,0);bar3d(l+60,t+150,r+60,b+150,0,0);bar3d(l+60,t+180,r+60,b+150,0,0);bar3d(l+120,t,r+120,b,0,0);bar3d(l+120,t+30,r+120,b+30,0,0);bar3d(l+120,t+60,r+120,b+60,0,0);bar3d(l+120,t+90,r+120,b+90,0,0);bar3d(l+120,t+120,r+120,b+120,0,0);bar3d(l+120,t+150,r+120,b+150,0,0);bar3d(l+120,t+180,r+120,b+150,0,0);bar3d(l+180,t,r+180,b,0,0);bar3d(l+180,t+30,r+180,b+30,0,0);bar3d(l+180,t+60,r+180,b+60,0,0);bar3d(l+180,t+90,r+180,b+90,0,0);bar3d(l+180,t+120,r+180,b+120,0,0);bar3d(l+180,t+150,r+180,b+150,0,0);bar3d(l+180,t+180,r+180,b+150,0,0);bar3d(l+240,t,r+240,b,0,0);bar3d(l+240,t+30,r+240,b+30,0,0);bar3d(l+240,t+60,r+240,b+60,0,0);bar3d(l+240,t+90,r+240,b+90,0,0);bar3d(l+240,t+120,r+240,b+120,0,0);bar3d(l+240,t+150,r+240,b+150,0,0);
22/02/12 17:24C Programming
Página 5 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
bar3d(l+240,t+180,r+240,b+150,0,0);bar3d(l+300,t,r+300,b,0,0);bar3d(l+300,t+30,r+300,b+30,0,0);bar3d(l+300,t+60,r+300,b+60,0,0);bar3d(l+300,t+90,r+300,b+90,0,0);bar3d(l+300,t+120,r+300,b+120,0,0);bar3d(l+300,t+150,r+300,b+150,0,0);bar3d(l+300,t+180,r+300,b+150,0,0);bar3d(l+360,t,r+360,b,0,0);bar3d(l+360,t+30,r+360,b+30,0,0);bar3d(l+360,t+60,r+360,b+60,0,0);bar3d(l+360,t+90,r+360,b+90,0,0);bar3d(l+360,t+120,r+360,b+120,0,0);bar3d(l+360,t+150,r+360,b+150,0,0);bar3d(l+360,t+180,r+360,b+150,0,0);settextstyle(1,0,2);setcolor(15);for(g=0;g< 7;g++){strcpy(st1,day[g]);outtextxy(x,y,st1);x+=60;}}initmouse(){i.x.ax=0;int86(0x33,&i,&o);return(o.x.ax);}showmouse(){i.x.ax=1;int86(0x33,&i,&o);return(o.x.ax);}hidemouse(){i.x.ax=2;int86(0x33,&i,&o);return(o.x.ax);}void restrictmouse(int x1,int y1,int x2,int y2){i.x.ax=7;i.x.cx=x1;i.x.dx=x2;int86(0x33,&i,&o);i.x.ax=8;i.x.cx=y1;i.x.dx=y2;int86(0x33,&i,&o);}void getmousestatus(int *button,int *x,int *y)
22/02/12 17:24C Programming
Página 6 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 2:42 AM
{i.x.ax=3;int86(0x33,&i,&o);*button=o.x.bx;*x=o.x.cx;*y=o.x.dx;}
Labels: C++, Calender35 comments
T U E S D A Y , O C T O B E R 1 3 , 2 0 0 9
Simple C program for Scan Line Polygon FillingAlgorithm
#include <stdio.h>#include <conio.h>#include <graphics.h>
main(){
int n,i,j,k,gd,gm,dy,dx;int x,y,temp;int a[20][2],xi[20];float slope[20];
clrscr();printf("\n\n\tEnter the no. of edges of polygon : ");scanf("%d",&n);printf("\n\n\tEnter the cordinates of polygon :\n\n\n ");
for(i=0;i<n;i++){printf("\tX%d Y%d : ",i,i);scanf("%d %d",&a[i][0],&a[i][1]);}
a[n][0]=a[0][0];a[n][1]=a[0][1];
detectgraph(&gd,&gm);initgraph(&gd,&gm,"c:\\tc\\bgi");
/*- draw polygon -*/
for(i=0;i<n;i++) {line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
22/02/12 17:24C Programming
Página 7 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
}
getch();
for(i=0;i<n;i++){dy=a[i+1][1]-a[i][1];dx=a[i+1][0]-a[i][0];
if(dy==0) slope[i]=1.0;if(dx==0) slope[i]=0.0;
if((dy!=0)&&(dx!=0)) /*- calculate inverse slope -*/ {slope[i]=(float) dx/dy;}}
for(y=0;y< 480;y++){k=0;for(i=0;i<n;i++){
if( ((a[i][1]<=y)&&(a[i+1][1]>y))||((a[i][1]>y)&&(a[i+1][1]<=y))){xi[k]=(int)(a[i][0]+slope[i]*(y-a[i][1]));k++;}}
for(j=0;j<k-1;j++) /*- Arrange x-intersections in order -*/for(i=0;i<k-1;i++){if(xi[i]>xi[i+1]){temp=xi[i];xi[i]=xi[i+1];xi[i+1]=temp;}}
setcolor(35);for(i=0;i<k;i+=2){line(xi[i],y,xi[i+1]+1,y);getch();}
}
}
22/02/12 17:24C Programming
Página 8 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 12:53 PMLabels: Polygon, Scan Line
17 comments
S A T U R D A Y , S E P T E M B E R 1 9 , 2 0 0 9
Guide to prevent your computer from gettinginfected with Viruses that spread throughremovable media(like pen drives).
Most of us use removable media daily, for transferring data from onecomputer to another.We generally use pen drives with computers atoffices, colleges, cyber cafes, etc...The computers at such places mayor may not have anti-virus software installed. If the system you areusing is infected with virus, then this virus will also get transferredonto your pen drive along with other data. If you use a pen drivecontaining virus, it will infect your system, which intern may lead toloss and/or theft of your personal data and leave you with no otheroption but to format your hard drive. Most common forms of suchviruses are regsvr.exe,new folder.exe, etc..I have been using this method to prevent my computer from gettinginfected with viruses,contained in removable media, for quiet sometime now with great success, so I thought i'd share it with others.All you need, to follow this guide is a good anti-virus software ( Irecommend and use ESET NOD32 ).
STEP 1: Click 'start' and then select 'run'.
STEP 2: In the dialogue box type 'gpedit.msc'.Doing this will give youaccess to the group policy editor.
22/02/12 17:24C Programming
Página 9 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
NOTE:- the group policy editor can only be accessed from theadministrator's account.
SETP 3: A new window should now open. Click on 'Administrativetemplates'.
STEP 4: Now on the left hand side, double click 'system'.This is whatyour window should look like.
STEP 5: From the list, find the line that reads 'Prevent access toregistry editing tools'.
22/02/12 17:24C Programming
Página 10 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
STEP 7: Double click it and a new window should open.
STEP 8: Select 'enabled' and click 'apply'.
This will prevent an unwanted application (Virus) to make anychanges to the registry.
STEP 9: Now select 'turn off autoplay' from the list and double click it.
STEP 10: Select 'enabled' and from the drop down box select 'alldrives',click apply.
22/02/12 17:24C Programming
Página 11 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
This is what your window should look like:
The virus contains an 'autorun.inf' file. Whenever you plug in your pendrive into the usb port an interrupt is generated,your computerservices the interrupt with the appropriate ISR (interrupt serviceroutine), this is how the computer (and the virus) know that someremovable media has been connected to your computer. The autoplayfeature reads this autorun.inf file and executes the commands listedin it. These commands are responsible for installing the virus filesonto your system without your permission.So turning 'off' the autoplaywizard, does not allow the 'autorun.inf' to execute its code.
STEP 11: Now plug in the pen drive and go to 'my computer'.
22/02/12 17:24C Programming
Página 12 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 1:23 PM
Step 12: 'Right click' on the icon that corresponds to your pen driveand select 'advanced options' and then 'clean files'.
STEP 13: Nod32 will now start scanning the removable media forviruses.
STEP 14: Once the scan is complete, select and delete all the infectedfiles from the scan log.
STEP 15: Just to make sure that the autorun.inf file is no longerpresent on your pen drive, go to 'start',click run and type cmd (givesaccess to the command prompt). Type your drive letter followed by':'. For eg. if my drive letter is 'i', I will type 'i:'. On the next line type'dir'.This should give you a list of all the files present in your pendrive. If you see the 'autorun.inf' file in the list the simply delete itusing this command 'del autorun.inf'.
STEP 16: The virus changes the attributes of all the folders on yourpen drive to 'hidden', so to collectively remove the hidden attributefrom all the files and view the files once again just type this in thecommand prompt:I:\>attrib -H -S \*.* /S /D
STEP 17: Now open my computer and 'explore' (do not double clickand access the drive as yet) your pen drive. At this point you shouldbe able to see and access all files on your pen drive. Simply deletethe files that you don't recognize or alternatively just copy all therequired files onto some other location.
STEP 18: After all the required data as been recovered, format yourpen drive !!
Labels: new folder.exe, regsvr.exe, Virus removal4 comments
C++ program to make a pie chart
#include<iostream.h>#include<stdio.h>
22/02/12 17:24C Programming
Página 13 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 4:32 AM
#include<conio.h>#include<math.h>#include<graphics.h>#include<dos.h>#define round(a)(int(a+0.5))void main(){double total=0.0,a=0.0;double x2,y2;int i,n;int gd=DETECT,gm;initgraph(&gd,&gm,"C:\\TC\\BGI");cout<<"PIE CHART"<<endl;cout<<"Enter the no. of regions"<<endl;cin>>n;double values[10];double per[10];double angle[10]={0,0,0,0,0,0,0,0,0,0};double b[10];cout<<"Enter the values of the regions"<<endl;circle(300,300,100);line(300,300,400,300);for(i=0;i<n;i++){cin>>values[i];total=total+values[i];}for(i=0;i<n;i++){per[i]=((values[i]/total)*100);a=((per[i]/100)*360);if(i==0)b[i]=a;elseb[i]=b[i-1]+a;angle[i]=(3.14*b[i])/180;x2=(300+100*cos(angle[i]));y2=(300-100*sin(angle[i]));line(300,300,round(x2),round(y2));setfillstyle(1,i+1);if(x2>300&&y2< 300)floodfill(x2+2,y2+2,15);elsefloodfill(x2-2,y2-2,15);}getch();closegraph();}
Labels: C++ program to make a pie chart2 comments
S U N D A Y , J U N E 7 , 2 0 0 9
22/02/12 17:24C Programming
Página 14 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
C Program For Oblique projection of a 3D object
#include<stdio.h>#include<math.h>#include<graphics.h>
main(){
int x1,y1,x2,y2,gd,gm;int ymax,a[4][8];float par[4][4],b[4][8];int i,j,k,m,n,p;double L1,phi;
a[0][0] = 100; a[1][0] = 100; a[2][0] = 100;a[0][1] = 200; a[1][1] = 100; a[2][1] = 100;
a[0][2] = 200; a[1][2] = 200; a[2][2] = 100;a[0][3] = 100; a[1][3] = 200; a[2][3] = 100;
a[0][4] = 100; a[1][4] = 100; a[2][4] = 200;a[0][5] = 200; a[1][5] = 100; a[2][5] = 200;
a[0][6] = 200; a[1][6] = 200; a[2][6] = 200;a[0][7] = 100; a[1][7] = 200; a[2][7] = 200;
phi = (double) (3.14*45.0)/180 ;L1 = 0.5;
par[0][0] = 1; par[0][1] = 0;par[0][2] = L1*cos(phi); par[0][3] = 0;
par[1][0] = 0; par[1][1] = 1;par[1][2] = L1*sin(phi); par[1][3] = 0;
par[2][0] = 0; par[2][1] = 0;par[2][2] = 0; par[2][3] = 0;
par[3][0] = 0; par[3][1] = 0;par[3][2] = 0; par[3][3] = 1;
m=4; n=4; p=8;
for(i=0; i<m; i++)for(k=0; k<p; k++)b[i][k] = 0;
for(i=0; i<m; i++)for(k=0; k<p; k++)for(j=0; j<n; j++)
22/02/12 17:24C Programming
Página 15 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 2:17 PM
b[i][k] += (float)par[i][j] * a[j][k];
detectgraph(&gd,&gm);initgraph(&gd,&gm, "c:\\tc\\bgi");
ymax = getmaxy();
/*- front plane display -*/
for(j=0;j<3;j++){x1=(int) b[0][j]; y1=(int) b[1][j];x2=(int) b[0][j+1]; y2=(int) b[1][j+1];line( x1,ymax-y1,x2,ymax-y2);
}x1=(int) b[0][3]; y1=(int) b[1][3];x2=(int) b[0][0]; y2=(int) b[1][0];line( x1,ymax-y1,x2,ymax-y2);
/*- back plane display -*/
setcolor(11);for(j=4;j<7;j++){x1=(int) b[0][j]; y1=(int) b[1][j];x2=(int) b[0][j+1]; y2=(int) b[1][j+1];line( x1,ymax-y1,x2,ymax-y2);
}x1=(int) b[0][7]; y1=(int) b[1][7];x2=(int) b[0][4]; y2=(int) b[1][4];line( x1,ymax-y1,x2,ymax-y2);
setcolor(13);for(i=0;i<4;i++){x1=(int) b[0][i]; y1=(int) b[1][i];x2=(int) b[0][4+i]; y2=(int) b[1][4+i];line( x1,ymax-y1,x2,ymax-y2);}
getch(); getch();
}
Labels: Oblique projection3 comments
C Program For Perspective projection of 3D Object
22/02/12 17:24C Programming
Página 16 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
#include<stdio.h>#include<math.h>#include<graphics.h>
main(){
int x1,y1,x2,y2,gd,gm;int ymax,a[4][8];float par[4][4],b[4][8];int i,j,k,m,n,p;int xp, yp, zp, x, y, z;
a[0][0] = 100; a[1][0] = 100; a[2][0] = -100;a[0][1] = 200; a[1][1] = 100; a[2][1] = -100;
a[0][2] = 200; a[1][2] = 200; a[2][2] = -100;a[0][3] = 100; a[1][3] = 200; a[2][3] = -100;
a[0][4] = 100; a[1][4] = 100; a[2][4] = -200;a[0][5] = 200; a[1][5] = 100; a[2][5] = -200;
a[0][6] = 200; a[1][6] = 200; a[2][6] = -200;a[0][7] = 100; a[1][7] = 200; a[2][7] = -200;
detectgraph(&gd,&gm);initgraph(&gd,&gm, "c:\\tc\\bgi");
ymax = getmaxy();xp = 300; yp = 320; zp = 100;
for(j=0; j<8; j++){x = a[0][j]; y = a[1][j]; z = a[2][j];
b[0][j] = xp - ( (float)( x - xp )/(z - zp)) * (zp);b[1][j] = yp - ( (float)( y - yp )/(z - zp)) * (zp);}
/*- front plane display -*/
for(j=0;j<3;j++){x1=(int) b[0][j]; y1=(int) b[1][j];x2=(int) b[0][j+1]; y2=(int) b[1][j+1];line( x1,ymax-y1,x2,ymax-y2);
}x1=(int) b[0][3]; y1=(int) b[1][3];x2=(int) b[0][0]; y2=(int) b[1][0];
22/02/12 17:24C Programming
Página 17 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 1:56 PM
line( x1, ymax-y1, x2, ymax-y2);
/*- back plane display -*/setcolor(11);for(j=4;j<7;j++){x1=(int) b[0][j]; y1=(int) b[1][j];x2=(int) b[0][j+1]; y2=(int) b[1][j+1];line( x1, ymax-y1, x2, ymax-y2);
}x1=(int) b[0][7]; y1=(int) b[1][7];x2=(int) b[0][4]; y2=(int) b[1][4];line( x1, ymax-y1, x2, ymax-y2);
setcolor(7);for(i=0;i<4;i++){x1=(int) b[0][i]; y1=(int) b[1][i];x2=(int) b[0][4+i]; y2=(int) b[1][4+i];line( x1, ymax-y1, x2, ymax-y2);}
getch(); getch();
}
Labels: Perspective projection3 comments
T U E S D A Y , M A Y 1 2 , 2 0 0 9
Installing TURBO C
All My programs can be compiled using the turbo C complier.Thefollowing tutorial is for installation of Turbo C on your computer.
Step 1> Copy the code for the program to notepad and save the filewith a ".c" extension (for c code) & ".c++" extension (for c++ code).
Step 2> Download the compiler from the above link and save the file.
Step 3> Open the file tc3.zip, find INSTALL.exe from its contents anddouble click to open it.
22/02/12 17:24C Programming
Página 18 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Step 4> A new window should open up now, press ENTER.
Step 5> Enter the drive letter you want to install turbo c on and pressENTER.
22/02/12 17:24C Programming
Página 19 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Step 6> Now on thw following screen type the source path or pressENTER to select the default path.
Step 7> After this just press F9 on the screen that follows to continueinstallation.
22/02/12 17:24C Programming
Página 20 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
CONGRACTULATIONS you have set up turbo c on your computersuccessfully
Now copy the file you saved in Step 1 to the C:\TC\Bin folder and runit from turbo c!!
Note:- Inorder to run graphics programs you have to include thegraphics library, for thisrun turbo c then select Options->Linker->Libraries and check thegraphics library.
This tutorial is for Installation of Turbo C on windows XP 32-bit, willpost instructions for installation on XP 64-bit and Vista in sometime......
22/02/12 17:24C Programming
Página 21 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 3:55 AMLabels: Install Turbo C
57 comments
Graphics program to Display Animation (Fireworks)
#include<conio.h>#include<graphics.h>#include<stdio.h>#include<math.h>void main(){int gd,gm;int x,y;int i,j,kk;
detectgraph(&gd,&gm);initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(WHITE);line(0,400,640,400);rectangle(300,330,340,400);rectangle(310,320,330,330);setcolor(4);line(319,280,319,398);line(320,280,320,398);rectangle(320,280,330,300);outtextxy(340,280,"PRESS ANY KEY TO IGNITE THE ROCKET");getch();for(j=400;j<640;j++){cleardevice();setcolor(WHITE);line(0,j,640,j);rectangle(300,j-70,340,j);rectangle(310,j-80,330,j-70);
setcolor(RED);line(319,280,319,400);line(320,280,320,400);rectangle(320,280,330,300);
setcolor(YELLOW);circle(325,300,2);
delay(5);}
for(i=400;i>340;i--){cleardevice();
setcolor(RED);
22/02/12 17:24C Programming
Página 22 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 12:52 AM
line(319,i,319,i-120);line(320,i,320,i-120);rectangle(320,i-120,330,i-100);
setcolor(YELLOW);circle(325,i-100,2);delay(25);}
cleardevice();kk=0;for(j=100;j<350;j++){if(j%20==0){setcolor(kk);kk=kk+3;delay(50);}ellipse(320,30,0,360,j+100,j+0);}for(j=100;j<350;j++){if(j%20==0){setcolor(BLACK);delay(2);}ellipse(320,30,0,360,j+100,j+0);}cleardevice();for(i=0;i<70;i++){setcolor(i);settextstyle(GOTHIC_FONT,HORIZ_DIR,6);outtextxy(110,150,"HAPPY NEWYEAR");delay(90);}getch();}
Labels: Animation12 comments
M O N D A Y , M A Y 1 1 , 2 0 0 9
C Program To Output The Olympic Symbol
#include<stdio.h>#include<graphics.h>#include<conio.h>#include<math.h>#include<dos.h>
22/02/12 17:24C Programming
Página 23 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
void main(){int i=0,j=0,k=0,l=0,m=0,ch;float pi=3.1424,a,b,c,d,e;int gd=DETECT,gm;initgraph(&gd,&gm,"c:\\tc\\bgi");printf("\n\nEnter 1 or 2 ");scanf("%d",&ch);printf("\n\nYou have entered %d",ch);getch();clrscr();switch(ch){case 1 : while(i<360){a=(pi/180)*i;setcolor(3);circle(120+100*sin(a),150-100*cos(a),10);i++;delay(5);}while(j<360){b=(pi/180)*j;setcolor(0);circle(280+100*sin(b),150-100*cos(b),10);j++;delay(5);}while(k<360){c=(pi/180)*k;setcolor(4);circle(440+100*sin(c),150-100*cos(c),10);k++;delay(5);}while(l<360){d=(pi/180)*l;setcolor(14);circle(200+100*sin(d),300-100*cos(d),10);l++;delay(5);}while(m<360){e=(pi/180)*m;setcolor(2);circle(370+100*sin(e),300-100*cos(e),10);m++;delay(5);}
22/02/12 17:24C Programming
Página 24 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 5:19 AM
break;case 2 : while(i<360){a=(pi/180)*i;setcolor(3);circle(120+100*sin(a),150-100*cos(a),10);i++;delay(5);}while(l<360){d=(pi/180)*l;setcolor(14);circle(200+100*sin(d),300-100*cos(d),10);l++;delay(5);}while(j<360){b=(pi/180)*j;setcolor(0);circle(280+100*sin(b),150-100*cos(b),10);j++;delay(5);}while(k<360){c=(pi/180)*k;setcolor(4);circle(440+100*sin(c),150-100*cos(c),10);k++;delay(5);}while(m<360){e=(pi/180)*m;setcolor(2);circle(370+100*sin(e),300-100*cos(e),10);m++;delay(5);}
break;default:setcolor(13);outtextxy(190,220,"YOU HAVE ENTERED THE WRONG CHOICE!!");}getch();}
Labels: The Olympic Symbol1 comments
22/02/12 17:24C Programming
Página 25 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
C Program for 3-D transformations
#include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> #include<stdlib.h>
int xp[2],yp[2],z; void display(); void translate(); void scaling(); void rotation(); void matrixmul(int [4][4]);
void main() { int gd=DETECT,gm; int ch,i; initgraph(&gd,&gm,"c:\\tc\\bgi"); for(i=0;i<2;i++) { printf("\nEnter X-coordinate of vertex %d : ",i+1); scanf("%d",&xp[i]); printf("\nEnter Y-coordinate of vertex %d : ",i+1); scanf("%d",&yp[i]); } printf("\nEnter The Z-axis For 3d Figure : "); scanf("%d",&z); clrscr(); cleardevice(); display(xp,yp); getche(); do { printf("----- MENU -----"); printf("\n1.TRANSLATION."); printf("\t2.SCALING."); printf("\n3.ROTATION."); printf("\t4.EXIT."); printf("\nEnter Your Choice : "); scanf("%d",&ch); clrscr(); cleardevice(); display(xp,yp); switch(ch) { case 1 : translate(); break;
case 2 : scaling(); break;
22/02/12 17:24C Programming
Página 26 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
case 3 : rotation(); break;
case 4 : exit(0);
default: outtextxy(1,66,"-PLEASE SELECT THE RIGHT OPTION-");} } while(ch!=4); getch(); closegraph(); }
void translate() { int p[4][4]; int tx,ty,tz,i,j; for(i=0;i<4;i++) for(j=0;j<4;j++) p[i][j]=(i==j); printf("\nEnter The Translating Factor tx : "); scanf("%d",&tx); printf("\nEnter The Translating Factor ty : "); scanf("%d",&ty); printf("\nEnter The Translating Factor tz : "); scanf("%d",&tz); clrscr(); cleardevice(); display(); p[0][3]=tx; p[1][3]=ty; p[2][3]=tz; matrixmul(p); }
void scaling() { int p[4][4]; int sx,sy,sz,i,j; for(i=0;i<4;i++) for(j=0;j<4;j++) p[i][j]=(i==j); printf("\nEnter The Scaling Factor sx : "); scanf("%d",&sx); printf("\nEnter The Scaling Factor sy : "); scanf("%d",&sy); printf("\nEnter The Scaling Factor sz : "); scanf("%d",&sz); if(sx==0) sx=1; if(sy==0) sy=1; if(sz==0)
22/02/12 17:24C Programming
Página 27 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
sz=1; clrscr(); cleardevice(); p[0][0]=sx; p[1][1]=sy; p[2][2]=sz; p[3][3]=1; matrixmul(p); }
void rotation() { float res[4][1],p[4][4],t[4][1]; int ang,i,j,k,l,rch; float rad; for(i=0;i<4;i++) for(j=0;j<4;j++) p[i][j]=(i==j); printf("\nEnter The Rotating Angle : "); scanf("%d",&ang); rad=ang*0.0174; printf("\nChoose the axis of roration "); printf("\n1.X-axis"); printf("\n2.Y-axis"); printf("\n3.Z-axis"); printf("\nEnter Your Choice : "); scanf("%d",&rch); switch(rch) { case 1 : p[1][1]=cos(rad); p[1][2]=(-1)*sin(rad); p[2][1]=sin(rad); p[2][2]=cos(rad); break;
case 2 : p[0][0]=cos(rad); p[2][0]=(-1)*sin(rad); p[0][2]=sin(rad); p[2][2]=cos(rad); break;
case 3 : p[0][0]=cos(rad); p[0][1]=(-1)*sin(rad); p[1][0]=sin(rad); p[1][1]=cos(rad); break;
default : printf("\nInvalid Choice !"); } clrscr(); cleardevice();
22/02/12 17:24C Programming
Página 28 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
for(i=0;i<2;i++) { t[0][0]=xp[i]; t[1][0]=yp[i]; t[2][0]=z; t[3][0]=1; for(j=0;j<4;j++) { for(k=0;k<1;k++) { res[j][k]=0; for(l=0;l<4;l++) { res[j][k]=res[j][k]+(p[j][l]*t[l][k]); } } } xp[i]=res[0][0]; yp[i]=res[1][0]; z=res[2][0]; } display(xp,yp); }
void display(int xp[2],int yp[2]) { int x3,y3,x4,y4; line(getmaxx()/2,0,getmaxx()/2,getmaxy()); line(0,getmaxy()/2,getmaxx(),getmaxy()/2); outtextxy(getmaxx()/2+5,getmaxy()/2+5,"(0,0)"); outtextxy(getmaxx()-50,getmaxy()/2+10,"X-Axis"); outtextxy(getmaxx()/2+10,20,"Y-Axis"); outtextxy(10,getmaxy()/2+10,"X'-Axis"); outtextxy(getmaxx()/2+10,getmaxy()-20,"Y'-Axis"); rectangle(getmaxx()/2+xp[0],getmaxy()/2-yp[0],getmaxx()/2+xp[1],getmaxy()/2-yp[1]); if(z>=xp[0]) { x3=z+xp[0]; y3=z+yp[0]; x4=z+xp[1]; y4=z+yp[1]; rectangle(getmaxx()/2+x3,getmaxy()/2-y3,getmaxx()/2+x4,getmaxy()/2-y4); line(getmaxx()/2+xp[0],getmaxy()/2-yp[0],getmaxx()/2+x3,getmaxy()/2-y3); line(getmaxx()/2+xp[1],getmaxy()/2-yp[1],getmaxx()/2+x4,getmaxy()/2-y4); line(getmaxx()/2+xp[0],getmaxy()/2-yp[1],getmaxx()/2+x3,getmaxy()/2-y4); line(getmaxx()/2+xp[1],getmaxy()/2-yp[0],getmaxx()/2+x4,getmaxy()/2-y3); } else
22/02/12 17:24C Programming
Página 29 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 12:01 AM
{ x3=xp[0]-z; y3=yp[0]-z; x4=xp[1]-z; y4=yp[1]-z; rectangle(getmaxx()/2+x3,getmaxy()/2-y3,getmaxx()/2+x4,getmaxy()/2-y4); line(getmaxx()/2+xp[0],getmaxy()/2-yp[0],getmaxx()/2+x3,getmaxy()/2-y3); line(getmaxx()/2+xp[1],getmaxy()/2-yp[1],getmaxx()/2+x4,getmaxy()/2-y4); line(getmaxx()/2+xp[0],getmaxy()/2-yp[1],getmaxx()/2+x3,getmaxy()/2-y4); line(getmaxx()/2+xp[1],getmaxy()/2-yp[0],getmaxx()/2+x4,getmaxy()/2-y3); } }
void matrixmul(int a[4][4]) { float res[4][1],b[4][1]; int i,j,k,l; for(i=0;i<2;i++) { b[0][0]=xp[i]; b[1][0]=yp[i]; b[2][0]=z; b[3][0]=1; for(j=0;j<4;j++) { for(k=0;k<1;k++) { res[j][k]=0; for(l=0;l<4;l++) { res[j][k]=res[j][k]+(a[j][l]*b[l][k]); } } } xp[i]=res[0][0]; yp[i]=res[1][0]; } z=res[2][0]; display(xp,yp); }
Labels: Rotation, Scaling, Translation1 comments
S A T U R D A Y , M A Y 9 , 2 0 0 9
C program to implement Bezier Curve DrawingAlgorithm
22/02/12 17:24C Programming
Página 30 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
#include<stdio.h>#include<conio.h>#include<graphics.h>
int x,y,z;
void main(){float u;int gd,gm,ymax,i,n,c[4][3];
for(i=0;i<4;i++) { c[i][0]=0; c[i][1]=0; }
printf("\n\n Enter four points : \n\n");
for(i=0; i<4; i++){printf("\t X%d Y%d : ",i,i);scanf("%d %d",&c[i][0],&c[i][1]);
}
c[4][0]=c[0][0];c[4][1]=c[0][1];
detectgraph(&gd,&gm);initgraph(&gd,&gm,"e:\\tc\\bgi");
ymax = 480;
setcolor(13);for(i=0;i<3;i++){line(c[i][0],ymax-c[i][1],c[i+1][0],ymax-c[i+1][1]);}
setcolor(3);n=3;
for(i=0;i<=40;i++){u=(float)i/40.0;bezier(u,n,c);
if(i==0){ moveto(x,ymax-y);}else{ lineto(x,ymax-y); }getch();}
22/02/12 17:24C Programming
Página 31 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 4:46 AM
getch();}bezier(u,n,p)float u;int n; int p[4][3];{int j;float v,b;float blend(int,int,float);x=0;y=0;z=0;for(j=0;j<=n;j++){b=blend(j,n,u);x=x+(p[j][0]*b);y=y+(p[j][1]*b);z=z+(p[j][2]*b);}}
float blend(int j,int n,float u){int k;float v,blend;v=C(n,j);for(k=0;k<j;k++){ v*=u; }for(k=1;k<=(n-j);k++){ v *= (1-u); }blend=v;return(blend);}
C(int n,int j){int k,a,c;a=1;for(k=j+1;k<=n;k++) { a*=k; }for(k=1;k<=(n-j);k++) { a=a/k; }c=a;return(c);}
Labels: Bezier Curve Drawing Algorithm3 comments
C program for 2D Transformations
#include<stdio.h>#include<conio.h>#include<graphics.h>#include<math.h>
void translate();
22/02/12 17:24C Programming
Página 32 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
void scale();void rotate();
void main(){int ch;int gd=DETECT,gm;initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(6);outtextxy (100,88,"Object.");rectangle(100,150,150,100);
printf("---MENU---");printf("\n 1)Translate\n 2)Scale\n 3)Rotate");printf("\nEnter your choice: ");scanf("%d",&ch);cleardevice();
switch(ch){case 1: translate();break;case 2: scale();break;case 3: rotate();break;default: printf("you have enterd wrong choice");break;}getch();closegraph();}
void translate(){int tx,ty;setcolor(2);outtextxy(240,10,"TRANSLATION");outtextxy(238,20,"------------");printf("\nEnter tx: ");scanf("%d",&tx);printf("\nEnter ty: ");scanf("%d",&ty);cleardevice();rectangle(100,150,150,100);printf("\nAfter Translation");rectangle(100+tx,150+ty,150+tx,100+ty);}
void scale(){int sx,sy;setcolor(2);
22/02/12 17:24C Programming
Página 33 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
outtextxy(240,10,"SCALING");outtextxy(238,20,"--------");printf("\nEnter sx: ");scanf("%d",&sx);printf("\nEnter sy: ");scanf("%d",&sy);cleardevice();rectangle(100,150,150,100);printf("\nAfter Scaling");rectangle(100*sx,150*sy,150*sx,100*sy);}
void rotate(){float theta;int x1,x2,x3,x4;int y1,y2,y3,y4;int ax1,ax2,ax3,ax4,ay1,ay2,ay3,ay4;int refx,refy;printf("\nEnter the angle for rotation: ");scanf("%f",&theta);theta=theta*(3.14/180);cleardevice();setcolor(2);outtextxy(240,10,"ROTATE");outtextxy(238,20,"-------");refx=100;refy=100;
x1=100;y1=100;x2=150;y2=100;x3=150;y3=150;x4=100;y4=150;
ax1=refy+(x1-refx)*cos(theta)-(y1-refy)*sin(theta);ay1=refy+(x1-refx)*sin(theta)+(y1-refy)*cos(theta);
ax2=refy+(x2-refx)*cos(theta)-(y2-refy)*sin(theta);ay2=refy+(x2-refx)*sin(theta)+(y2-refy)*cos(theta);
ax3=refy+(x3-refx)*cos(theta)-(y3-refy)*sin(theta);ay3=refy+(x3-refx)*sin(theta)+(y3-refy)*cos(theta);
ax4=refy+(x4-refx)*cos(theta)-(y4-refy)*sin(theta);ay4=refy+(x4-refx)*sin(theta)+(y4-refy)*cos(theta);rectangle(100,150,150,100);line(ax1,ay1,ax2,ay2);line(ax2,ay2,ax3,ay3);line(ax3,ay3,ax4,ay4);line(ax4,ay4,ax1,ay1);
22/02/12 17:24C Programming
Página 34 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 2:07 AM
}
Labels: Rotation, Scaling, Translation13 comments
T H U R S D A Y , M A Y 7 , 2 0 0 9
C Program for Cohen Sutherland Line ClippingAlgorithm
#include<stdio.h>#include<graphics.h>#include<conio.h>
typedef unsigned int outcode;enum { TOP=0x1, BOTTOM=0x2, RIGHT=0x4, LEFT=0x8 };
void lineclip(x0,y0,x1,y1,xwmin,ywmin,xwmax,ywmax )float x0,y0,x1,y1,xwmin,ywmin,xwmax,ywmax;{
int gd,gm;outcode code0,code1,codeout;int accept = 0, done=0;
code0 = calcode(x0,y0,xwmin,ywmin,xwmax,ywmax);code1 = calcode(x1,y1,xwmin,ywmin,xwmax,ywmax);
do{if(!(code0 | code1)){ accept =1 ; done =1; }elseif(code0 & code1) done = 1;else{float x,y;codeout = code0 ? code0 : code1;if(codeout & TOP){x = x0 + (x1-x0)*(ywmax-y0)/(y1-y0);y = ywmax;}elseif( codeout & BOTTOM){x = x0 + (x1-x0)*(ywmin-y0)/(y1-y0);y = ywmin;}elseif ( codeout & RIGHT){
22/02/12 17:24C Programming
Página 35 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
y = y0+(y1-y0)*(xwmax-x0)/(x1-x0);x = xwmax;}else{y = y0 + (y1-y0)*(xwmin-x0)/(x1-x0);x = xwmin;}if( codeout == code0){x0 = x; y0 = y;code0=calcode(x0,y0,xwmin,ywmin,xwmax,ywmax);}else{x1 = x; y1 = y;code1 = calcode(x1,y1,xwmin,ywmin,xwmax,ywmax);}}} while( done == 0);
if(accept) line(x0,y0,x1,y1);
rectangle(xwmin,ywmin,xwmax,ywmax);
getch();
}
int calcode (x,y,xwmin,ywmin,xwmax,ywmax)float x,y,xwmin,ywmin,xwmax,ywmax;{int code =0;
if(y> ywmax)code |=TOP;else if( y<ywmin)code |= BOTTOM;else if(x > xwmax)code |= RIGHT;else if ( x< xwmin)code |= LEFT;
return(code);}
main(){
float x2,y2,x1,y1,xwmin,ywmin,xwmax,ywmax;int gd=DETECT,gm;
22/02/12 17:24C Programming
Página 36 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 11:11 AM
clrscr();initgraph(&gd,&gm,"e:\\tc\\bgi");
printf("\n\n\tEnter the co-ordinates of Line :");
printf("\n\n\tX1 Y1 : ");scanf("%f %f",&x1,&y1);
printf("\n\n\tX2 Y2 : ");scanf("%f %f",&x2,&y2);
printf("\n\tEnter the co_ordinates of window :\n ");printf("\n\txwmin , ywmin : ");scanf("%f %f",&xwmin,&ywmin);printf("\n\txwmax , ywmax : ");scanf("%f %f",&xwmax,&ywmax);clrscr();line(x1,y1,x2,y2);rectangle(xwmin,ywmin,xwmax,ywmax);getch();clrscr();
lineclip(x1,y1,x2,y2,xwmin,ywmin,xwmax,ywmax );getch();closegraph();
}
Labels: Cohen Sutherland Line Clipping Algorithm19 comments
W E D N E S D A Y , M A Y 6 , 2 0 0 9
C Program for Liang Barsky Line Clipping Algorithm
#include<graphics.h>#include<dos.h>#include<conio.h>#include<stdlib.h>
void main(){int gd, gm ;int x1 , y1 , x2 , y2 ;int wxmin,wymin,wxmax, wymax ;float u1 = 0.0,u2 = 1.0 ;int p1 , q1 , p2 , q2 , p3 , q3 , p4 ,q4 ;float r1 , r2 , r3 , r4 ;int x11 , y11 , x22 , y22 ;clrscr();printf("Enter the windows left xmin , top boundry ymin\n");
22/02/12 17:24C Programming
Página 37 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
scanf("%d%d",&wxmin,&wymin);printf("Enter the windows right xmax ,bottom boundry ymax\n");scanf("%d%d",&wxmax,&wymax);printf("Enter line x1 , y1 co-ordinate\n");scanf("%d%d",&x1,&y1);printf("Enter line x2 , y2 co-ordinate\n");scanf("%d%d",&x2,&y2);printf("liang barsky express these 4 inequalities using lpk<=qpk\n");p1 = -(x2 - x1 ); q1 = x1 - wxmin ;p2 = ( x2 - x1 ) ; q2 = wxmax - x1 ;p3 = - ( y2 - y1 ) ; q3 = y1 - wymin ;p4 = ( y2 - y1 ) ; q4 = wymax - y1 ;printf("p1=0 line is parallel to left clipping\n");printf("p2=0 line is parallel to right clipping\n");printf("p3=0 line is parallel to bottom clipping\n");printf("p4=0 line is parallel to top clipping\n");
if( ( ( p1 == 0.0 ) && ( q1 < 0.0 ) ) ||( ( p2 == 0.0 ) && ( q2 < 0.0 ) ) ||( ( p3 == 0.0 ) && ( q3 < 0.0 ) ) ||( ( p4 == 0.0 ) && ( q4 < 0.0 ) ) ){printf("Line is rejected\n");getch();detectgraph(&gd,&gm);initgraph(&gd,&gm,"c:\\tc\\bgi");setcolor(RED);rectangle(wxmin,wymax,wxmax,wymin);setcolor(BLUE);line(x1,y1,x2,y2);getch();setcolor(WHITE);line(x1,y1,x2,y2);getch();}else{if( p1 != 0.0 ){r1 =(float) q1 /p1 ;if( p1 < 0 )u1 = max(r1 , u1 );elseu2 = min(r1 , u2 );}if( p2 != 0.0 ){r2 = (float ) q2 /p2 ;if( p2 < 0 )u1 = max(r2 , u1 );elseu2 = min(r2 , u2 );
}
22/02/12 17:24C Programming
Página 38 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
if( p3 != 0.0 ){r3 = (float )q3 /p3 ;if( p3 < 0 )u1 = max(r3 , u1 );elseu2 = min(r3 , u2 );}if( p4 != 0.0 ){r4 = (float )q4 /p4 ;if( p4 < 0 )u1 = max(r4 , u1 );elseu2 = min(r4 , u2 );}
if( u1 > u2 )printf("line rejected\n");else{x11 = x1 + u1 * ( x2 - x1 ) ;y11 = y1 + u1 * ( y2 - y1 ) ;
x22 = x1 + u2 * ( x2 - x1 );y22 = y1 + u2 * ( y2 - y1 );
printf("Original line cordinates\n");printf("x1 = %d , y1 = %d, x2 = %d, y2 = %d\n",x1,y1,x2,y2);printf("Windows coordinate are \n");printf("wxmin = %d, wymin = %d,wxmax = %d , wymax = %d",wxmin,wymin,wxmax,wymax);
printf("New coordinates are \n");printf("x1 = %d, y1 = %d,x2 = %d , y2 = %d\n",x11,y11,x22,y22);detectgraph(&gd,&gm);initgraph(&gd,&gm,"C:\\TC\\BGI");setcolor(2);rectangle(wxmin,wymax,wxmax,wymin);setcolor(1);line(x1,y1,x2,y2);getch();setcolor(0);line(x1,y1,x2,y2);setcolor(3);line(x11,y11,x22,y22);getch();
}}}
Labels: Liang Barsky Line Clipping Algorithm
22/02/12 17:24C Programming
Página 39 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 10:43 PM 4 comments
T U E S D A Y , M A Y 5 , 2 0 0 9
C Implementation of Mid-Point Ellipse DrawingAlgorithm
#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <time.h> #include <dos.h>
int main(void) { int gd=DETECT,gm; int cenx,ceny;float Pk,a,b,x,y; clrscr();
printf("\n\n Enter 'a' and 'b': "); scanf("%f%f",&a,&b);
initgraph(&gd,&gm,"c:\\tc\\bgi");
cenx=getmaxx()/2; ceny=getmaxy()/2;
Pk=b*b-b*a*a+0.25*a*a; x=0; y=b; putpixel(cenx+x,ceny+y,WHITE);putpixel(cenx+x,ceny-y,WHITE);putpixel(cenx-x,ceny+y,WHITE);putpixel(cenx-x,ceny-y,WHITE);
while (2*x*b*b <= 2*y*a*a) { if (Pk<0) { x=x+1; y=y; Pk=Pk+2*x*b*b+3*b*b; } else { x=x+1; y=y-1; Pk=Pk+2*x*b*b+3*b*b-2*y*a*a+2*a*a; } putpixel(cenx+x,ceny+y,WHITE);
22/02/12 17:24C Programming
Página 40 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 1:11 PM
putpixel(cenx+x,ceny-y,WHITE);putpixel(cenx-x,ceny+y,WHITE);putpixel(cenx-x,ceny-y,WHITE);delay(40); }
Pk=(x+0.5)*(x+0.5)*b*b+(y-1)*(y-1)*a*a-a*a*b*b; putpixel(cenx+x,ceny+y,WHITE);putpixel(cenx+x,ceny-y,WHITE);putpixel(cenx-x,ceny+y,WHITE);putpixel(cenx-x,ceny-y,WHITE);while (y>0){if (Pk>0){x=x;y=y-1;Pk=Pk-2*y*a*a+3*a*a;}else{x=x+1;y=y-1;Pk=Pk-2*y*a*a+3*a*a+2*x*b*b+2*b*b;}putpixel(cenx+x,ceny+y,WHITE);putpixel(cenx+x,ceny-y,WHITE);putpixel(cenx-x,ceny+y,WHITE);putpixel(cenx-x,ceny-y,WHITE);delay(40);}gotoxy(1,25);printf ("\npress any key to exit.");getch(); closegraph(); return 0; } /*SAMPLE INPUT*/
/*Enter 'a' and 'b' 120 80*/
Labels: Mid-Point Ellipse Drawing Algorithm3 comments
C Program to Implement Flood Fill Algorithm
#include<conio.h>#include<stdio.h>#include<graphics.h>#include<dos.h>
22/02/12 17:24C Programming
Página 41 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
void fill_right(x,y)int x , y ;{if(getpixel(x,y) == 0){putpixel(x,y,RED);fill_right(++x,y);x = x - 1 ;fill_right(x,y-1);fill_right(x,y+1);
}}
void fill_left(x,y)int x , y ;{if(getpixel(x,y) == 0){putpixel(x,y,RED);
fill_left(--x,y);x = x + 1 ;fill_left(x,y-1);fill_left(x,y+1);
}}
void main(){int x , y ,a[10][10];int gd, gm ,n,i;
detectgraph(&gd,&gm);initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("\n\n\tEnter the no. of edges of polygon : ");scanf("%d",&n);printf("\n\n\tEnter the cordinates of polygon :\n\n\n ");
for(i=0;i<n;i++){printf("\tX%d Y%d : ",i,i);scanf("%d %d",&a[i][0],&a[i][1]);}
a[n][0]=a[0][0];a[n][1]=a[0][1];
printf("\n\n\tEnter the seed pt. : ");scanf("%d%d",&x,&y);
22/02/12 17:24C Programming
Página 42 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 7:43 AM
cleardevice();setcolor(WHITE);
for(i=0;i<n;i++) /*- draw poly -*/{line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);}
fill_right(x,y);fill_left(x-1,y);
getch();}
/*SAMPLE INPUT*//*Enter the number of edges of polygon 4
X0 Y0 = 50 50X1 Y1 = 200 50X2 Y2 = 200 300X3 Y3 = 50 300
Enter the seed point 100 100*/
Labels: Flood Fill Algorithm6 comments
C Program to implement Boundary Fill Algorithm
#include<stdio.h>#include<conio.h>#include<graphics.h>#include<dos.h>
void fill_right(x,y)int x , y ;{if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED)){putpixel(x,y,RED);fill_right(++x,y);x = x - 1 ;fill_right(x,y-1);fill_right(x,y+1);}delay(1);}
22/02/12 17:24C Programming
Página 43 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 7:24 AM
void fill_left(x,y)int x , y ;{if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED)){putpixel(x,y,RED);
fill_left(--x,y);x = x + 1 ;fill_left(x,y-1);fill_left(x,y+1);}delay(1);}
void main(){int x,y,n,i;int gd=DETECT,gm;clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
/*- draw object -*/
line (50,50,200,50);line (200,50,200,300);line (200,300,50,300);line (50,300,50,50);
/*- set seed point -*/x = 100; y = 100;
fill_right(x,y);fill_left(x-1,y);
getch();}
Labels: Boundary Fill Algorithm3 comments
S U N D A Y , M A Y 3 , 2 0 0 9
C Program for Bresenham Circle Drawing algorithm
# include<stdio.h>
# include<conio.h>
# include<graphics.h>
# include<math.h>
22/02/12 17:24C Programming
Página 44 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 11:53 AM
void main()
{
int gd=DETECT,gm;
int r,x,y,p,xc=320,yc=240;
initgraph(&gd,&gm,"C:\\TC\\BGI");
cleardevice();
printf("Enter the radius ");
scanf("%d",&r);
x=0;
y=r;
putpixel(xc+x,yc-y,1);
p=3-(2*r);
for(x=0;x<=y;x++)
{
if (p<0)
{
y=y;
p=(p+(4*x)+6);
}
else
{
y=y-1;
p=p+((4*(x-y)+10));
}
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,2);
putpixel(xc+x,yc+y,3);
putpixel(xc-x,yc+y,4);
putpixel(xc+y,yc-x,5);
putpixel(xc-y,yc-x,6);
putpixel(xc+y,yc+x,7);
putpixel(xc-y,yc+x,8);
}
getch();
closegraph();
}
Labels: Bresenham Circle Drawing algorithm10 comments
C Program for Bresenham line drawing algorithm
22/02/12 17:24C Programming
Página 45 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 10:45 AM
# include <stdio.h># include <conio.h># include <graphics.h>
void main(){int dx,dy,x,y,p,x1,y1,x2,y2;int gd,gm;
clrscr();
printf("\n\n\tEnter the co-ordinates of first point : ");scanf("%d %d",&x1,&y1);printf("\n\n\tEnter the co-ordinates of second point : ");scanf("%d %d",&x2,&y2);
dx = (x2 - x1);dy = (y2 - y1);
p = 2 * (dy) - (dx);
x = x1;y = y1;
detectgraph(&gd,&gm);initgraph(&gd,&gm,"e:\\tc\\bgi");putpixel(x,y,WHITE);
while(x <= x2){if(p < 0){x=x+1;y=y;p = p + 2 * (dy);}else{x=x+1;y=y+1;p = p + 2 * (dy - dx);}putpixel(x,y,WHITE);}getch();closegraph();
}
Labels: Bresenham line drawing algorithm12 comments
22/02/12 17:24C Programming
Página 46 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 1:50 AM
C Program for Character Generation
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,i,j;
int a[20][20]=
{{0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0}, {0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,0},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0},
{0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0},
{0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0},
{0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0}};
initgraph(&gd,&gm,"c:\\tc\\bgi");
for(i=0;i<19;i++)
{
for(j=0;j<19;j++)
{
if(a[i][j]==1)
putpixel(100+j,200+i,WHITE);
}
}
getch();
}
Labels: Character Generation0 comments
S A T U R D A Y , M A Y 2 , 2 0 0 9
C program to implement Digital DifferentialAnalyzer Line drawing algorithm
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int x1,x2,y1,y2,dx,dy,steps,k;
float xi,yi,x,y;
22/02/12 17:24C Programming
Página 47 de 47http://code-heaven.blogspot.com/search?updated-max=2019-09-19T04:32:00-07:00&max-results=400
Posted by Angad at 3:06 PM
Newer Posts
clrscr();
initgraph (&gd,&gm,"C:\\TC\\BGI");
printf("Enter the co-ordinates of the first point \n");
printf("x1= ");
scanf("%d/n",&x1);
printf("y1= ");
scanf("%d/n",&y1);
printf("Enter the co-ordinates of the second point \n");
printf("x2= ");
scanf("%d/n",&x2);
printf("y2= ");
scanf("%d/n",&y2);
clrscr();
dx= x2-x1;
dy= y2-y1;
if (abs(dx) > abs(dy))
steps = abs(dx);
else
steps = abs(dy);
xi=(float)dx/steps;
yi=(float)dy/steps;
x=x1;
y=y1;
for(k=0;k<steps;k++)
{
putpixel (x,y,BLUE);
x=x+xi;
y=y+yi;
}
getch();
closegraph();
}
Labels: Digital Differential Analyzer Line drawing algorithm2 comments
Home
Subscribe to: Posts (Atom)