• R/O
  • HTTP
  • SSH
  • HTTPS

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

oga's tools


File Info

Rev. d6f35a911265152c0ebe479a6552316ce6024300
Größe 2,595 Bytes
Zeit 2024-12-28 17:25:55
Autor hyperoga
Log Message

change access permission

Content

/*
 *     mexhat.c  for terminal
 *
 *        V0.10  2024/12/10  by oga.
 *        V0.11  2024/12/10  add -c, -w option
 *
 *        max terminal size: mexhat -x 200 -y 60
 */

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <cur.h>

#define VER "0.11"

int x_size = 80;
int y_size = 39;
char *dot_chr = ".";

void usage()
{
	printf("Mexican Hat ver %s\n", VER);
	printf("usage : mexhat [-x <x_size>] [-y <y_size>] [-w <wait_time(ms)>] [-c <dot_char(.)>] [-nocls]\n");
	printf("        -nocls    : no clear screen\n");
	printf("        -x        : window size X\n");
	printf("        -y        : window size Y\n");
	printf("        -w        : wait time (ms)\n");
	printf("        -c        : dot char. default:. \n");
	exit(1);
}

int main(int a, char *b[])
{
	int    vf       = 0;  /* -v        verbose flag */
	int    nocls    = 0;  /* -nocls    flag         */

	int     i, sx, sy;
	int     col;
	int     wait = 0;
	double  dr, r, x, y, z;
	int     d[180];

	for (i = 1; i<a; i++) {
	    if (!strncmp(b[i],"-h",2)) {
	    	usage();
	    }
	    if (!strncmp(b[i],"-v",2)) {
		vf = 1;
		continue;
	    }
	    if (!strcmp(b[i],"-nocls")) {
	        nocls = 1;
	        continue;
	    }
	    if (!strcmp(b[i],"-x")) {
	    	if (++i >= a) usage();
	        x_size = atoi(b[i]);
	        continue;
	    }
	    if (!strcmp(b[i],"-y")) {
	    	if (++i >= a) usage();
	        y_size = atoi(b[i]);
	        continue;
	    }
	    if (!strcmp(b[i],"-w")) {
	    	if (++i >= a) usage();
	        wait = atoi(b[i]);
	        continue;
	    }
	    if (!strcmp(b[i],"-c")) {
	    	if (++i >= a) usage();
	        dot_chr = b[i];
	        continue;
	    }
	}

	if (vf) {
		printf("size=%dx%d\n", x_size, y_size);
	}

	if (nocls == 0) {
		cls();
	}

	for (i = 0; i < 180; i++) {
		d[i] = 100;
	}
	dr = 3.1419/180;

	for (y = -180; y <= 180; y+=6) {
		for (x = -180; x <= 180; x+=4) {
			r = dr * sqrt(x*x + y*y);
			z = 100 * cos(r) - 30 * cos(3*r);
			sx = (int)90.0+x/3.0-y/6.0;
			sy = (int)40.0-y/6.0-z/4.0;
			if (vf) {
				locate(0,1);
				printf("sx=%d, sy=%d\n", sx, sy);
			}
			if (d[sx] > sy) {
				if (0 <= sx && sx < 512) {
					if (vf) {
						locate(0,2);
						printf("psx=%d, psy=%d\n", (sx*x_size)/150, (sy*y_size)/100);
					}
					col = ((z+100)*7)/200+1;
					color(col);
					locate((sx*x_size)/150, (sy*y_size)/100);
					printf("%s\n", dot_chr);
					if (wait) {
						usleep(wait*1000);
					}
					//fflush(stdout);
					d[sx] = sy;
				}
			}
		}
	}
	locate(0, y_size-2);
	return 0;
}
/* vim:ts=4:ai
 */