View difference between Paste ID: n49wmSb3 and
SHOW: | | - or go back to the newest paste.
1-
1+
// consine.c - Displays a 2D sine pattern in the console
2
// Created by flarn2006
3
// License: Creative Commons BY-NC-SA 3.0
4
5
#include <curses.h>
6
#include <math.h>
7
#include <stdlib.h>
8
9
char levelchar(float value);
10
11
int main(int argc, const char *argv[]) {
12
	int x, y;
13
	int maxx, maxy;
14
	initscr();
15
	cbreak();
16
	noecho();
17
	getmaxyx(stdscr, maxy, maxx);
18
	
19
	for (y=0; y<=maxy; y++)
20
	for (x=0; x<=maxx; x++) {
21
		float fx = (float)x;
22
		float fy = (float)y;
23
		float value = fabsf(sin(fx/5.0)+sin(fy/2.5));
24
		value /= 2.0;
25
		char level = levelchar(value);
26
		mvaddch(y, x, level);
27
	}
28
	
29
	getch();
30
	endwin();
31
    return 0;
32
}
33
34
char levelchar(float value)
35
{
36
	const char *levels = "'.,-:;!|@#";
37
	int index = (int)(10*value) % 10;
38
	return levels[index];
39
}