Author Topic: Turbo C Graphics - Draw Circle with pixels  (Read 1098 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Turbo C Graphics - Draw Circle with pixels
« on: November 18, 2011, 03:18:32 pm »
Here is the Turbo C example on how to draw a circle with pixel by pixel.

The formula is: x = x + r cos (theta) and y = y + r sin (theta)

Code:
//Source Code Listing

#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <conio.h>
#include <bios.h>
#include <math.h>
 
void DrawCircle(int x, int y, int r, int color)
{
      static const double PI = 3.1415926535;
      double i, angle, x1, y1;
 
      for(i = 0; i < 360; i += 0.1)
      {
            angle = i;
            x1 = r * cos(angle * PI / 180);
            y1 = r * sin(angle * PI / 180);
            putpixel(x + x1, y + y1, color);
      }
}
 
void main()
{
      int grd, grm, i;
      int color, xmax, ymax;
      detectgraph(&grd,&grm);
      initgraph(&grd, &grm, "");
 
      color = GREEN;
      setbkcolor(BLUE);
 
      xmax = getmaxx();
      ymax = getmaxy();
 
      setcolor(WHITE);
      rectangle(0,0,xmax,ymax);
 
      for(i = 0; i < 230; i += 10)
      {
            DrawCircle(320, 240, i, color++);
            if(color > WHITE)
                  color = GREEN;
      }
      getch();
      closegraph();
}


 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1