``
```
// Project1tuxing18light1002.cpp : 定义应用程序的入口点。
//
#include "stdafx.h"
#include "Project1tuxing18light1002.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_PROJECT1TUXING18LIGHT1002, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// 执行应用程序初始化:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PROJECT1TUXING18LIGHT1002));
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_PROJECT1TUXING18LIGHT1002));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_PROJECT1TUXING18LIGHT1002);
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;
}
//
//
//
//将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;
}
//
struct RGBstruc1 { int r;
int g; int b;
};
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 );
}
// 函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// 目标: 处理主窗口的消息。
//
// WM_COMMAND - 处理应用程序菜单
// WM_PAINT - 绘制主窗口
// WM_DESTROY - 发送退出消息并返回
//
//
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:
{//case110
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
HPEN hpen;
// TODO: 在此处添加使用 hdc 的任何绘图代码...
//
//输出文本-PI值
char cha40a01[40];
uint64_t uint64pi = (uint64_t)(Multi18_PI/10000000000); //10个0
long double d_64 = (long double)(Multi18_PI / 1000000000); //9
std::cout << uint64pi << 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 x01_100 = 100; int y01_100 = 100;
MoveToEx(hdc, x01_100, y01_100, NULL);
LineTo(hdc, 200, 150);
//
// 画圆 1号圆
int r1_100 = 100;
//圆心:
int c01_x00 = 200;
int c01_y00 = 200;
//画个圆 i1i为角度值(非弧度
//圆的密度 称10
for (int i1i = 0; i1i <= 10*350; ++i1i) { //for220 //for (int i1i = 0; i1i <= 360; ++i1i) { //for220
// long double hu1du001 = Multi18_PI* i1i / 180; //转成弧度 10^18倍的弧度
long double hu1du001 = (long double)Multi18_PI / 10000 * i1i / 10 / 180 / 100000000000000;//先 降4个0 最后再降14个(共18个)
int x001 = cos(hu1du001) *r1_100;
int y001 = sin(hu1du001)*r1_100;
SetPixel(hdc, x001 + c01_x00 , y001 + c01_y00, RGB(0, 0, 227));//127));
}//for220
//画反射
//
long double hu2du01 = 3;// 2;
//{////画反射1
MoveToEx(hdc, c01_x00, c01_y00, NULL);
uint64_t tt = 0; //tt时间
int flag01 = 0;//(每次相交(横纵坐标相等后)只反转1次
int IsFanZhuan = 0;
int r01t01 = 0;// 240;
int numColor = 0;
for (uint64_t t1 = 0; t1 <= 260; ++t1) {//for330
int x01 = cos(hu2du01)*r01t01;// t1;
int y01 = sin(hu2du01)*r01t01;// t1;
//取颜色
//HPEN = hpen;
hpen = CreatePen( PS_SOLID, 1, getColorRGB1(numColor % 7) );
//取颜色end
SetPixel(hdc, x01 + c01_x00, y01 + c01_y00, getColorRGB1( (numColor+1) % 7)); // RGB(0, 200, 0));
SetPixel(hdc, x01 + c01_x00 +1, y01 + c01_y00+1, getColorRGB1((numColor + 1) % 7)); SetPixel(hdc, x01 + c01_x00+1, y01 + c01_y00, getColorRGB1( (numColor+1) % 7)); SetPixel(hdc, x01 + c01_x00, y01 + c01_y00+1, getColorRGB1((numColor + 1) % 7)); ////
//输出变量(到文本
char char30a02[30];
_itoa_s(x01, char30a02, 10);
TCHAR szText01x[30];
CharToTchar(char30a02, szText01x);
TextOut(hdc, 410, 20, szText01x, wcslen(szText01x));
//输出变量(到文本-end
//是否相交呢?
int IsXiangjiao = 0;
for (int i1i = 0; i1i <= 360; ++i1i) {//for440 //for (int i1i=0;i1i<=10*360; ++i1i ) {//for440
long double hu1du001 = (long double)Multi18_PI / 10000 * i1i /*/ 10*/ / 180 / 100000000000000;//先 降4个0 最后再降14个(共18个)
int x001 = cos(hu1du001) * r1_100;
int y001 = sin(hu1du001)* r1_100;
//输出变量(到文本
char char30a02[30];
_itoa_s(x01, char30a02, 10);
TCHAR szText01x[30];
CharToTchar(char30a02, szText01x);
TextOut(hdc, 450, 40, szText01x, wcslen(szText01x));
//输出变量(到文本-end
if ((x01/2 == (x001/2 )) && (y01 == (y001 ))) {//if550 //和圆撞上了!
IsXiangjiao = 1;
if (0 == flag01) {
IsFanZhuan = (1==IsFanZhuan) ? 0 : 1; //乒乓标志,翻转! IsFanZhuan = 1;
// long double hu2du002 = PId - hu2du01;
// hu2du01 = hu2du01 + 0.1;
hu2du01 = hu2du01 + 2 * 3.12;//+ 2*3.14;
flag01 ++; //相等过一次,就反转(过)了,记住,不要再进来反转(这个相当于“单例模式(设计模型)”!)
++numColor;
} // hu2du002; //只反转1次
}//if550
}//for440
//下面进入(射线的)下一个点的计算和检测
if (0 != flag01 && (1!=IsXiangjiao) )//if550elseif560//不(再)相交了
{ flag01 = 0; }////if550elseif560 既然不相等了,flag01赶快复位!
if (0 == IsFanZhuan) { r01t01++; }
else { r01t01--; }
}//for330
//}////画反射1end
//
//
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