匀速圆周运动模拟器
s沙兴安a
·
·
个人记录
#include<iostream>
#include<fstream>
#include<windows.h>
#include<conio.h>
#include<stdio.h>
#include<time.h>
#include<sstream>
#include<cstring>
#include<cmath>
#include<iomanip>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int px,py;
double x,y,r,v,omega,theta,tim,t;
const double PI=3.14159265358979;
void console(){
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO bInfo;
GetConsoleScreenBufferInfo(hOut, &bInfo );
SetConsoleTitle("匀速圆周运动模拟器 - 兴安狠活");
}
void color(int a){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void cls(){//赟刑道提供,如有侵权请联系删除。
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 }; // home for the cursor
SetConsoleCursorPosition( hConsole, coordScreen );
}
void Line(string str){//该函数如需借鉴请先联系沙兴安
int i,l,w;
w=152;
l=str.length();
for(i=0;i<(w-l)/2;i++)
cout<<" ";
cout<<str<<endl;
return ;
}
void line(string str,int w){//该函数如需借鉴请先联系沙兴安
int i,l;
l=str.length();
for(i=0;i<(w-l)/2;i++)
cout<<" ";
cout<<str;
return ;
}
void printline(string str){//该函数如需借鉴请先联系沙兴安
int i,l,w;
w=152;
l=str.length();
color(7);
for(i=0;i<(w-l)/2;i++)
cout<<"=";
color(14);
cout<<str;
color(7);
for(i=0;i<(w-l)/2;i++)
cout<<"=";
if(str.length()%2==1) cout<<"=";
cout<<endl;
return ;
}
double Angle_Radian(double degree){
return degree*(PI/180);
}
void render(){
x=r*cos(Angle_Radian(theta));
y=r*sin(Angle_Radian(theta));
px=round(x);
py=round(y);
for(int i=17;i>=-17;i--){
if(abs(i)%2==0) color(159);
else color(223);
if(abs(i)<10) cout<<"0";
cout<<abs(i);
for(int j=-37;j<=37;j++){
if(i==py && j==px){
color(191);
cout<<" ";
}else{
if(i==0 || j==0){
color(240);
if(i==0 && j==37) cout<<"++";
else if(i==0 && j==-37) cout<<"--";
else if(i==17 && j==0) cout<<"++";
else if(i==-17 && j==0) cout<<"--";
else cout<<" ";
}else{
color(7);
cout<<" ";
}
}
}
cout<<endl;
}
color(159);
cout<<" ";
for(int i=-37;i<=37;i++){
if(abs(i)%2==0) color(159);
else color(223);
if(abs(i)<10) cout<<"0";
cout<<abs(i);
}
cout<<endl;
printline("匀速圆周运动模拟器");
cout<<"坐标:("<<fixed<<setprecision(2)<<y<<","<<fixed<<setprecision(2)<<x<<")\t\t";
cout<<"t="<<fixed<<setprecision(2)<<t;
cout<<" \t\t已转圈数:"<<fixed<<setprecision(3)<<1.0*theta/360<<"圈 ";
}
int main(){
console();
system("mode con:cols=153 lines=43");
color(11);
Line("兴安科技出品 - 兴安狠活系列");
color(14);
Line("匀速圆周运动模拟器");
color(7);
cout<<"输入圆的半径(单位:m):";
cin>>r;
cout<<"输入角速度(单位:rad/s):";
cin>>omega;
cout<<"输入观看时间(单位:s):";
cin>>tim;
system("cls");
while(t<=tim){
cls();
render();
t+=0.05;
theta=omega*t;
}
return 0;
}