[C] 在指定位置画一像素 →→→→→进入此内容的聊天室

来自 , 2019-03-14, 写在 C, 查看 163 次.
URL http://www.code666.cn/view/ccbd8ca9
  1. #include <graphics.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <dos.h>
  6.  
  7. #define PIXEL_COUNT 1000
  8. #define DELAY_TIME  100  /* in milliseconds */
  9.  
  10. int main(void)
  11. {
  12.    /* request autodetection */
  13.    int gdriver = DETECT, gmode, errorcode;
  14.    int i, x, y, color, maxx, maxy, maxcolor, seed;
  15.  
  16.    /* initialize graphics and local variables */
  17.    initgraph(&gdriver, &gmode, "");
  18.  
  19.    /* read result of initialization */
  20.    errorcode = graphresult();
  21.    if (errorcode != grOk)  /* an error occurred */
  22.    {
  23.       printf("Graphics error: %s\n", grapherrormsg(errorcode));
  24.       printf("Press any key to halt:");
  25.       getch();
  26.       exit(1); /* terminate with an error code */
  27.    }
  28.  
  29.    maxx = getmaxx() + 1;
  30.    maxy = getmaxy() + 1;
  31.    maxcolor = getmaxcolor() + 1;
  32.  
  33.    while (!kbhit())
  34.    {
  35.       /* seed the random number generator */
  36.       seed = random(32767);
  37.       srand(seed);
  38.       for (i=0; i<PIXEL_COUNT; i++)
  39.       {
  40.   x = random(maxx);
  41.          y = random(maxy);
  42.          color = random(maxcolor);
  43.          putpixel(x, y, color);
  44.       }
  45.  
  46.       delay(DELAY_TIME);
  47.       srand(seed);
  48.       for (i=0; i<PIXEL_COUNT; i++)
  49.       {
  50.   x = random(maxx);
  51.   y = random(maxy);
  52.   color = random(maxcolor);
  53.   if (color == getpixel(x, y))
  54.      putpixel(x, y, 0);
  55.       }
  56.    }
  57.  
  58.    /* clean up */
  59.    getch();
  60.    closegraph();
  61.    return 0;
  62. }

回复 "在指定位置画一像素"

这儿你可以回复上面这条便签

captcha