问题的提出:根据“心”形曲线的数学参数方程,绘制曲线并输出屏幕。在各坐标点处循环显示“LOVE”的各字母。
编程思路:“心”形曲线的数学参数方程为:
用xin[2*R+1][2*R+1]存储图形。
代码:
// test9_.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <math.h>
const int R = 16;//极坐标的半径
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char xin[2*R+1][2*R+1];
//初始化
int x,y,t;
double d;
for (x=0; x<=2*R; x++)
{
for (y=0; y<=2*R; y++)
{
xin[x][y]=' ';
}
}
for(t=0; t<=360; t+=5)
{
d=t*3.14159/180;//转换为弧度
//i=(int)(R*sin(d/2)*sin(d));
//j=(int)(R*sin(d/2)*cos(d));
x=(int)(R*sin(d/2)*sin(d))+R;
y=(int)(R*sin(d/2)*cos(d))+R;
if(t%4==0)
xin[x][y]='L';
else if(t%4==1)
xin[x][y]='O';
else if(t%4==2)
xin[x][y]='V';
else if(t%4==3)
xin[x][y]='E';
else
xin[x][y]='*';
}
for (x=0; x<=2*R; x++)
{
for (y=0; y<=2*R; y++)
{
cout<<setw(2)<<xin[x][y];
}
cout<<endl;
}
system("pause");
return 0;
}
结果: