Skip to content

Instantly share code, notes, and snippets.

@jerstlouis
Created May 11, 2014 05:09
Show Gist options
  • Save jerstlouis/4d038195055a5b86a1e4 to your computer and use it in GitHub Desktop.
Save jerstlouis/4d038195055a5b86a1e4 to your computer and use it in GitHub Desktop.
import "ecere"
class TriApp : Application
{
ConsoleFile f { };
void Main()
{
int w = 50;
int h = 20;
bool filled = false, inverted = false;
int x, y;
int i;
bool valid = true;
for(i = 1; i<argc; i++)
{
char * arg = argv[i];
if(arg[0] == '-')
{
if(!strcmp(arg + 1, "filled")) filled = true;
else if(!strcmp(arg + 1, "invert")) inverted = true;
else if(!strcmp(arg+1, "w") || !strcmp(arg+1, "h"))
{
if(i + 1 < argc && argv[i+1][0] != '-')
{
int v = atoi(argv[i+1]);
if(v < 1) valid = false;
else if(!strcmp(arg+1, "w"))
w = v;
else
h = v;
i++;
}
else
valid = false;
}
}
else
valid = false;
}
if(!valid)
printf($"Syntax:\n asciiTriangle [-w <width>] [-h <height>] [-invert] [-filled]\n");
else
{
for(y = 0; y < h; y++)
{
double yc = (inverted ? h-1-y : y) + 0.5;
double l = sqrt((double)(w * w + h * h) * (yc * yc) / (h * h) - (yc * yc));
if(filled || y == h-1)
{
for(x = 0; x <= l; x++)
f.Putc('*');
}
else
{
f.Putc('*');
if(l > 1)
{
for(x = 1; x <= l-1; x++)
f.Putc(' ');
f.Putc('*');
}
}
f.Putc('\n');
}
}
system("pause");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment