Skip to main content

First Graphic program in C

Current semester i have a Computer Graphics as a subject.
Here is my first program that implements the
bresenham's circle drawing algorithm to draw a circle
and with some lines i created a smiley : )

#include "stdio.h"
#include "graphics.h"

void brecircle(xc,yc,r)
{

int x,y,p;
x=0;
y=r;
putpixel(xc+x,yc-y,1);

p=3-(2*r);

for(x=0;x<=y;x++)
{
if (p<0)
{
y=y;
p=(p+(4*x)+6);
}
else
{
y=y-1;

p=p+((4*(x-y)+10));
}

putpixel(xc+x,yc-y,15);
putpixel(xc-x,yc-y,15);
putpixel(xc+x,yc+y,15);
putpixel(xc-x,yc+y,15);
putpixel(xc+y,yc-x,15);
putpixel(xc-y,yc-x,15);
putpixel(xc+y,yc+x,15);
putpixel(xc-y,yc+x,15);
}
}

int main() {
  int x,y;
  int gd = DETECT, gm=0;
  initgraph(&gd,&gm,"");
  x=getmaxx()/2;
  y=getmaxy()/2;
  brecircle(x,y,150);
  brecircle(x-50,y-50,19);
  brecircle(x+50,y-50,19);
  line(x,y,x+20,y+20);
  line(x,y,x-20,y+20);
  line(x-20,y+20,x+20,y+20);
  line(x-40,y+50,x+40,y+50);
  getch();
  closegraph();
  return 0;
}

output:

Comments

Post a Comment