Advertisement

Parabola Console

Started by October 19, 2024 11:06 PM
3 comments, last by Alberth 4 weeks ago

All I want to do is draw a parabola to the console, however I have drawn the x-axis and y-axis. here is the code I am using.

#include<iostream>
using namespace std;
int main()
{
	double screen_length = 79;
	double screen_height = 24;
	double minx = -10;
	double maxx = 10;
	double miny = -10;
	double maxy = 100;
	double xx = 20 / static_cast<float>(screen_length);
	double yy = static_cast<float>(screen_height) / 110;
	double xpoint, ypoint;
	for (int i = 1; i <= 24; i++)
	{
		if (i == 23)
		{
			for (int k = 1; k <= 80; k++)
				cout << "-";
		}
		xpoint = (i - minx)*xx;
		for (int c = 1; c <= 80; c++)
		{
			if (c == 40)
				cout << "|";
			else
				cout << " ";
			ypoint = (c - miny)*yy;
			if (ypoint == (xpoint * xpoint))
			{
				cout << "*";
			}
		}
		cout << endl;
		yy += yy;
		xx += xx;
	}
	cout << xx << endl << yy << endl;
	cout << xpoint << endl << ypoint << endl;
	return 0;
}

I have solved my problem, sorry for the post.

Advertisement

That's awesome. One time I did that too. Do you create ASCII graphics by chance?

pbivens67 said:

double screen_length = 79;
double screen_height = 24;

These look like global size parameters, so you can change these and get a different size picture.

Does that work? If eg you change the former to say 100 and the latter to 30, do you get a larger picture?

Your code looks like it doesn't work. Try fixing it.

Advertisement