Advertisement
Arusekk

paint.cpp

Oct 17th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1. #include <cstdio>
  2. #include "conio.h"
  3. #ifdef __WIN32
  4. #include <windows.h>
  5. #include <conio.h>
  6. #endif
  7.  
  8. // program to design drawings
  9. // writes the output to obrazek.h
  10. // You move through screen using capital WSAD, by Enter you change colors
  11. // then you can press lowercase q to save the output to obrazek.h
  12.  
  13. void setcolor(unsigned short int color) {
  14.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
  15. }
  16.  
  17. const int WIDTH=79, HEIGHT=20;
  18.  
  19. int main() {
  20.   char c;
  21.   int i, idx = 0, j, i2, j2;
  22.   unsigned short color = 143;
  23.   bool coloring = false;
  24.   char ekran[HEIGHT][WIDTH];
  25.   short ekran2[HEIGHT][WIDTH];
  26.   COORD poz;
  27.   for (i=0; i<HEIGHT; i++)
  28.     for (j=0; j<WIDTH; j++) {
  29.       ekran[i][j]=' ';
  30.       ekran2[i][j]=135;
  31.     }
  32.   i=j=0;
  33.   for (;;) {
  34.     setcolor(7);
  35.     printf(" \n");
  36. #ifdef __WIN32
  37.     system("cls");
  38. #else
  39.     fprintf(stdout, "\x1b[H\x1b[J");
  40.     fflush(stdout);
  41. #endif
  42.     printf("%hu\n", color);
  43.     for (i2=0; i2<16; i2++) {
  44.       if (i2 == idx && coloring)
  45.     setcolor(112);
  46.       else
  47.     setcolor(7);
  48.       if (color&(1<<i2))
  49.     printf("%x", i2);
  50.       else
  51.     printf("_");
  52.     }
  53.     setcolor(color);
  54.     printf("\nnapis\n");
  55.     setcolor(7);
  56.     printf(" \n");
  57.  
  58.     for (i2=0; i2<HEIGHT; i2++) {
  59.       for (j2=0; j2<WIDTH; j2++) {
  60.     setcolor(ekran2[i2][j2]);
  61.     printf("%c", ekran[i2][j2]);
  62.       }
  63.       setcolor(7);
  64.       printf(" \n");
  65.     }
  66.     poz.X=j;
  67.     poz.Y=i+4;
  68.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), poz);
  69. //     printf("%c", c);
  70.     c = _getch();
  71.     if (c==13 || c==10) { coloring^=1; continue; }
  72.     if (coloring) {
  73.       if (c == 'a')
  74.     idx--;
  75.       if (c == 'd')
  76.     idx++;
  77.       idx &= 15;
  78.       if (c == 'e')
  79.     color ^= (1 << idx);
  80.       if (c == 'q') {
  81.     FILE* fp = fopen("obrazek.h","w");
  82.     fprintf(fp, "const char* obrazek[] = {\n");
  83.     for (i=0; i<HEIGHT; i++) {
  84.       fprintf(fp, "  \"");
  85.       for (j=0; j<WIDTH; j++)
  86.         if (ekran[i][j] < ' ' || ekran[i][j]=='\\')
  87.           fprintf(fp, "\\x%02x", ekran[i][j]);
  88.         else
  89.           fprintf(fp, "%c", ekran[i][j]);
  90.       fprintf(fp, "\",\n");
  91.     }
  92.     fprintf(fp, "};\n");
  93.     fprintf(fp, "const char* obrazek_c[] = {\n");
  94.     for (i=0; i<HEIGHT; i++) {
  95.       fprintf(fp, "  \"");
  96.       for (j=0; j<WIDTH; j++)
  97.         if (ekran2[i][j] < ' ' || ekran2[i][j]=='\\')
  98.           fprintf(fp, "\\x%02x", ekran2[i][j]);
  99.         else
  100.           fprintf(fp, "%c", ekran2[i][j]&255);
  101.       fprintf(fp, "\",\n");
  102.     }
  103.     fprintf(fp, "};\n");
  104.     fclose(fp);
  105.       }
  106.     }
  107.     else {
  108.       if (c=='\t' || c=='\v') c=' ';
  109.       if (c=='W') i--;
  110.       else if (c=='S') i++;
  111.       else if (c=='A') j--;
  112.       else if (c=='D') j++;
  113.       else {
  114.     ekran2[i][j]=color;
  115.     ekran[i][j++]=c;
  116.     if (j>WIDTH)
  117.       i++;
  118.       }
  119.       i=(i+HEIGHT)%HEIGHT;
  120.       j=(j+WIDTH)%WIDTH;
  121.     }
  122.   }
  123. #ifdef __WIN32
  124.   system("cls");
  125. #else
  126.   fprintf(stdout, "\x1b[H\x1b[J");
  127.   fflush(stdout);
  128. #endif
  129.   setcolor(7);
  130.   _getch();
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement