Untitled

 avatar
unknown
plain_text
a year ago
1.1 kB
15
Indexable
#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <stdio.h>
#include <dos.h>

void plot8(int xc,int yc,int x,int y,int c){
    int px[8]={ xc+x,xc-x,xc+x,xc-x, xc+y,xc-y,xc+y,xc-y };
    int py[8]={ yc+y,yc+y,yc-y,yc-y, yc+x,yc+x,yc-x,yc-x };
    for(int i=0;i<8;i++){ putpixel(px[i],py[i],c); delay(15); }
}

int main(){
    int xc,yc,r; clrscr();
    cout<<"Midpoint Circle (Turbo C++)\n";
    cout<<"Center xc yc: "; cin>>xc>>yc;
    cout<<"Radius r: ";     cin>>r;

    int gd=DETECT,gm;
    initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");  // adjust if needed

    int x=0, y=r, d=1-r; char buf[64];
    setcolor(WHITE);

    while(x<=y){
        plot8(xc,yc,x,y,WHITE);
        setcolor(LIGHTCYAN);
        sprintf(buf,"x=%d y=%d d=%d   ",x,y,d);
        outtextxy(10,10,buf);              // live step info

        if(d<0) d += (2*x+3);
        else    { d += (2*(x-y)+5); y--; }
        x++;
    }

    setcolor(YELLOW);
    outtextxy(10,30,"Done. Press any key...");
    getch(); closegraph(); return 0;
}
Editor is loading...
Leave a Comment