Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.9 kB
1
Indexable
Never
#include <SFML/Graphics.hpp>
#include <iostream>
#include <cmath>

using namespace sf;

const int width = 602;
const int height = 602;
const double g = 9.81;

int xyeta(int a) {
	int temp = a;
	int count = 0;

	while (temp > 0) {
		temp /= 10;
		count += 1;
	}

	count -= 1;
	//if (count > 2)count -= 2;
	//else count -= 1;
	return count;
}


int main() {
	setlocale(LC_ALL, "Russian");
	double velocity;
	double angle_of_launch;
	double initial_height;
	double v_y;
	double maximum_height;
	double scale;

	std::cout << "Задай скорость: ";
	std::cin >> velocity;
	std::cout << "Задай угол запуска: ";
	std::cin >> angle_of_launch;
	std::cout << "Задай начальную высоту: ";
	std::cin >> initial_height;
	std::cout << "Задай масштаб(сам потыкай какой нормальный масштаб): ";
	std::cin >> scale;

	RenderWindow window(VideoMode(width, height), "Trajectory of a projectile");

	int x0 = width / 2;
	int y0 = height / 2;

	CircleShape point(2.f);
	point.setFillColor(Color::Red);

	int o1 = -10;
	int o2 = 10;
	//float c = 150;
	float c = 100;
	int quantity_of_points = ((o1) * (-1) + o2) * c + 1;
	//int scale = 20;

	int anim = 0;

	while (window.isOpen()) {
		Event event;
		while (window.pollEvent(event)) {
			if (event.type == Event::Closed) window.close();
		}
		if (anim < quantity_of_points) anim += 50;

		window.clear(Color::White);

		for (int i = 0; i < anim; i++) {
			double x = o1 + i / c;
			double y = initial_height + x * tan(angle_of_launch) - g * pow(x, 2) / (2 * pow(velocity, 2) * pow(cos(angle_of_launch), 2));

			double x1 = x0 + x * scale;
			double y1 = y0 - y * scale;

			point.setPosition(x1, y1);
			window.draw(point);
		}
		window.display();
	}
	
}
Leave a Comment