oga's tools
Rev. | 2b80abcdeb00aad07aa265bd434df3975aadbb9a |
---|---|
Size | 2,263 bytes |
Time | 2024-12-10 04:54:07 |
Author | hyperoga |
Log Message | add color() func
|
/*
* mexhat.c for terminal
*
* V0.10 2024/12/10 by oga.
*
* 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.10"
int x_size = 80;
int y_size = 39;
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)) {
printf("Mexican Hat ver %s\n", VER);
printf("usage : mexhat [-x <x_size>] [-y <y_size>] [-w <wait_time(ms)>] [-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");
exit(1);
}
if (!strncmp(b[i],"-v",2)) {
vf = 1;
continue;
}
if (!strcmp(b[i],"-nocls")) {
nocls = 1;
continue;
}
if (!strcmp(b[i],"-x")) {
x_size = atoi(b[++i]);
continue;
}
if (!strcmp(b[i],"-y")) {
y_size = atoi(b[++i]);
continue;
}
if (!strcmp(b[i],"-w")) {
wait = atoi(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(".\n");
if (wait) {
usleep(20*1000);
}
//fflush(stdout);
d[sx] = sy;
}
}
}
}
locate(0, y_size-2);
return 0;
}
/* vim: ts=4:ai
*/