Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 23 / Pentagon
.cpp// Copyright (C) 1991 - 1999 Rational Software Corporation
#include "stdafx.h"
#include "Pentagon.h"
#include <iostream.h>
#include <math.h>
#include "OurConstants.h"
//##ModelId=47092D650177
Pentagon::Pentagon(CPoint center, int size, COLORREF aColor):
ID(++count_ID)
{
// TODO: Add your specialized code here.
this->centerPoint = center;
this->size=size;
// TODO: Add your specialized code here.
color = aColor;
pen = DEFAULT_PEN;
CPoint p1(
(int)(centerPoint.x - size*cos(PI/10) - GAP),
(int)(centerPoint.y - size*cos(PI/5) - GAP)
);
CPoint p2(
(int)(centerPoint.x + size*cos(PI/10) + GAP),
(int)(centerPoint.y + size + GAP)
);
boundRect = CRect(p1,p2);
boundRect.NormalizeRect();
}
//##ModelId=470A152E01C5
Pentagon::~Pentagon()
{
// TODO: Add your specialized code here.
cout << "Destructor: Pentagon object ID: " << ID << endl;
}
//##ModelId=472F355503A9
double Pentagon::area() {
return 5*size*size*sin(2*PI/10)*sin(3*PI/10);
}
//##ModelId=472F355503D8
void Pentagon::move(CSize& size) {
centerPoint+=size;
boundRect+=size;
}
//##ModelId=470A2862001F
long Pentagon::count_ID = 0;
//##ModelId=470A27EF034B
void Pentagon::draw(CDC* pDC, COLORREF color, int pen=0)
{
// TODO: Add your specialized code here.
// Create a pen for this object and
// initialize it to the object color and line width of 1 pixel
CPen aPen;
COLORREF aColor = color; // Initialize with element color
if(!pen) pen = DEFAULT_PEN;
if(!aPen.CreatePen(PS_SOLID, pen, aColor))
{
// Pen creation failed. Abort the program.
AfxMessageBox("Pen creation failed drawing a line", MB_OK);
AfxAbort();
}
CPen* pOldPen = pDC->SelectObject(&aPen); // Select the pen
CPoint p1(
(int)(centerPoint.x-size*sin(PI/5)),
(int)(centerPoint.y-size*cos(PI/5))
);
CPoint p2(
(int)(centerPoint.x-size*cos(PI/10)),
(int)(centerPoint.y+size*sin(PI/10))
);
CPoint p3(
(int)(centerPoint.x),
(int)(centerPoint.y+size)
);
CPoint p4(
(int)(centerPoint.x+size*cos(PI/10)),
(int)(centerPoint.y+size*sin(PI/10))
);
CPoint p5(
(int)(centerPoint.x+size*sin(PI/5)),
(int)(centerPoint.y-size*cos(PI/5))
);
// Now draw the pentagon
pDC->MoveTo(p1);
pDC->LineTo(p2);
pDC->MoveTo(p2);
pDC->LineTo(p3);
pDC->MoveTo(p3);
pDC->LineTo(p4);
pDC->MoveTo(p4);
pDC->LineTo(p5);
pDC->MoveTo(p5);
pDC->LineTo(p1);
//
pDC->SelectObject(pOldPen); // Restore the old pen
}
int Pentagon::getSize() const
{
return this->size;
}
Соседние файлы в папке Лабораторная работа 23