Advertisement
pierrotdu18

Untitled

Aug 19th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. void drawPolygon(uint8_t r, uint8_t g, uint8_t b, int nombreDePoints, ...)
  2. // r, g, b, <number of points you want (4 for a square, for instance, not 8 because of x and y...)>, <x1,y1,x2,y2...>
  3. {
  4.     // the number of arguments in the <...> must be even
  5.     int i;
  6.     int* pointsList = (int*)malloc(nombreDePoints*2*sizeof(int));
  7.    
  8.     va_list ap;
  9.     int cur_arg = 1;
  10.  
  11.     va_start(ap, nombreDePoints);
  12.    
  13.     for (i = 0; i < nombreDePoints*2; i++)
  14.     {
  15.         cur_arg = va_arg(ap, int);
  16.         *(pointsList + i) = cur_arg;
  17.     }
  18.    
  19.     for (i = 0; i < nombreDePoints*2 - 2; i+=2)
  20.     {
  21.         drawLine(*(pointsList + i), *(pointsList + i + 1), *(pointsList + i + 2), *(pointsList + i + 3), r, g, b);
  22.     }
  23.     drawLine(*(pointsList + nombreDePoints*2 - 2), *(pointsList + nombreDePoints*2 - 1), *(pointsList), *(pointsList + 1), r, g, b);
  24.     va_end(ap);
  25.     free(pointsList);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement