?? snowflake.h
字號:
//************************ snowflake.h ***************************
// Visual C++ program
#include <cmath>
double PI = 3.14159;
class vonKoch {
public:
vonKoch(int,int,CDC*);
void snowflake();
private:
double side, angle;
int level;
CPoint currPt, pt;
CDC *pen;
void right(double x) {
angle += x;
}
void left (double x) {
angle -= x;
}
void drawFourLines(double side, int level);
};
vonKoch::vonKoch(int s, int lvl, CDC *pDC) {
pen = pDC;
currPt.x = 200;
currPt.y = 100;
pen->MoveTo(currPt);
angle = 0.0;
side = s;
level = lvl;
}
void vonKoch::drawFourLines(double side, int level) {
// arguments to sin() and cos() are angles
// specified in radians, i.e., the coefficient
// PI/180 is necessary;
if (level == 0) { //
pt.x = int(cos(angle*PI/180)*side) + currPt.x;
pt.y = int(sin(angle*PI/180)*side) + currPt.y;
pen->LineTo(pt);
currPt.x = pt.x;
currPt.y = pt.y;
}
else {
drawFourLines(side/3,level-1);
left (60);
drawFourLines(side/3,level-1);
right(120);
drawFourLines(side/3,level-1);
left (60);
drawFourLines(side/3,level-1);
}
}
void vonKoch::snowflake() {
for (int i = 1; i <= 3; i++) {
drawFourLines(side,level);
right(120);
}
}
// The function OnDraw() is generated by Visual C++ when creating
// a snowflake project of type MFC AppWizard (exe), Single Document;
#include "a:snowflake.h"
void CSnowflakeView::OnDraw(CDC* pDC)
{
CSnowflakeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
vonKoch(200,4,pDC).snowflake();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -