Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <graphics.h>
- #include <math.h>
- void startgraphics(){
- int gd = DETECT, gm;
- initgraph(&gd, &gm, "");
- cleardevice();
- }
- void dda(int a, int b, int r){
- int n, count = 0;
- float x = 0, y = r, e;
- for(n=1; ; n++)
- if(pow(2, n-1) <= r && r < pow(2, n)) break;
- e = pow(2, -n);
- do{
- x+=e*y;
- y-=e*x;
- putpixel((int)x+a, (int)y+b, 3);
- }while(count++<r*10); //while(y-sy < e || sx-x > e) gives infinite loop
- }
- void bres(int a, int b, int r){
- int x = 0, y = r, d = 3-2*r;
- do{
- putpixel(x+a, y+b, 3);
- putpixel(-x+a, y+b, 3);
- putpixel(x+a, -y+b, 3);
- putpixel(-x+a, -y+b, 3);
- putpixel(y+a, x+b, 3);
- putpixel(-y+a, x+b, 3);
- putpixel(y+a, -x+b, 3);
- putpixel(-y+a, -x+b, 3);
- if(d < 0) d+=4*x+6;
- else {d+= 4*(x-y)+10; y--;}
- x++;
- } while(x < y);
- }
- void mid(int a, int b, int r){
- int x = 0, y = r;
- float d = 1.25 - r;
- do{
- putpixel(x+a, y+b, 3);
- putpixel(-x+a, y+b, 3);
- putpixel(x+a, -y+b, 3);
- putpixel(-x+a, -y+b, 3);
- putpixel(y+a, x+b, 3);
- putpixel(-y+a, x+b, 3);
- putpixel(y+a, -x+b, 3);
- putpixel(-y+a, -x+b, 3);
- if(d<0){x++; d+=2*x+1;}
- else{x++; y--; d+=2*(x-y)+1;}
- }while(x < y);
- }
- void main(){
- startgraphics();
- dda(getmaxx()/2, getmaxy()/2, 80);
- bres(getmaxx()/2, getmaxy()/2, 100);
- mid(getmaxx()/2, getmaxy()/2, 150);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement