其他分享
首页 > 其他分享> > 2021-05-15

2021-05-15

作者:互联网

                                                                                                                                                                       绘制sin曲线

#include <iostream>
#include <cmath>
#define sineheight 20
#define degreestep 5
#define sinewidth  73
using namespace std;
char *framebuffer;
bool intiWindow(int width, int height) {
	framebuffer = new char[(width+1) * 20];
	if (!framebuffer)return false;
	for (int y = 0; y < height+1; y++)
		for (int x = 0; x < width; x++)framebuffer[y * width + x] = ' ';
	return true;
}
void setPixel(int width, int height) {
	framebuffer[sinewidth * height + width] = '*';
}
void draw_sin_curve() {
	for (int degree = 0; degree < 361; degree += degreestep) {
		int x =degree / degreestep;
		int y =  -1*floor(sin(degree* 3.141 / 180) * (sineheight /2)+0.5) + sineheight / 2;
		setPixel(x, y);
	}
	
}
	void show() {
		for (int y = 0; y < sineheight+1; y++) {
			for (int x = 0; x < sinewidth; x++)cout << framebuffer[y * sinewidth + x];
			cout << endl;
		}
	}
	int main() {
		if (!intiWindow(73, 20)) { return 1; }
		draw_sin_curve();
		show();
		delete[]  framebuffer;
	}

 

标签:15,degree,05,int,height,width,2021,sineheight,framebuffer
来源: https://blog.csdn.net/Danholic/article/details/116852888