Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Want to make computer graphics demos, but don't know how to open a window? Don't have time to learn?
- Use greyscale CLI graphics!
- Here are 2 grey scales that work well on the terminal:
- char greyscale[] = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\\|()1{}[]?-_+~<>i!lI;:,\"^`'. ";
- char short_greyscale[] = " .:-=+*#%@";
- The larger greyscale is better for very detailed images while the short greyscale is more convincing.
- Simply make your demo output a floating point number between 0 and 1 for every position, multiply it by strlen(greyscale), shorten it to an int and use it as an index to the array of characters. Write it out with printf() or std::cout if you're using C++. I recommend pushing out all lines of your graphics at once, by creating an array to hold your screen. Allocate it like this:
- char screen[(screen_width + 1) * (screen_height) + 1];
- Initialize it like this:
- screen[(screen_width + 1) * (screen_height)] = '\0';
- for(int y = 0; y < screen_height; y++)
- {
- screen[screen_width + (screen_width + 1) * y] = '\n';
- }
- When you want to write a float VAL which is between 0 and 1 to position (X, Y) in the screen, write to it like this:
- screen[X + (screen_width + 1) * Y] = greyscale[VAL * (strlen(greyscale) - 1)];
- Print it like this:
- printf("\n%s",screen);
- Or this:
- std::cout << "\n" << screen << std::endl;
- You now have everything you need to make amazing things using only ANSI C on the terminal. Go forth, and make me proud!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement