ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
`` Feature:包括 1、带控制台 2、可以选择颜色 …… `//调用Console控制台 AllocConsole(); #pragma warning(disable:4996) _tfreopen(TEXT("CONOUT$"), TEXT("w"), stdout); _tfreopen(TEXT("CONOUT$"), TEXT("w"), stderr); _tfreopen(TEXT("CONIN$"), TEXT("r"), stdin); #pragma warning(default:4996) _tsetlocale(LC_ALL, TEXT("chs")); std::cout << PId << std::endl;` ``` // Win32Project1light18digui181008d.cpp : 定义应用程序的入口点。 // #include "stdafx.h" #include <iostream> #include "Win32Project1light18digui181008d.h" using namespace std; #define PI18 3141592653589793238 #define PId 3.141592653589793238 #define MAX_LOADSTRING 100 // 全局变量: long long diguiAllTimes1 = 0; //HDC hdc; HINSTANCE hInst; // 当前实例 TCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本 TCHAR 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 _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // TODO: 在此放置代码。 //调用Console控制台 AllocConsole(); #pragma warning(disable:4996) _tfreopen(TEXT("CONOUT$"), TEXT("w"), stdout); _tfreopen(TEXT("CONOUT$"), TEXT("w"), stderr); _tfreopen(TEXT("CONIN$"), TEXT("r"), stdin); #pragma warning(default:4996) _tsetlocale(LC_ALL, TEXT("chs")); std::cout << PId << std::endl; cout << PI18 << endl; MSG msg; HACCEL hAccelTable; // 初始化全局字符串 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_WIN32PROJECT1LIGHT18DIGUI181008D, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // 执行应用程序初始化: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32PROJECT1LIGHT18DIGUI181008D)); // 主消息循环: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; } // // 函数: MyRegisterClass() // // 目的: 注册窗口类。 // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX 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_WIN32PROJECT1LIGHT18DIGUI181008D)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WIN32PROJECT1LIGHT18DIGUI181008D); wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassEx(&wcex); } // // 函数: InitInstance(HINSTANCE, int) // // 目的: 保存实例句柄并创建主窗口 // // 注释: // // 在此函数中,我们在全局变量中保存实例句柄并 // 创建和显示主程序窗口。 // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // 将实例句柄存储在全局变量中 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // // COLORREF getColor1RGB1(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 (7 == i) return (255, 255, 0); //黄 // if(i>=7) return (255, 200, 200);//灰白 } // ////digui01andDrawlight 参数 : 01hdc, 2:tt光线总长,3:入射角度(角度非弧度), 4(当前)光线入口x坐标x01;5当前光线入口Y坐标Y01; //digui01andDrawlight(hdc, tt, 125, 190, 200); ////int digui01DrawLine01light(HDC hdc, long long tt, int rsjiaodu, int x01, int y01) int digui01DrawLine01light(HDC hdc , int whichCircle, long long tt, double rsHu01du01, int rsjiaodu, int x01, int y01) //int digui01DrawLine01light( long long tt, int rsjiaodu, int x01, int y01) {//int digui01andDrawlight112110 diguiAllTimes1++; printf_s("dgTimes:%lld", diguiAllTimes1); // cout << "diguiAllTimes1:" << diguiAllTimes1 << endl; // printf_s("run112110Here!"); // cout << "run112110Here!" << endl; if (tt <= 1) { cout << "[tt=1?" << tt << "]"<<endl; return 1; } // double rsHudu01 = ((double)rsjiaodu * 1000.0 / 180.0 / 1000.0 / 10000.0) * PI18 / 10000000000000;// 0; double rsHudu01 = (double)rsjiaodu *PId / 180; cout << "入射角1度:" << rsjiaodu;// << endl; rsHudu01 = (double)rsjiaodu*3.1415926 / 180.0; printf_s("_rsHu01du01:=%f", rsHu01du01); cout << endl; // cout << "rsHudu01:=" << rsHudu01 << endl; long lightDuanlen01 = 0;//当前光线 线段长度 // for (long long ii = 0; ii < tt; ++ii) {//for1110 ++lightDuanlen01; double danweiX01 = cos(rsHu01du01); double danweiY01 = sin(rsHu01du01); double yuanShiX001 = (double)danweiX01*lightDuanlen01; double yuanShiY001 = danweiY01*lightDuanlen01; // int zhenShiX0001 = (double)yuanShiX001 + x01; int zhenShiY0001 = (double)yuanShiY001 + y01; //根据真实 实际坐标,描点成线--… SetPixel(hdc, zhenShiX0001, zhenShiY0001, RGB(0, 0, 200)); //亮蓝 //判断: //判断真实点的轴距 //判断 是否 撞过 C1 圆1: if (/*1*/ 1==whichCircle && zhenShiX0001 >= 200 /*1*/) {//if11a10 long long tt1new01 = tt - ii; double faXian1Hudu01 = PId;// -0.1; //法线弧度为PI=π double rsOld00Hu1du01 = (double)PId*rsjiaodu / 180; //旧入射角度转弧度 double rsNewHudu01 = faXian1Hudu01 + (2*PId- rsHu01du01) ;// PId;// //(double)210 * PId / 180; //(double)130 * PId / 180; // 110 * PId / 180; //(90 + 80)*PId + rsOld00Hu1du01; // 180; //faXian1Hudu01 - rsOld00Hu1du01; //double rsNewHudu01 = faXian1Hudu01 + rsOld00Hu1du01; int rsNewJiao1du = ceil(rsNewHudu01 * 180 / PId); // if (rsNewJiao1du < 0) rsNewJiao1du += 360; // if (rsNewJiao1du > 360) rsNewJiao1du -= 360; lightDuanlen01 = 1; if (diguiAllTimes1 < 1900) {//if diguiAllTimes1 < 1900 //判断是否和第一个圆相撞,则切换到 第2号圆////切换 去第 1号圆的判断(和Draw digui01DrawLine01light( hdc,2, (long long)tt1new01, rsNewHudu01, rsNewJiao1du, zhenShiX0001, zhenShiY0001); //digui01DrawLine01light(hdc, tt1new01, rsNewJiao1du, zhenShiX0001, zhenShiY0001); }//if diguiAllTimes1 < 1950//3000//1900 else { return 2; } }//if11a10 //根据真实 实际坐标,描点成线--… SetPixel(hdc, zhenShiX0001, zhenShiY0001, RGB(0, 200, 0)); //亮绿 //判断 是否 撞过 C2 圆2: if (/*1*/ 2==whichCircle && zhenShiX0001 <=100 /*1*/) {//if11a10 long long tt1new01 = tt - ii; double faXian1Hudu01 = 0; // (double)-PId; //法线弧度为PI=π double rsOld00Hu1du01 = (double)PId*rsjiaodu / 180; //旧入射角度转弧度 double rsNewHudu01 = (double)faXian1Hudu01 +(PId- rsHu01du01);// -rsOld00Hu1du01; int rsNewJiao1du = 0;//faXian1Hudu01;//废弃 //ceil( (double)150 * PId / 180); ////rsNewHudu01 * 180 / PId; // if (rsNewJiao1du < 0) rsNewJiao1du += 360; // if (rsNewJiao1du > 360) rsNewJiao1du -= 360; lightDuanlen01 = 1; if (diguiAllTimes1 < 1900) {//if diguiAllTimes1 < 1900 lightDuanlen01 = 1; //切去第 1号圆的判断(和Draw cout << "[22:rsNewHudu01" << rsNewHudu01 <<"]"<< endl; //rsNewJiao1du废弃 digui01DrawLine01light( hdc, 1, tt1new01, rsNewHudu01, rsNewJiao1du, zhenShiX0001, zhenShiY0001); //digui01DrawLine01light(hdc, tt1new01, rsNewJiao1du, zhenShiX0001, zhenShiY0001); }//if diguiAllTimes1 < 1950 }//if11a10 //根据真实 实际坐标,描点成线--… SetPixel(hdc, zhenShiX0001, zhenShiY0001, getColor1RGB1(diguiAllTimes1%8 )); //RGB(200, 0, 0)); //亮红 }//for1110 // return 1; }//int digui01DrawLine01light // // int wm01paint01(HWND hWnd, PAINTSTRUCT ps, HDC hdc ) { //int wm01paint01(HWND hWnd, PAINTSTRUCT ps, HDC hdc) { int c1_200_r01 = 200; int c2_20b0_r02 = 200; int c1XpianyiX = 0; //左圆用初始值-(圆心的偏移量为0 int c1YpianyiY = 200;//向下偏移200 int c2XpianyiX = 300; int c2YpianyiY = 200; int tt1chushi_R01 = 200; //c1i01为角度变化,弧度需要计算 *π/180 MoveToEx(hdc, 100, 0, NULL); LineTo(hdc, 100, 400); MoveToEx(hdc, 200, 0, NULL); LineTo(hdc, 200, 400); //根据 时间 tt 描点成线-start int light1R001 = 0;// 210;//发射光的初始半径 应大于200 int light1new01R001 = light1R001; int ChuShi1RuSheJiao01jiaoDu = 135 - 10;// 180;// 45;// 0;// 130;// 100;////135 - 10; double ruShejiao1Hu1du01 = ((double)0.1 * 100 * ChuShi1RuSheJiao01jiaoDu / 10000 * PI18 / 180 / 1000000000000000);//除 10^18 cout << "ruShejiao1Hu1du01 " << ruShejiao1Hu1du01 << endl; int chushi1x001 = 190;// 200;// 0;// 190; int chushi1y001 = 200;// 0;// 200; // long long tt = 1390;// 390;// 590; //digui01andDrawlight 参数 : 01hdc, 2:tt光线总长,3:入射角度(角度非弧度), 4(当前)光线入口x坐标x01;5当前光线入口Y坐标Y01; //初始撞向第2号圆 //125度= 125/180*PId; digui01DrawLine01light( hdc, 2,tt, (165*PId/180), 125, 190, 200 ); //digui01DrawLine01light(hdc, tt, 125, 190, 200); // return 1; }//int wm01paint01 // 函数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: 处理主窗口的消息。 // // WM_COMMAND - 处理应用程序菜单 // WM_PAINT - 绘制主窗口 // WM_DESTROY - 发送退出消息并返回 // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(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 hdc = BeginPaint(hWnd, &ps); // TODO: 在此添加任意绘图代码... wm01paint01(hWnd, ps ,hdc); //wm01paint01(hWnd, ps, hdc); 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; } ``` ![](https://box.kancloud.cn/4e854e16cbdcdc5d5d4fc20799feaf6f_308x722.png)