Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include "conio.h"
- #ifdef __WIN32
- #include <windows.h>
- #include <conio.h>
- #endif
- // program to design drawings
- // writes the output to obrazek.h
- // You move through screen using capital WSAD, by Enter you change colors
- // then you can press lowercase q to save the output to obrazek.h
- void setcolor(unsigned short int color) {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
- }
- const int WIDTH=79, HEIGHT=20;
- int main() {
- char c;
- int i, idx = 0, j, i2, j2;
- unsigned short color = 143;
- bool coloring = false;
- char ekran[HEIGHT][WIDTH];
- short ekran2[HEIGHT][WIDTH];
- COORD poz;
- for (i=0; i<HEIGHT; i++)
- for (j=0; j<WIDTH; j++) {
- ekran[i][j]=' ';
- ekran2[i][j]=135;
- }
- i=j=0;
- for (;;) {
- setcolor(7);
- printf(" \n");
- #ifdef __WIN32
- system("cls");
- #else
- fprintf(stdout, "\x1b[H\x1b[J");
- fflush(stdout);
- #endif
- printf("%hu\n", color);
- for (i2=0; i2<16; i2++) {
- if (i2 == idx && coloring)
- setcolor(112);
- else
- setcolor(7);
- if (color&(1<<i2))
- printf("%x", i2);
- else
- printf("_");
- }
- setcolor(color);
- printf("\nnapis\n");
- setcolor(7);
- printf(" \n");
- for (i2=0; i2<HEIGHT; i2++) {
- for (j2=0; j2<WIDTH; j2++) {
- setcolor(ekran2[i2][j2]);
- printf("%c", ekran[i2][j2]);
- }
- setcolor(7);
- printf(" \n");
- }
- poz.X=j;
- poz.Y=i+4;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), poz);
- // printf("%c", c);
- c = _getch();
- if (c==13 || c==10) { coloring^=1; continue; }
- if (coloring) {
- if (c == 'a')
- idx--;
- if (c == 'd')
- idx++;
- idx &= 15;
- if (c == 'e')
- color ^= (1 << idx);
- if (c == 'q') {
- FILE* fp = fopen("obrazek.h","w");
- fprintf(fp, "const char* obrazek[] = {\n");
- for (i=0; i<HEIGHT; i++) {
- fprintf(fp, " \"");
- for (j=0; j<WIDTH; j++)
- if (ekran[i][j] < ' ' || ekran[i][j]=='\\')
- fprintf(fp, "\\x%02x", ekran[i][j]);
- else
- fprintf(fp, "%c", ekran[i][j]);
- fprintf(fp, "\",\n");
- }
- fprintf(fp, "};\n");
- fprintf(fp, "const char* obrazek_c[] = {\n");
- for (i=0; i<HEIGHT; i++) {
- fprintf(fp, " \"");
- for (j=0; j<WIDTH; j++)
- if (ekran2[i][j] < ' ' || ekran2[i][j]=='\\')
- fprintf(fp, "\\x%02x", ekran2[i][j]);
- else
- fprintf(fp, "%c", ekran2[i][j]&255);
- fprintf(fp, "\",\n");
- }
- fprintf(fp, "};\n");
- fclose(fp);
- }
- }
- else {
- if (c=='\t' || c=='\v') c=' ';
- if (c=='W') i--;
- else if (c=='S') i++;
- else if (c=='A') j--;
- else if (c=='D') j++;
- else {
- ekran2[i][j]=color;
- ekran[i][j++]=c;
- if (j>WIDTH)
- i++;
- }
- i=(i+HEIGHT)%HEIGHT;
- j=(j+WIDTH)%WIDTH;
- }
- }
- #ifdef __WIN32
- system("cls");
- #else
- fprintf(stdout, "\x1b[H\x1b[J");
- fflush(stdout);
- #endif
- setcolor(7);
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement