先上结果(图):
![](https://box.kancloud.cn/fe9dc4e44de33ed33462a99c07bc82b8_502x501.png)
``
```
// Project1light2translate181003.cpp : 定义应用程序的入口点。
//
#include "stdafx.h"
#include "Project1light2translate181003.h"
#include <iostream>
#define MAX_LOADSTRING 100
// 12345678901234567890123456789012345678901234567890
#define PId 3.14159265358979323846264338327950288419716939937510f //双精度的PI
#define PIuint64 3141592653589793238Ui64
// 12345678901234567890123456789012345678901234567890
#define Multi18_PI 3141592653589793238
#define Multi18fmDeno 1000000000000000000 //18个0
// 全局变量:
HINSTANCE hInst; // 当前实例
WCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本
WCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名
// 此代码模块中包含的函数的前向声明:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: 在此处放置代码。
// 初始化全局字符串
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_PROJECT1LIGHT2TRANSLATE181003, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// 执行应用程序初始化:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PROJECT1LIGHT2TRANSLATE181003));
MSG msg;
// 主消息循环:
while (GetMessage(&msg, nullptr, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// 函数: MyRegisterClass()
//
// 目标: 注册窗口类。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PROJECT1LIGHT2TRANSLATE181003));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_PROJECT1LIGHT2TRANSLATE181003);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassExW(&wcex);
}
//
// 函数: InitInstance(HINSTANCE, int)
//
// 目标: 保存实例句柄并创建主窗口
//
// 注释:
//
// 在此函数中,我们在全局变量中保存实例句柄并
// 创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // 将实例句柄存储在全局变量中
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// 函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// 目标: 处理主窗口的消息。
//
// WM_COMMAND - 处理应用程序菜单
// WM_PAINT - 绘制主窗口
// WM_DESTROY - 发送退出消息并返回
//
//
//将TCHAR转为char
//*tchar是TCHAR类型指针,*_char是char类型指针
int TcharToChar(const TCHAR * tchar, char * _char)
{
int iLength;
//获取字节长度
iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);
//将tchar值赋给_char
WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);
return 1;
}
//同上*tchar是TCHAR类型指针,*_char是char类型指针
int CharToTchar(const char * _char, TCHAR * tchar)
{
int iLength;
iLength = MultiByteToWideChar(CP_ACP, 0, _char, strlen(_char) + 1, NULL, 0);
MultiByteToWideChar(CP_ACP, 0, _char, strlen(_char) + 1, tchar, iLength);
return iLength;
}
//
COLORREF getColorRGB1(int i) {
if (0 == i) return (9, 9, 9);
if (1 == i) return (0, 0, 200); //蓝
if (2 == i) return (0, 180, 0); //绿
if (3 == i) return (160, 0, 0); //红
if (4 == i) return (200, 0, 200); //品紫
if (5 == i) return (0, 255, 0); //亮绿
if (6 == i) return (0, 255, 255); //亮青
// if(i>=6)
return (255, 200, 200);
}
//
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// 分析菜单选择:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// HPEN hpen;
// TODO: 在此处添加使用 hdc 的任何绘图代码...
//
//输出文本-PI值
char cha40a01[40];
long double d_64 = (long double)(Multi18_PI / 1000000000); //9
std::cout << d_64 << std::endl;
_itoa_s((Multi18_PI / 10000000000), cha40a01, 10); //现在8*10倍PI;10个0(10000000000ok!) //9个0不行(溢出)
TCHAR szText[40];
CharToTchar(cha40a01, szText);
TextOut(hdc, 15, 10, szText, wcslen(szText));
//输出文本-PI值End
//
// 画圆 1号圆
int r1_200 = 200;// 100;
//圆心:
int c01_x00 = 200;
int c01_y00 = 200;
//画个圆 i1i01为角度值(非弧度
//圆的密度 //乘10
for (int i1i01 = 0; i1i01 <= 10 * 350; ++i1i01) { //for220 //for (int i1i01 = 0; i1i01 <= 360; ++i1i01) { //for220
// long double hu1du001 = Multi18_PI* i1i01 / 180; //转成弧度 10^18倍的弧度
long double hu1du001 = (long double)i1i01*(PId/180);// (long double)Multi18_PI / 10000 * i1i01 / 10 / 180 / 100000000000000;//先 降4个0 最后再降14个(共18个)
int x001 = cos(hu1du001) *r1_200;
int y001 = sin(hu1du001)*r1_200;
// SetPixel(hdc, x001 + c01_x00, y001 + c01_y00, RGB(0, 0, 227));//127));
}//for220
//
//画发射线
//
long double hu2du01 = 0;// 1.57;//发射线的 角度
//发射线的初始(出发点)
c01_x00 = 200;
c01_y00 = 200;
int Xpianyi90 = 90;
int Ypianyi40 = 40;
int lightX00start = c01_x00 + Xpianyi90;
int lightY00start = c01_y00 + Ypianyi40;
MoveToEx(hdc, lightX00start, lightY00start, NULL);
//逐点画光
uint64_t r01t01=0;
int numColor = 0;
int flagHaveFirst01 = 0;
int FanZhuanTimes = 0;
double newJiao2du = 0;
int newhalfBanjin2g = 0;
int newBan2jing;
int xx001 = c01_x00+Xpianyi90;
int yy001 = c01_y00 + Ypianyi40;//0;
for (uint64_t t1 = 0; t1 <= 9240; ++t1) {//for330 //for (uint64_t t1 = 0; t1 <= 1240; ++t1) {//for330
int x01 = cos(hu2du01)*r01t01; //t1;
int y01 = sin(hu2du01)*r01t01;
int x010002 = x01 + c01_x00+Xpianyi90;//Xpianyi90; //int x010002 = x01 + lightX00start;
int y010002 = y01 + c01_y00+Ypianyi40;//Ypianyi40; //int y010002 = y01 + lightY00start;
if(1==FanZhuanTimes%2 ) {//if7700
x01 = cos(hu2du01)* r01t01;// newBan2jing;//*r01t01; //t1;
y01 = sin(hu2du01)* r01t01;// newBan2jing;////*r01t01;
x010002 = xx001 -x01; //x010002 = x01 + xx001;
y010002 = y01 + yy001;
}//if7700
if (0 == FanZhuanTimes % 2) {
x01 = cos(hu2du01)* r01t01;// newBan2jing;//*r01t01; //t1;
y01 = sin(hu2du01)* r01t01;// newBan2jing;////*r01t01;
x010002 = xx001 +x01; //x010002 = x01 + xx001;
y010002 = y01 + yy001;
}
//取颜色
HPEN hpen;
hpen = CreatePen(PS_SOLID, 1, getColorRGB1(numColor % 7));
SetPixel(hdc, x010002, y010002, getColorRGB1((numColor + 1) % 7)); // //SetPixel(hdc, x010002, y010002, getColorRGB1((numColor + 1) % 7)); //
//取颜色end
//下面判断是否相交
int IsXiangJiao = 0;
int r200r = r1_200;
for (int i1i = 0; i1i <= 720; ++i1i) {//for440
long double hu1du001 = (long double)i1i*((long double)PId / 180);//(long double)Multi18_PI / 10000 * i1i / 180 / 100000000000000;//先除10000后除10^14
int x0101 = cos(hu1du001) * r1_200;
int y0101 = sin(hu1du001)* r1_200;
int x01001 = x0101 + c01_x00;
int y01001 = y0101 + c01_y00;
SetPixel(hdc, x01001 , y01001 , RGB(0, 0, 227));// SetPixel(hdc, x01001+c01_x00 , y01001+c01_y00 , RGB(0, 0, 227));//
//if碰撞(重叠
if ((x010002 / 10 == ((x01001) / 10)) && (y010002 / 4 == (y01001 / 4))) {//if550 //if ((x010002 / 4 == ((x01001) / 4)) && (y010002 / 4 == (y01001 / 4))) {//if550
IsXiangJiao = 1;
if (0 == flagHaveFirst01) {//if5600
//hu2du01 = -hu2du01 ;
FanZhuanTimes++;
flagHaveFirst01++;
++numColor;
//
xx001 = x01001; yy001 = y01001;
r01t01 = 0; //半径初始化了!
//输出文本-值
char cha30a01[30];
_itoa_s((FanZhuanTimes),cha30a01, 10); //
TCHAR szTex02t[30];
CharToTchar(cha30a01, szTex02t);
TextOut(hdc, 405, 100, szTex02t, wcslen(szTex02t));
//输出文本-值End
//算新元 圆02b号 情况
//新圆 半径 等于 2*
newJiao2du = asin( (double)Ypianyi40 / r200r);
_itoa_s(( 100*newJiao2du), cha30a01, 10); //
TCHAR szTex03t[30];
CharToTchar(cha30a01, szTex03t);
TextOut(hdc, 420, 150, szTex03t, wcslen(szTex03t));
if(1==(FanZhuanTimes%2) ) hu2du01 = -hu2du01- 2*newJiao2du;
else hu2du01 = -hu2du01+ 2*newJiao2du;
if (6.28 < hu2du01) hu2du01 -= 6.28;
if (0 > hu2du01) hu2du01 += 6.28;
newhalfBanjin2g = cos(newJiao2du);
newBan2jing = 2 * newhalfBanjin2g;
//算新元 圆02b号 情况end
//
}//if5600
}//if550
//if碰撞(重叠end
}//for440
if (0 != flagHaveFirst01 && (1 != IsXiangJiao)) { flagHaveFirst01 = 0; } //不(再)相交了//既然不相等了,flag01赶快复位!
//判断是否相交end
if (0 == FanZhuanTimes ) { //% 2) {//if 6600
r01t01++; //延长光线!
}//if6600
else { r01t01++; }
}//for330
//逐点画光end
//画发射线end
//
//
EndPaint(hWnd, &ps);
}//case110 //case WM_PAINT
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// “关于”框的消息处理程序。
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
```
- R高精“密率”-PI的分数的高精度表示形式-R语言181000a
- 高精“密率”-PI的分数的高精度表示形式181001
- java40k2011Terryfix181002
- PI的高精度分数表示形式180101
- c++算PI的分数表示形式180102
- 单圆弧的反射181001a
- 单个圆的圆弧反射181020a
- 附录11:181001非控制台(WindowsForm)窗口程序创建控制台(调试程序用
- 递归调用-判断两圆相碰撞情况181020
- 用递归算法模拟两圆反射Billiards181020
- 光线(粒子)在两圆间碰撞效果1810a
- 光线粒子在两圆内壁碰撞效果1810B
- twoBillards模拟光线(粒子)在重叠的两圆内壁的碰撞C++完整代码(带注释)Terry181001