Acasa Tehnologie Desenare cerc si poligon in C

Desenare cerc si poligon in C

by Dragos Schiopu

>Desenare cerc si poligon in C, marire/micsorare si mutare.

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
#include <dos.h>
int pi=M_PI;

int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax,y,x,raza,poly[20],a,b,cemut,ind;
char ch;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %sn", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
xmax = getmaxx(); ymax = getmaxy();
/*
for(int i=0;i<=xmax/2;i++)
{
outtextxy(0,0,"Resizing a circle");
circle(xmax/2,ymax/2,i);
delay(10);
cleardevice();
}

for(i=-220;i<=xmax+220;i++)
{
outtextxy(0,0,"Moving a circle on X axes");
circle(i,ymax/2,200);
delay(3);
cleardevice();
}
for(i=-220;i<=xmax+220;i++)
{
outtextxy(0,0,"Moving a circle on Y axes");
setfillstyle(SOLID_FILL,5);
circle(xmax/2,i,200);
delay(3);
cleardevice();
}
*/
x=xmax/2; y=ymax/2; raza=200;
a=0;b=0; cemut=1; ind=1;
do
{
//50,52,54,56.58
ch=getch();
cleardevice();
//cout<<ch;
if(ch=='c') cemut=1;
if(ch=='d') cemut=2;
if(ch=='a') cemut=3;
if(ch=='v') ind++;
if(ch=='b') ind--;
if(ch=='P') { y=y+ind; b=b+ind;} //in jos
if(ch=='H') { y=y-ind; b=b-ind;} // in sus
if(ch=='M') { x=x+ind; a=a+ind;} // drepta
if(ch=='K') { x=x-ind; a=a-ind;} // stanga
if(ch=='+') raza++;
if(ch=='-') raza--;
if(cemut==1 || cemut==3) circle(x,y,raza);
//drawpoly(4,xmax/4,ymax/4,3*xmax/4,3*ymax/4);
poly[0] = xmax/4+a; /* 1st vertext */
poly[1] = ymax/4+b;

poly[2] = 3*xmax/4+a; /* 2nd */
poly[3] = ymax/4+b;

poly[4] = 3*xmax/4+a; /* 3rd */
poly[5] = 3*ymax/4+b;

poly[6] = xmax/4+a; /* 4th */
poly[7] = 3*ymax/4+b;
/*
drawpoly doesn't automatically close
the polygon, so we close it.
*/
poly[8] = poly[0];
poly[9] = poly[1];

/* draw the polygon */
if(cemut==2 || cemut==3) drawpoly(5, poly);
}
while(ch!=27);
getch();
closegraph();
clrscr();
return 0;
}

s-ar putea sa-ti placa