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;
	}

 

上一篇:Android Studio下HierarchyViewer的使用


下一篇:浙江大学计算机与软件学院2019年保研上机模拟练习