📄 kaleidoscope.cpp
字号:
// Kaleidoscope.cpp: implementation of the Kaleidoscope class.
//
//////////////////////////////////////////////////////////////////////
#include <iostream.h>
#include <assert.h>
#include "ezwin.h"
#include <time.h>
#include "ircleShape.h"
#include "RandomInt.h"
#include "SquareShape.h"
#include "TriangleShape.h"
#include "Kaleidoscope.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Kaleidoscope::Kaleidoscope(SimpleWindow &w,
int s) : Window(w), Speed(s),
CircleTrinket(w, Position(0, 0)),
SquareTrinket(w, Position(0, 0)),
TriangleTrinket(w, Position(0, 0)),
RandomColor(0, MaxColors - 1),
RandomShape(0, NumberOfShapeTypes - 1) {
assert(&w != NULL);
}
int Kaleidoscope::GetSpeed() {
return Speed;
}
SimpleWindow& Kaleidoscope::GetWindow() const {
return Window;
}
float Kaleidoscope::RandomOffset(int Range,
float ShapeSize) {
RandomInt R(0, Range * 10);
float offset = R.Draw() / 10.0;
if (offset < ShapeSize / 2)
offset = ShapeSize / 2;
return offset;
}
int Kaleidoscope::Turn() {
const Position CenterOfWindow = Window.GetCenter();
const float MaxShapeSize =
(Window.GetWidth() / 2.0) - 1.0;
const float MaxOffset =
(Window.GetWidth() / 2.0) - 1.0;
vector<color> ShapeColor(2);
ShapeColor[0] = (color) RandomColor.Draw();
ShapeColor[1] = (color) RandomColor.Draw();
RandomInt RandomShapeSize(10, MaxShapeSize * 10);
const float ShapeSize = RandomShapeSize.Draw() / 10.0;
const float Offset = RandomOffset(MaxOffset, ShapeSize);
vector<Position> ShapeLocation(ShapesPerTurn);
ShapeLocation[0] = CenterOfWindow + Position( Offset, -Offset);
ShapeLocation[1] = CenterOfWindow + Position(-Offset, -Offset);
ShapeLocation[2] = CenterOfWindow + Position(-Offset, Offset);
ShapeLocation[3] = CenterOfWindow + Position( Offset, Offset);
const ShapeType KindOfShape = (ShapeType) RandomShape.Draw();
if (KindOfShape == CircleType) {
for (int i = 0; i < ShapesPerTurn; ++i) {
CircleTrinket.SetPosition(ShapeLocation[i]);
CircleTrinket.SetColor(ShapeColor[i % 2]);
CircleTrinket.SetSize(ShapeSize);
CircleTrinket.Draw();
}
}
else if (KindOfShape == SquareType) {
for (int i = 0; i < ShapesPerTurn; ++i) {
SquareTrinket.SetPosition(ShapeLocation[i]);
SquareTrinket.SetColor(ShapeColor[i % 2]);
SquareTrinket.SetSize(ShapeSize);
SquareTrinket.Draw();
}
}
else if (KindOfShape == TriangleType) {
for (int i = 0; i < ShapesPerTurn; ++i) {
TriangleTrinket.SetPosition(ShapeLocation[i]);
TriangleTrinket.SetColor(ShapeColor[i % 2]);
TriangleTrinket.SetSize(ShapeSize);
TriangleTrinket.Draw();
}
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -