506 lines
14 KiB
C++
506 lines
14 KiB
C++
#include "Paint.h"
|
||
|
||
#define SIN(x) sin(M_PI*x/180)
|
||
#define COS(x) cos(M_PI*x/180)
|
||
#define ATAN(y,x) atan2f(y,x)/M_PI*180
|
||
|
||
void paint_figures(HDC hdc) {
|
||
int defaultxy = 20;
|
||
|
||
int x1, y1;
|
||
int x2, y2;
|
||
|
||
x1 = defaultxy, y1 = defaultxy;
|
||
x2 = defaultxy, y2 = defaultxy + 300;
|
||
|
||
do {
|
||
MoveToEx(hdc, x1, y1, NULL);
|
||
LineTo(hdc, x2, y2);
|
||
y1 += 10;
|
||
x2 += 10;
|
||
} while (y1 <= defaultxy + 300);
|
||
|
||
x1 = 2 * defaultxy + 300, y1 = defaultxy;
|
||
x2 = 2 * defaultxy + 300, y2 = defaultxy + 300;
|
||
|
||
do {
|
||
MoveToEx(hdc, x1, y1, NULL);
|
||
LineTo(hdc, x2, y2);
|
||
x1 += 10;
|
||
x2 += 10;
|
||
y1 += 10;
|
||
y2 -= 10;
|
||
} while (x1 <= 2 * defaultxy + 2 * 300);
|
||
|
||
|
||
x1 = defaultxy, y1 = 2 * defaultxy + 300;
|
||
x2 = defaultxy, y2 = 2 * defaultxy + 2 * 300;
|
||
int r = 255, g = 0, b = 0;
|
||
int i = 1;
|
||
HPEN hPen;
|
||
|
||
do {
|
||
hPen = CreatePen(PS_SOLID, 1, RGB(r, g, b));
|
||
SelectObject(hdc, hPen);
|
||
MoveToEx(hdc, x1, y1, NULL);
|
||
LineTo(hdc, x2, y2);
|
||
DeleteObject(hPen);
|
||
x1 += 10;
|
||
x2 += 10;
|
||
y1 += 1;
|
||
y2 -= 1;
|
||
switch (i % 7) {
|
||
case 0:
|
||
r = 255, g = 0, b = 0;
|
||
break;
|
||
case 1:
|
||
r = 255, g = 165, b = 0;
|
||
break;
|
||
case 2:
|
||
r = 255, g = 255, b = 0;
|
||
break;
|
||
case 3:
|
||
r = 128, g = 255, b = 0;
|
||
break;
|
||
case 4:
|
||
r = 0, g = 191, b = 255;
|
||
break;
|
||
case 5:
|
||
r = 0, g = 0, b = 255;
|
||
break;
|
||
case 6:
|
||
r = 139, g = 0, b = 255;
|
||
break;
|
||
}
|
||
i++;
|
||
} while (x1 < defaultxy + 300);
|
||
|
||
SelectObject(hdc, GetStockObject(DC_PEN));
|
||
|
||
x1 = 2 * defaultxy + 300, y1 = 2 * defaultxy + 300;
|
||
x2 = 2 * defaultxy + 300, y2 = 2 * defaultxy + 2 * 300;
|
||
|
||
r = 255, g = 0, b = 0;
|
||
i = 1;
|
||
|
||
do {
|
||
|
||
hPen = CreatePen(PS_SOLID, 1, RGB(r, g, b));
|
||
SelectObject(hdc, hPen);
|
||
MoveToEx(hdc, x1, y1, NULL);
|
||
LineTo(hdc, x2, y2);
|
||
DeleteObject(hPen);
|
||
|
||
MoveToEx(hdc, x1, y1, NULL);
|
||
LineTo(hdc, x2, y2);
|
||
DeleteObject(hPen);
|
||
x2 += 10;
|
||
y1 += 10;
|
||
y2 -= 10;
|
||
|
||
switch (i % 7) {
|
||
case 0:
|
||
r = 255, g = 0, b = 0;
|
||
break;
|
||
case 1:
|
||
r = 255, g = 165, b = 0;
|
||
break;
|
||
case 2:
|
||
r = 255, g = 255, b = 0;
|
||
break;
|
||
case 3:
|
||
r = 128, g = 255, b = 0;
|
||
break;
|
||
case 4:
|
||
r = 0, g = 191, b = 255;
|
||
break;
|
||
case 5:
|
||
r = 0, g = 0, b = 255;
|
||
break;
|
||
case 6:
|
||
r = 139, g = 0, b = 255;
|
||
break;
|
||
}
|
||
i++;
|
||
} while (y1 <= 2 * defaultxy + +2 * 300);
|
||
|
||
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
||
SelectObject(hdc, GetStockObject(DC_PEN));
|
||
}
|
||
|
||
void house(HDC hdc, int xstart, int ystart) {
|
||
HPEN HPen;
|
||
|
||
HPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 0));
|
||
SelectObject(hdc, HPen);
|
||
POINT pt[5];
|
||
pt[0] = { xstart + 150, ystart };
|
||
pt[1] = { xstart + 300, ystart + 100 };
|
||
pt[2] = { xstart + 300, ystart + 300 };
|
||
pt[3] = { xstart, ystart + 300 };
|
||
pt[4] = { xstart, ystart + 100 };
|
||
Polygon(hdc, pt, 5);
|
||
|
||
MoveToEx(hdc, pt[1].x, pt[1].y, NULL);
|
||
LineTo(hdc, pt[4].x, pt[4].y);
|
||
|
||
Rectangle(hdc, pt[4].x + 75, pt[4].y + 50, pt[2].x - 75, pt[2].y - 50);
|
||
|
||
MoveToEx(hdc, xstart + 150, ystart + 150, NULL);
|
||
LineTo(hdc, xstart + 150, ystart + 250);
|
||
|
||
MoveToEx(hdc, xstart + 150, ystart + 200, NULL);
|
||
LineTo(hdc, xstart + 225, ystart + 200);
|
||
|
||
DeleteObject(HPen);
|
||
SelectObject(hdc, GetStockObject(DC_PEN));
|
||
}
|
||
|
||
void oldhouse(HDC hdc) {
|
||
POINT pt[5];
|
||
pt[0].x = 250;
|
||
pt[0].y = 100;
|
||
pt[1].x = 400;
|
||
pt[1].y = 200;
|
||
pt[2].x = 400;
|
||
pt[2].y = 400;
|
||
pt[3].x = 100;
|
||
pt[3].y = 400;
|
||
pt[4].x = 100;
|
||
pt[4].y = 200;
|
||
|
||
MoveToEx(hdc, pt[0].x, pt[0].y, NULL);
|
||
for (int i = 1; i < 5; i++) {
|
||
LineTo(hdc, pt[i].x, pt[i].y);
|
||
}
|
||
LineTo(hdc, pt[0].x, pt[0].y);
|
||
|
||
MoveToEx(hdc, pt[1].x, pt[1].y, NULL);
|
||
LineTo(hdc, pt[4].x, pt[4].y);
|
||
|
||
int marginWindow = 56;
|
||
|
||
marginWindow = marginWindow % ((pt[1].y - pt[2].y) / 2);
|
||
|
||
POINT ptwindow[5];
|
||
ptwindow[0].x = pt[1].x - marginWindow;
|
||
ptwindow[0].y = pt[1].y + marginWindow;
|
||
ptwindow[1].x = pt[2].x - marginWindow;
|
||
ptwindow[1].y = pt[2].y - marginWindow;
|
||
ptwindow[2].x = pt[3].x + marginWindow;
|
||
ptwindow[2].y = pt[3].y - marginWindow;
|
||
ptwindow[3].x = pt[4].x + marginWindow;
|
||
ptwindow[3].y = pt[4].y + marginWindow;
|
||
ptwindow[4].x = pt[1].x - marginWindow;
|
||
ptwindow[4].y = pt[1].y + marginWindow;
|
||
|
||
Polyline(hdc, ptwindow, 5);
|
||
|
||
int centerx = pt[4].x + (pt[1].x - pt[4].x) / 2;
|
||
int centery = pt[1].y + (pt[2].y - pt[1].y) / 2;
|
||
|
||
MoveToEx(hdc, centerx, ptwindow[0].y, NULL);
|
||
LineTo(hdc, centerx, ptwindow[1].y);
|
||
|
||
MoveToEx(hdc, centerx, centery, NULL);
|
||
LineTo(hdc, ptwindow[0].x, centery);
|
||
}
|
||
|
||
void car(HDC hdc, int xstart, int ystart, COLORREF color) {
|
||
HBRUSH HBrush;
|
||
HBrush = CreateSolidBrush(color);
|
||
SelectObject(hdc, HBrush);
|
||
Rectangle(hdc, xstart, ystart + 50, xstart + 250, ystart + 100);
|
||
DeleteObject(HBrush);
|
||
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
||
|
||
HBrush = CreateHatchBrush(HS_DIAGCROSS, RGB(0, 0, 0));
|
||
SelectObject(hdc, HBrush);
|
||
Ellipse(hdc, xstart + 25, ystart + 75, xstart + 75, ystart + 125);
|
||
Ellipse(hdc, xstart + 175, ystart + 75, xstart + 225, ystart + 125);
|
||
DeleteObject(HBrush);
|
||
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
||
|
||
POINT pt[4];
|
||
pt[0] = { xstart + 50, ystart + 50 };
|
||
pt[1] = { xstart + 100, ystart };
|
||
pt[2] = { xstart + 200, ystart };
|
||
pt[3] = { xstart + 250, ystart + 50 };
|
||
Polyline(hdc, pt, 4);
|
||
|
||
MoveToEx(hdc, pt[1].x, pt[1].y, NULL);
|
||
LineTo(hdc, pt[1].x, pt[1].y + 50);
|
||
|
||
MoveToEx(hdc, pt[2].x, pt[2].y, NULL);
|
||
LineTo(hdc, pt[2].x, pt[2].y + 50);
|
||
}
|
||
|
||
void carD(HDC hdc, int xstart, int ystart) {
|
||
car(hdc, xstart, ystart, RGB(0, 255, 255));
|
||
|
||
}
|
||
|
||
void bush1(HDC hdc, int xstart, int ystart, COLORREF color) {
|
||
HPEN HPen;
|
||
HPen = CreatePen(PS_SOLID, 2, color);
|
||
SelectObject(hdc, HPen);
|
||
|
||
POINT end = { xstart - 75,ystart - 75 };
|
||
|
||
while (end.x <= xstart + 75) {
|
||
MoveToEx(hdc, xstart, ystart, NULL);
|
||
LineTo(hdc, end.x, end.y);
|
||
end.x += 15;
|
||
}
|
||
|
||
DeleteObject(HPen);
|
||
SelectObject(hdc, GetStockObject(DC_PEN));
|
||
}
|
||
|
||
void bush2(HDC hdc, int xstart, int ystart, COLORREF color) {
|
||
HPEN HPen;
|
||
HPen = CreatePen(PS_SOLID, 2, color);
|
||
SelectObject(hdc, HPen);
|
||
|
||
POINT end = { -100,0 };
|
||
|
||
while (end.x <= 0) {
|
||
MoveToEx(hdc, xstart, ystart, NULL);
|
||
LineTo(hdc, xstart + end.x, ystart - end.y);
|
||
end.x += 10;
|
||
end.y += 20;
|
||
}
|
||
|
||
end.x -= 10;
|
||
end.y -= 20;
|
||
|
||
while (end.x <= 100) {
|
||
MoveToEx(hdc, xstart, ystart, NULL);
|
||
LineTo(hdc, xstart + end.x, ystart - end.y);
|
||
end.x += 10;
|
||
end.y -= 20;
|
||
}
|
||
|
||
DeleteObject(HPen);
|
||
SelectObject(hdc, GetStockObject(DC_PEN));
|
||
|
||
DeleteObject(HPen);
|
||
SelectObject(hdc, GetStockObject(DC_PEN));
|
||
}
|
||
|
||
void christmasTree(HDC hdc, int xstart, int ystart) {
|
||
HBRUSH HBrush;
|
||
|
||
HBrush = CreateSolidBrush(RGB(0, 255, 0));
|
||
SelectObject(hdc, HBrush);
|
||
POINT pt[3];
|
||
pt[0] = { xstart + 50, ystart };
|
||
pt[1] = { xstart + 100, ystart + 50 };
|
||
pt[2] = { xstart, ystart + 50 };
|
||
|
||
int diff = 50;
|
||
Polygon(hdc, pt, 3);
|
||
for (int i = 0; i < 2; i++) {
|
||
for (int j = 0; j < 3; j++) {
|
||
pt[j].y += diff;
|
||
}
|
||
Polygon(hdc, pt, 3);
|
||
}
|
||
DeleteObject(HBrush);
|
||
|
||
HBrush = CreateSolidBrush(RGB(88, 57, 39));
|
||
SelectObject(hdc, HBrush);
|
||
Rectangle(hdc, pt[2].x + 37, pt[2].y, pt[1].x - 37, pt[1].y + 25);
|
||
DeleteObject(HBrush);
|
||
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
||
}
|
||
|
||
void tree(HDC hdc, int xstart, int ystart) {
|
||
HBRUSH HBrush;
|
||
|
||
HBrush = CreateSolidBrush(RGB(88, 57, 39));
|
||
SelectObject(hdc, HBrush);
|
||
Rectangle(hdc, xstart + 37, ystart + 115, xstart + 63, ystart + 200);
|
||
DeleteObject(HBrush);
|
||
|
||
HBrush = CreateSolidBrush(RGB(0, 255, 0));
|
||
SelectObject(hdc, HBrush);
|
||
Ellipse(hdc, xstart, ystart, xstart + 100, ystart + 125);
|
||
DeleteObject(HBrush);
|
||
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
||
}
|
||
|
||
void treeR(HDC hdc, int xstart, int ystart, int ang) {
|
||
HBRUSH HBrush;
|
||
|
||
HBrush = CreateSolidBrush(RGB(88, 57, 39));
|
||
SelectObject(hdc, HBrush);
|
||
POINT pt[4];
|
||
pt[0] = { xstart, ystart };
|
||
pt[1] = { (long)(xstart + (float)25 * COS(ang)), (long)(ystart + (float)25 * SIN(ang)) };
|
||
pt[2] = { (long)(xstart + (float)25 * COS(ang) - (float)85 * SIN(ang)), (long)(ystart + (float)85 * COS(ang) + (float)25 * SIN(ang)) };
|
||
pt[3] = { (long)(xstart - (float)85 * SIN(ang)), (long)(ystart + (float)85 * COS(ang)) };
|
||
|
||
Polygon(hdc, pt, 4);
|
||
DeleteObject(HBrush);
|
||
|
||
DeleteObject(HBrush);
|
||
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
||
}
|
||
|
||
void test(HDC hdc, int xcenter, int ycenter, int width, int heigth, int ang) {
|
||
|
||
float R1 = (float)(width / 2), R2 = (float)(heigth / 2);
|
||
|
||
float downX = (float)width * COS(ang) - (float)heigth * SIN(ang);
|
||
float downY = (float)heigth * COS(ang) + (float)width * SIN(ang);
|
||
|
||
|
||
POINT pt[4];
|
||
pt[0] = { (long)(xcenter - downX / 2), (long)(ycenter - downY / 2) };
|
||
pt[1] = { (long)(pt[0].x + (float)width * COS(ang)), (long)(pt[0].y + (float)width * SIN(ang)) };
|
||
pt[2] = { (long)(pt[0].x + downX), (long)(pt[0].y + downY) };
|
||
pt[3] = { (long)(pt[0].x - (float)heigth * SIN(ang)), (long)(pt[0].y + (float)heigth * COS(ang)) };
|
||
|
||
Polygon(hdc, pt, 4);
|
||
|
||
float shag = 5;
|
||
|
||
float i = 0;
|
||
|
||
while (i < 360) {
|
||
float x1, y1, L1, ang1, x2, y2, L2, ang2, res;
|
||
|
||
x1 = R1 + (float)(R1 * COS(i));
|
||
y1 = R2 - (float)(R2 * SIN(i));
|
||
#ifdef TEST
|
||
MoveToEx(hdc, (int)x1, (int)y1, NULL);
|
||
#endif
|
||
|
||
|
||
L1 = sqrt(pow(x1, 2) + pow(y1, 2));
|
||
ang1 = ATAN(y1, x1);
|
||
res = (ang1 + ang);
|
||
x1 = xcenter + L1 * COS(res) - downX / 2;
|
||
y1 = ycenter + L1 * SIN(res) - downY / 2;
|
||
|
||
i += shag;
|
||
|
||
if (i > 360) i = 360;
|
||
|
||
x2 = R1 + (float)(R1 * COS(i));
|
||
y2 = R2 - (float)(R2 * SIN(i));
|
||
#ifdef TEST
|
||
LineTo(hdc, (int)x2, (int)y2);
|
||
#endif
|
||
L2 = sqrt(pow(x2, 2) + pow(y2, 2));
|
||
ang2 = ATAN(y2, x2);
|
||
res = (ang2 + ang);
|
||
x2 = xcenter + L2 * COS(res) - downX / 2;
|
||
y2 = ycenter + L2 * SIN(res) - downY / 2;
|
||
MoveToEx(hdc, (int)x1, (int)y1, NULL);
|
||
LineTo(hdc, (int)x2, (int)y2);
|
||
}
|
||
|
||
MoveToEx(hdc, xcenter, ycenter + heigth, NULL);
|
||
LineTo(hdc, xcenter, ycenter - heigth);
|
||
|
||
MoveToEx(hdc, xcenter + width, ycenter, NULL);
|
||
LineTo(hdc, xcenter - width, ycenter);
|
||
}
|
||
|
||
void sun(HDC hdc, int xcenter, int ycenter) {
|
||
HBRUSH HBrush;
|
||
HPEN HPen;
|
||
|
||
HBrush = CreateSolidBrush(RGB(255, 255, 0));
|
||
HPen = CreatePen(PS_SOLID, 2, RGB(255, 255, 0));
|
||
SelectObject(hdc, HBrush);
|
||
SelectObject(hdc, HPen);
|
||
Ellipse(hdc, xcenter - 50, ycenter - 50, xcenter + 50, ycenter + 50);
|
||
|
||
|
||
int margin = 60;
|
||
int length = 100;
|
||
int n = 14.88;
|
||
float shag = (float)90 / (n - 1);
|
||
|
||
for (float i = 0; i < 360; i += shag) {
|
||
double alph = i / 180 * M_PI;
|
||
double S = sin(alph);
|
||
double C = cos(alph);
|
||
int ystart = margin * S,
|
||
yend = ystart + length * S,
|
||
xstart = margin * C,
|
||
xend = xstart + length * C;
|
||
|
||
MoveToEx(hdc, xcenter - xstart, ycenter + ystart, NULL);
|
||
LineTo(hdc, xcenter - xend, ycenter + yend);
|
||
}
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
|
||
//margin = 360, length = 100;
|
||
|
||
//for (double i = 0; i < 360; i += 10) {
|
||
// double alph = (double)i / 180 * M_PI;
|
||
// double S = sin(alph) / 4;
|
||
// double C = cos(alph) / 5;
|
||
// int ystart = margin * S,
|
||
// yend = ystart + length * 5 * S,
|
||
// xstart = margin * C,
|
||
// xend = (xstart + length * 4 * C);
|
||
|
||
// MoveToEx(hdc, 400 - xstart, 400 + ystart, NULL);
|
||
// LineTo(hdc, 400 - xend, 400 + yend);
|
||
//}
|
||
|
||
//margin = sqrt(60), length = 10;
|
||
|
||
//for (double i = 0; i < 360; i += 10) {
|
||
// double alph = (double)i / 180 * M_PI;
|
||
// double S = sin(alph);
|
||
// double C = cos(alph);
|
||
// double ystart = margin * S * 5,
|
||
// yend = ystart + length * S * 5,
|
||
// xstart = margin * C * 4,
|
||
// xend = xstart + length * C * 4;
|
||
|
||
// MoveToEx(hdc, 400 - (int)xstart, 400 + (int)ystart, NULL);
|
||
// LineTo(hdc, 400 - (int)xend, 400 + (int)yend);
|
||
//}
|
||
|
||
//int R = 360;
|
||
|
||
//for (double i = 0; i < 360; i += .1) {
|
||
// double alph = (double)i / 180 * M_PI;
|
||
// double S = sin(alph) / 4;
|
||
// double C = cos(alph) / 5;
|
||
|
||
// double alph1 = (double)(i + 0.1) / 180 * M_PI;
|
||
// double S1 = sin(alph1) / 4;
|
||
// double C1 = cos(alph1) / 5;
|
||
|
||
// int ystart = (R * S),
|
||
// yend = (R * S1),
|
||
// xstart = (R * C),
|
||
// xend = (R * C1);
|
||
|
||
// MoveToEx(hdc, 400 - xstart, 400 + ystart, NULL);
|
||
// LineTo(hdc, 400 - xend, 400 + yend);
|
||
|
||
// ystart = (R+500) * S,
|
||
// yend = (R+500) * S1,
|
||
// xstart = (R+400) * C,
|
||
// xend = (R+400) * C1;
|
||
|
||
// MoveToEx(hdc, 400 - xstart, 400 + ystart, NULL);
|
||
// LineTo(hdc, 400 - xend, 400 + yend);
|
||
//}
|
||
|
||
DeleteObject(HBrush);
|
||
DeleteObject(HPen);
|
||
|
||
SelectObject(hdc, GetStockObject(DC_BRUSH));
|
||
SelectObject(hdc, GetStockObject(DC_PEN));
|
||
} |