Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <curses.h>
- #include <stdlib.h>
- #include <unistd.h>
- #define MAXX 80 /* Numero di colonne dello schermo */
- #define MAXY 24 /* Numero di righe dello schermo */
- #define PASSO 1
- #define SPEED 500000
- #define N 2
- struct pos {
- char c;
- int x; /* coordinata x */
- int y; /* coordinata y */
- };
- void* print_xs (void* parameters){
- int r;
- int dx, dy;
- struct pos* p;
- p = (struct pos*) parameters;
- while (1){
- r=random();
- if(r<RAND_MAX/2)
- dx=PASSO;
- else
- dx=-PASSO;
- if(p->x+dx<1 || p->x+dx>=MAXX)
- dx=-dx;
- p->x+=dx;
- r=random();
- if(r<RAND_MAX/2)
- dy=PASSO;
- else
- dy=-PASSO;
- if(p->y+dy<1 || p->y+dy>=MAXY)
- dy=-dy;
- p->y+=dy;
- mvaddch(p->y,p->x,p->c);
- refresh();
- usleep(SPEED);
- mvaddch(p->y,p->x,' ');
- }
- return NULL;
- }
- int main () {
- pthread_t thread1_id;
- struct pos thread1_args;
- initscr();
- noecho();
- curs_set(0);
- thread1_args.c = random();
- thread1_args.x = random()%MAXX;
- thread1_args.y = random()%MAXY;
- pthread_create (&thread1_id, NULL, &print_xs, &thread1_args);
- pthread_join (thread1_id, NULL);
- endwin();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement