include stdafx include Окружность эллипс void circle HDC hdc int x0 in

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
#include "stdafx.h"
#include "Окружность и эллипс.h"
void circle(HDC hdc, int x0, int y0, int R, COLORREF color)
{
int x=0;
int y=R;
int d=1-R;
int d1=3;
int d2=-2*R+5;
SetPixel(hdc, x0, y0+R, color);
SetPixel(hdc, x0, y0-R, color);
SetPixel(hdc, x0+R, y0, color);
SetPixel(hdc, x0-R, y0, color);
while (x<y)
{
if (d<0)
{
d=d+d1;
d1=d1+2;
d2=d2+2;
x++;
}
else
{
d=d+d2;
d2=d2+4;
d1=d1+2;
x++;
y--;
}
SetPixel(hdc,x0+x,y0+y,color);
SetPixel(hdc,x0+y,y0+x,color);
SetPixel(hdc,x0-x,y0+y,color);
SetPixel(hdc,x0-y,y0+x,color);
SetPixel(hdc,x0+x,y0-y,color);
SetPixel(hdc,x0+y,y0-x,color);
SetPixel(hdc,x0-x,y0-y,color);
SetPixel(hdc,x0-y,y0-x,color);
}
}
void ellipse(HDC hdc, int x0, int y0, int a, int b, COLORREF color)
{
if (a == b) circle(hdc, x0, y0, a, color);
int x=0;
int y=b;
int d=4*b*b+a*a*(1-4*b);
int d1=12*b*b;
int d2=12*b*b+8*a*a-8*a*a*b;
SetPixel(hdc, x0, y0+b, color);
SetPixel(hdc, x0, y0-b, color);
while (a*a*y > b*b*x)
{
if (d<0)
{
d=d+d1;
d1=d1+8*b*b;
d2=d2+8*b*b;
x++;
}
else
{
d=d+d2;
d1=d1+8*b*b;
d2=d2+8*(b*b+a*a);
x++;
y--;
}
SetPixel(hdc, x0+x, y0+y, color);
SetPixel(hdc, x0+x, y0-y, color);
SetPixel(hdc, x0-x, y0-y, color);
SetPixel(hdc, x0-x, y0+y, color);
}
d1=8*b*b*(1+x)+4*a*a*(3-2*y);
d2=4*a*a*(3-2*y);
while (y>=0)
{
if(d<0)
{
d=d+d1;
d1=d1+8*a*a;
d2=d2+8*a*a;
y--;
x++;
}
else
{
d=d+d2;
d1=d1+8*(a*a+b*b);
d2=d2+8*a*a;
y--;
}
SetPixel(hdc, x0+x, y0+y, color);
SetPixel(hdc, x0+x, y0-y, color);
SetPixel(hdc, x0-x, y0-y, color);
SetPixel(hdc, x0-x, y0+y, color);
}
}