⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 triangleshape.cpp

📁 一个漂亮的万花筒游戏
💻 CPP
字号:
// TriangleShape.cpp: implementation of the TriangleShape class.
//
//////////////////////////////////////////////////////////////////////
#include <assert.h>
#include "ezwin.h"
#include "math.h"
#include "WindowObject.h"
#include "Shape.h"
#include "TriangleShape.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

TriangleShape::TriangleShape(SimpleWindow &Window,
 const Position &p, const color &c,
 float l) : Shape(Window, p, c), SideLength(l) {
	// No body needed
}

float TriangleShape::GetSideLength() const {
	return SideLength;
}

void TriangleShape::Draw() {
	const float Pi = 3.1416f;

	const Position Center = GetPosition();
	const float SLength = GetSideLength();

	float c = SLength / (2.0f * cos(30.0f * Pi / 180.0f));
	float a = tan(30.0f * Pi / 180.0f) * .5f * SLength;

	vector<Position> TrianglePoints(3);
	TrianglePoints[0] =
	 Center + Position(0.0f, -c);
	TrianglePoints[1] = Center
	 + Position(-.5f * SideLength, a);
	TrianglePoints[2] = Center
	 + Position(.5f * SideLength, a);

	
	GetWindow().RenderPolygon(TrianglePoints, 3,
	 GetColor(), HasBorder());
	return;
}

void TriangleShape::SetSize(float l) {
	SideLength = l;
	return;
}

void TriangleShape::Erase() {
	const float Pi = 3.1416f;

	const Position Center = GetPosition();
	const float SLength = GetSideLength();

	float c = SLength / (2.0f * cos(30.0f * Pi / 180.0f));
	float a = tan(30.0f * Pi / 180.0f) * .5f * SLength;

	vector<Position> TrianglePoints(3);
   TrianglePoints[0] =
	 Center + Position(0.0f, -c);
   TrianglePoints[1] = Center
    + Position(-.5f * SideLength, a);
   TrianglePoints[2] = Center
    + Position(.5f * SideLength, a);

	GetWindow().RenderPolygon(TrianglePoints, 3,
	 White, HasBorder());
   return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -