1
已解决
薛乘志
初级启示者
初级启示者
效果图:
(动图应该能看到)
如果你够勇,可以把字体调小点模拟更大的,如:
(抛物角20,初始速度30,重力加速度10)
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
void gotoxy(short x, short y) {
COORD coord = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
return;
}
void hideC() {
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);
CursorInfo.bVisible = false;
SetConsoleCursorInfo(handle, &CursorInfo);
}
bool m[40][20];
float angle, speed, acceleration, starthigh, stophigh;
int x, y, stoptime;
int main() {
system("cls");
r1:
cout << "抛射角(°):";
cin >> angle;
if (angle <= 0 || angle >= 90) {
cout << "数据无效,请重新输入.\n";
goto r1;
}
r2:
cout << "初始速度(单位长度/单位时间):";
cin >> speed;
if (speed <= 0) {
cout << "数据无效,请重新输入.\n";
goto r2;
}
r3:
cout << "重力加速度(单位长度/单位时间):";
cin >> acceleration;
if (acceleration <= 0) {
cout << "数据无效,请重新输入.\n";
goto r3;
}
cout << "初始高度(y轴位置):";
cin >> starthigh;
cout << "停止模拟高度(y轴位置):";
cin >> stophigh;
system("cls");
cout << "开始计算";
int ans[1005], maxn = -0x3f3f3f3f, minn = 0x3f3f3f3f, s;
while (y >= stophigh) {
y = acceleration / (-2 * cos(angle) * cos(angle) * speed * speed) * x * x + tan(angle) * x + starthigh;
ans[x++] = y;
cout << "X:" << x << " Y:" << y << endl;
maxn = max(maxn, y);
minn = min(minn, y);
}
r6:
system("cls");
cout << "每次变化间隔时间(ms):";
cin >> stoptime;
if (stoptime < 0) {
cout << "数据无效,请重新输入.\n";
goto r6;
}
hideC();
system("cls");
cout << "将在1s后开始模拟";
Sleep(1000);
system("cls");
gotoxy(0, 1);
for (int i = maxn; i >= minn; i--) {
cout << i << endl;
}
for (int i = 0; i < x; i++) {
gotoxy(i + 4, maxn - ans[i] + 1);
cout << "#";
gotoxy(0, maxn - ans[i] + 1);
cout << ans[i];
Sleep(stoptime);
gotoxy(i + 4, maxn - ans[i] + 1);
cout << " ";
}
Sleep(500);
for (int i = 0; i < x; i++) {
gotoxy(i + 4, maxn - ans[i] + 1);
cout << "#";
}
gotoxy(0, 0);
cout << "按任意键重新模拟";
getch();
goto r6;
return 0;
}
薛乘志在2021-11-21 14:09:35追加了内容
这玩意本质就是个函数图像,解析式就写在程序里
薛乘志在2021-11-21 14:12:01追加了内容
以后计划用这个原理做个愤怒的小鸟
0
0