绘制圆形文本 | 计算机图形学(c++版MFC)

声明:凡代码问题,欢迎私信或在评论区沟通。承蒙指正,一起成长!

一、实验目的

1.熟悉VC++6.0上机编程环境 ;

2.了解并掌握使用语言绘图函数绘制简单的二维图形;

3.理解平面中坐标的概念,能耐在指定位置输出文件。

二、实验内容

绘制如下图所显示数字1、2、3……12 ,使其延圆形轨道排列,呈现钟表表盘的样式。

思想:

        圆也是计算机图形学中经常用到的图形,具有一定的代表性,可以用下面方程表示一个圆,其圆心在原点(0,0) :

                X = r * cos(t) ,  Y = r * sin(t) ;      -3.1416  \leq  t  \leq  3.1416 

也可以使用下面方程表示一个圆,其圆心在(3,3)点 :

                X = r * cos(t)  + 3,  Y = r * sin(t)  + 3;      -3.1416  \leq  t  \leq  3.1416  

下面方法也表示一个圆,其圆心在(3,3),半径是1.8:

                y = \pm\sqrt{1.8^{2} -(x - 3)^{2}} + 3         -1.8  \leq  t  \leq  1.8

有了方程,当然可以使用方程绘制其图像。

三、直接上代码 

// clockView.cpp : implementation of the CClockView class
//

#include "stdafx.h"
#include "clock.h"

#include "clockDoc.h"
#include "clockView.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
// CClockView

IMPLEMENT_DYNCREATE(CClockView, CView)

BEGIN_MESSAGE_MAP(CClockView, CView)
	//{
   
   {AFX_MSG_MAP(CClockView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/
// CClockView construction/destruction

CClockView::CClockView()
{
	// TODO: add construction code here

}

CClockView::~CClockView()
{
}

BOOL CClockView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/
// CClockView drawing

void CClockView::OnDraw(CDC* pDC)
{
	CClockDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	double i;
	CString c; 
	int s[12] = {3,4,5,6,7,8,9,10,11,12,1,2};
	int k;
	for(k=0,i=0;k<12;k++,i+=52.3)
	{
		c.Format("%d",s[k]);
		pDC->TextOut((int)(200+100*cos(i/100)),(int)(200+100*sin(i/100)),c);
	}
}

/
// CClockView printing

BOOL CClockView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CClockView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CClockView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/
// CClockView diagnostics

#ifdef _DEBUG
void CClockView::AssertValid() const
{
	CView::AssertValid();
}

void CClockView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CClockDoc* CClockView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CClockDoc)));
	return (CClockDoc*)m_pDocument;
}
#endif //_DEBUG

/
// CClockView message handlers

四、运行结果

猜你喜欢

转载自blog.csdn.net/kndjg/article/details/125037307