peon125

Untitled

Sep 24th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pthread.h>
  4. #define world_x_size 53
  5. #define world_y_size 50
  6.  
  7. struct Pixel
  8. {
  9.     char what_here;
  10. };
  11.  
  12. typedef struct Pixel pixelsArr[world_x_size];
  13.  
  14. void create_world(pixelsArr *pixels)
  15. {
  16.     int x = 0;
  17.     int y = 0;
  18.     while (y < world_y_size)
  19.     {
  20.         x = 0;
  21.         while (x < world_x_size)
  22.         {
  23.             pixels[x][y].what_here = 'O';
  24.  
  25.             x++;
  26.         }
  27.  
  28.         y++;
  29.     }
  30. }
  31.  
  32. void update_thread(pixelsArr *pixels)
  33. {
  34.     while(1)
  35.     {
  36.         int x = 0;
  37.         int y = 0;
  38.         while (y < world_y_size)
  39.         {
  40.             char output[world_x_size + 1];
  41.             x = 0;
  42.             while (x < world_x_size)
  43.             {
  44.                 output[x] = pixels[x][y].what_here;
  45.  
  46.                 x++;
  47.             }
  48.  
  49.             y++;
  50.             printf(output);
  51.             printf("\n");
  52.         }
  53.         printf('\033c');
  54.     }
  55.  
  56.     return NULL;
  57. }
  58. int main()
  59. {
  60.     pixelsArr pixels[world_y_size];
  61.  
  62.     create_world(pixels);
  63.  
  64.     pthread_t thread;
  65.     pthread_create(&thread, NULL, update_thread, pixels);
  66.     pthread_join(thread, NULL);
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment