#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void plotPoints(int cx1, int cy1, int x1, int y1)
{
putpixel(cx1+x1, cy1+y1, RED);
putpixel(cx1-x1, cy1+y1, RED);
putpixel(cx1+x1, cy1-y1, RED);
putpixel(cx1-x1, cy1-y1, RED);
putpixel(cx1+y1, cy1+x1, RED);
putpixel(cx1-y1, cy1+x1, RED);
putpixel(cx1+y1, cy1-x1, RED);
putpixel(cx1-y1, cy1-x1, RED);
}
void plotPoints1(int cx2, int cy2, int x2, int y2)
{
putpixel(cx2-x2, cy2+y2, RED);
putpixel(cx2+x2, cy2-y2, RED);
putpixel(cx2+y2, cy2+x2, RED);
putpixel(cx2-y2, cy2-x2, RED);
}
void main()
{
int cx1,cy1,r1,cx2,cy2,r2;
int x1 = 0,y1,p1;
int x2 = 0,y2,p2;
int gd = DETECT, gm;
clrscr();
initgraph(&gd, &gm, "c:\\tc\\bgi");
cleardevice();
printf("Enter the coordinates of centre of the outer circle: ");
scanf("%d %d", &cx1, &cy1);
printf("Enter radius of Outer : ");
scanf("%d", &r1);
printf("Enter the coordinates of centre of the Inner circle: ");
scanf("%d %d", &cx2, &cy2);
printf("Enter radius of Inner : ");
scanf("%d", &r2);
y1 = r1;
p1 = 3 - 2 * r1;
while (x1 < y1)
{
plotPoints(cx1, cy1, x1, y1);
x1++;
if (p1 < 0)
p1 = p1 + 4 * x1 + 6;
else
{
y1--;
p1 = p1 + 4 * (x1 - y1) + 10;
}
plotPoints(cx1, cy1, x1, y1);
delay(200);
}
y2 = r2;
p2 = 3 - 2 * r2;
while (x2 < y2)
{
plotPoints1(cx2, cy2, x2, y2);
x2++;
if (p2 < 0)
p2 = p2 + 4 * x2 + 6;
else
{
y2--;
p2 = p2 + 4 * (x2 - y2) + 10;
}
plotPoints1(cx2, cy2, x2, y2);
delay(200);
}
getch();
}
Output :-
#include<conio.h>
#include<graphics.h>
void plotPoints(int cx1, int cy1, int x1, int y1)
{
putpixel(cx1+x1, cy1+y1, RED);
putpixel(cx1-x1, cy1+y1, RED);
putpixel(cx1+x1, cy1-y1, RED);
putpixel(cx1-x1, cy1-y1, RED);
putpixel(cx1+y1, cy1+x1, RED);
putpixel(cx1-y1, cy1+x1, RED);
putpixel(cx1+y1, cy1-x1, RED);
putpixel(cx1-y1, cy1-x1, RED);
}
void plotPoints1(int cx2, int cy2, int x2, int y2)
{
putpixel(cx2-x2, cy2+y2, RED);
putpixel(cx2+x2, cy2-y2, RED);
putpixel(cx2+y2, cy2+x2, RED);
putpixel(cx2-y2, cy2-x2, RED);
}
void main()
{
int cx1,cy1,r1,cx2,cy2,r2;
int x1 = 0,y1,p1;
int x2 = 0,y2,p2;
int gd = DETECT, gm;
clrscr();
initgraph(&gd, &gm, "c:\\tc\\bgi");
cleardevice();
printf("Enter the coordinates of centre of the outer circle: ");
scanf("%d %d", &cx1, &cy1);
printf("Enter radius of Outer : ");
scanf("%d", &r1);
printf("Enter the coordinates of centre of the Inner circle: ");
scanf("%d %d", &cx2, &cy2);
printf("Enter radius of Inner : ");
scanf("%d", &r2);
y1 = r1;
p1 = 3 - 2 * r1;
while (x1 < y1)
{
plotPoints(cx1, cy1, x1, y1);
x1++;
if (p1 < 0)
p1 = p1 + 4 * x1 + 6;
else
{
y1--;
p1 = p1 + 4 * (x1 - y1) + 10;
}
plotPoints(cx1, cy1, x1, y1);
delay(200);
}
y2 = r2;
p2 = 3 - 2 * r2;
while (x2 < y2)
{
plotPoints1(cx2, cy2, x2, y2);
x2++;
if (p2 < 0)
p2 = p2 + 4 * x2 + 6;
else
{
y2--;
p2 = p2 + 4 * (x2 - y2) + 10;
}
plotPoints1(cx2, cy2, x2, y2);
delay(200);
}
getch();
}
Output :-
No comments:
Post a Comment