Created
May 11, 2014 04:49
-
-
Save jerstlouis/7c3aecbe2f770469a17d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) | |
{ | |
int yc = inverted ? h-1-y : y; | |
int l = (int)sqrt((w * w + h * h) * (yc * yc) / (h * h) - (yc * yc)); | |
if(filled || yc == 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