Vous êtes sur la page 1sur 6

#include <graphics.

h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<dos.h>
void cyrus();
void ppm1(int,int,int,int,int,int,int,int,int,int);
void ppm2(int,int,int,int,int,int,int,int,int,int);
void main()
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
clrscr();
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
printf("Enter 1 for cyrus beck\n2 for mid point");
fflush(stdin);
cyrus();
/* clean up */
getch();
closegraph();
}
void cyrus()
{
int xmax, ymax;
int left,i ,right,top,bottom,x,y,x1,y1,x6,y6,x2,x3,y2,y3,a;
int x4,x5,y4,y5,x2s,y2s,x3s,y3s;
float tb,tr,tt,tl,max,min;
clrscr();
x=50;y=70;x1=90;y1=100;x6=130;y6=20;
setcolor(getmaxcolor());
xmax = getmaxx();
ymax = getmaxy();
line(0,ymax/2,xmax,ymax/2);
line(xmax/2,0,xmax/2,ymax);
line(xmax/2+x,ymax/2-y,xmax/2+x1,ymax/2-y1);

line(xmax/2+x1,ymax/2-y1,xmax/2+x6,ymax/2-y6);
line(xmax/2+x6,ymax/2-y6,xmax/2+x,ymax/2-y);
printf("Enter the value of a for different line");
scanf("%d",&a);

x2=30,y2=90,x3=150,y3=50;
setcolor(RED);
line(xmax/2+x2,ymax/2-y2,xmax/2+x3,ymax/2-y3);
x2s=57,y2s=80,x3s=110,y3s=64;
tl= 80*(x1-x2)/((float)(x3-x2))+40*(y1-y2)/((float)(y3-y2));
tr=40*(x2-x1)/((float)(x2-x3))+80*(y2-y3)/((float)(y-y2));
tb=40*(x2-x1)+((float)(x2-x3)) /(y2-y)/((float)(y2-y3));
if(tl>0&&tl>tb)
max=tl;
else if(tb>tl&&tb>0)
max=tb;
else
max=0;
if(tt<1&&tt<tr)
min=tt;
else if(tr<tt&&tr<1)
min=tr;
else
min=1;
x4=(float)x2+((x3-x2)*max);
y4=(float)y2+((y3-y2)*max);
x5=(float)x2+((x3-x2)*min);
y5=(float)y2+((y3-y2)*min);
setcolor(GREEN);
line(xmax/2+x2s,ymax/2-y2s,xmax/2+x3s,ymax/2-y3s);
getch();
}

/*
void mid()
{
int xmax, ymax;
int left,i ,right,top,bottom,x,y,x1,y1,x2,y2,x3,y3,mx,my;
int c[4],c1[4],c2[4];
clrscr();
setcolor(getmaxcolor());
xmax = getmaxx();
ymax = getmaxy();

line(0,ymax/2,xmax,ymax/2);
line(xmax/2,0,xmax/2,ymax);
printf("Enter the points of rectangle left,top,right,bottom");
fflush(stdin);
scanf("%d%d%d%d",&x,&y,&x1,&y1);
left=(xmax/2+x);
top=(ymax/2-y);
right=(xmax/2+x1);
bottom=(ymax/2-y1);
rectangle(left,top,right,bottom);
printf("Enter the points of line");
fflush(stdin);
scanf("%d%d%d%d",&x2,&y2,&x3,&y3);
line(xmax/2+x2,ymax/2-y2,xmax/2+x3,ymax/2-y3);
if(x2<x)
c[0]=1;
else
c[0]=0;
if(x2>x1)
c[1]=1;
else
c[1]=0;
if(y2>y)
c[2]=1;
else
c[2]=0;
if(y2<y1)
c[3]=1;
else
c[3]=0;
if(x3<x)
c1[0]=1;
else
c1[0]=0;
if(x3>x1)
c1[1]=1;
else
c1[1]=0;
if(y3>y)
c1[2]=1;
else
c1[2]=0;
if(y3<y1)
c1[3]=1;
else
c1[3]=0;
second:
if(((c[0]|c1[0])||(c[1]|c1[1])||(c[2]|c1[2])||(c[3]|c1[3]))==0)
{
setcolor(RED);
line(xmax/2+x2,ymax/2-y2,xmax/2+x3,ymax/2-y3);

}
if(((c[0]&c1[0])||(c[1]&c1[1])||(c[2]&c1[2])||(c[3]&c1[3]))!=0)
{
setcolor(15);
line(xmax/2+x2,ymax/2-y2,xmax/2+x3,ymax/2-y3);
}
mx=(x2+x3)/2;
my=(y2+y3)/2;
if(mx<x)
c2[0]=1;
else
c2[0]=0;
if(mx>x1)
c2[1]=1;
else
c2[1]=0;
if(my>y)
c2[2]=1;
else
c2[2]=0;
if(my<y1)
c2[3]=1;
else
c2[3]=0;
if(((c2[0]|c2[1])|(c2[2]|c2[3]))==0)
{
if((((c[0]|c2[0])||(c[1]|c2[1]))||((c[2]|c2[2])||(c[3]|c2[3])))==0)
{
setcolor(RED);
line(xmax/2+x2,ymax/2-y2,xmax/2+mx,ymax/2-my);
}
else
ppm1(xmax,ymax,x,y,x1,y1,x2,y2,mx,my);
if((((c1[0]|c2[0])||(c1[1]|c2[1]))||((c1[2]|c2[2])||(c1[3]|c2[3])))==0)
{
setcolor(RED);
line(xmax/2+mx,ymax/2-my,xmax/2+x3,ymax/2-y3);
}
else
ppm2(xmax,ymax,x,y,x1,y1,x3,y3,mx,my);
}
else if(((c2[0]|c2[1])|(c2[2]|c2[3]))!=0)
{
if(((c[0]|c[1])|(c[2]|c[3]))!=0)
{
x2=mx;
y2=my;
goto second;
}

if(((c1[0]|c1[1])|(c1[2]|c1[3]))!=0)
{
x3=mx;
y3=my;
goto second;
}
}
getch();
}
void ppm1(int xmax,int ymax,int x,int y,int x1,int y1,int x2,int y2,int mx,int m
y)
{
int c2[4];
int mx1,my1,mx2,my2;
mx2=mx;
my2=my;
do
{
mx1=(mx+x2)/2;
my1=(my+y2)/2;
if(mx1<x)
c2[0]=1;
else
c2[0]=0;
if(mx1>x1)
c2[1]=1;
else
c2[1]=0;
if(my1>y)
c2[2]=1;
else
c2[2]=0;
if(my1<y1)
c2[3]=1;
else
c2[3]=0;
if(((c2[0]|c2[1])|(c2[2]|c2[3]))!=0)
{
x2=mx1;
y2=my1;
}
else
{
mx=mx1;
my=my1;
}
}while(((mx!=x&&mx!=x1)&&(my!=y&&my!=y1)));
setcolor(RED);
line(xmax/2+mx2,ymax/2-my2,xmax/2+mx,ymax/2-my);
getch();
}

void ppm2(int xmax,int ymax,int x,int y,int x1,int y1,int x3,int y3,int mx,int m
y)
{
int c3[4];
int mx1,my1,mx2,my2;
my2=my;
mx2=mx;
do
{
mx1=(mx+x3)/2;
my1=(my+y3)/2;
if(mx1<x)
c3[0]=1;
else
c3[0]=0;
if(mx1>x1)
c3[1]=1;
else
c3[1]=0;
if(my1>y)
c3[2]=1;
else
c3[2]=0;
if(my1<y1)
c3[3]=1;
else
c3[3]=0;
if(((c3[0]|c3[1])||(c3[2]|c3[3]))!=0)
{
x3=mx1;
y3=my1;
}
else
{
mx=mx1;
my=my1;
}
}while(((mx!=x&&mx!=x1)&&(my!=y&&my!=y1)));
setcolor(RED);
line(xmax/2+mx2,ymax/2-my2,xmax/2+mx,ymax/2-my);
getch();
}
*/

Vous aimerez peut-être aussi