{"id":7,"date":"2004-07-01T11:17:50","date_gmt":"2004-07-01T15:17:50","guid":{"rendered":"http:\/\/www.hongliangjie.com\/blog\/?p=7"},"modified":"2008-05-31T23:01:30","modified_gmt":"2008-06-01T03:01:30","slug":"c-problem","status":"publish","type":"post","link":"https:\/\/www.hongliangjie.com\/blog\/2004\/07\/01\/c-problem\/","title":{"rendered":"C\u8bed\u8a00\u7684\u95ee\u9898"},"content":{"rendered":"<p>\u6628\u5929\u628a\u4e0b\u96e8\u7684\u9898\u7ec8\u4e8e\u7f16\u5b8c\u4e86\u3002\u5bf9Graphics.h\u91cc\u9762\u7684\u4e00\u4e9b\u51fd\u6570\u6709\u4e86\u4e00\u4e2a\u521d\u6b65\u7684\u4e86\u89e3\u3002\u6211\u89c9\u5f97\u6211\u8bbe\u8ba1\u7684\u8fd9\u4e2a\u7a0b\u5e8f\u662f\u4e00\u79cd\u591a\u7ebf\u7a0b\u7684\u7a0b\u5e8f\u7684\u96cf\u5f62\uff0c\u56e0\u4e3a\u4e24\u4e2a\u96e8\u6ef4\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u4e92\u4e0d\u5f71\u54cd\u3002\u8fd9\u662f\u653e\u5728\u4e00\u4e2a\u6570\u7ec4\u91cc\u9762\u5b9e\u73b0\u7684\u3002\u76ee\u524d\u7684\u95ee\u9898\u662f\u5982\u679c\u628a\u95f4\u9694\u65f6\u95f4\u8bbe\u7f6e\u7684\u76f8\u5bf9\u77ed\u4e9b\u7684\u8bdd\uff0c\u52a8\u753b\u8981\u5149\u6ed1\u4e9b\uff0c\u4f46\u662f\u6709\u95ea\u70c1\u7684\u611f\u89c9\u3002\u8fd9\u4e5f\u662f\u6240\u6709\u7f16\u7a0b\u8bed\u8a00\u7684\u64e6\u576a\u51fd\u6570\u6240\u5e26\u6765\u7684\uff0c\u600e\u4e48\u89e3\u51b3\uff0c\u786e\u5b9e\u662f\u4e00\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u9644\u4e0a\u6e90\u7a0b\u5e8f: <\/p>\n<pre lang=\"c\" line=\"1\">\r\n#include <stdio.h>\r\n#include <math.h>\r\n#include <graphics.h>\r\n#include <stdlib.h>\r\n#include <time.h>\r\n#include <dos.h>\r\n#include <conio.h>\r\n\r\n#define PI 3.1415926\r\n\r\n#define RAINDROPLEN 15 \/*  The length of a raindrop *\/\r\n#define RAINTANGLE 0 \/*  The tangle of each raindrop *\/\r\n#define RAINDROPZ 0  \/* The internal of each raindrop *\/\r\n#define RAINCOLOR white \/* The color of each raindrop *\/\r\n#define RAINWAVELEVEL 40 \/* The level of each wave *\/\r\n#define DELAYTIME 2000 \/* The internal of each flash of the screen *\/\r\n\r\n\/* Calculate the next X,Y of a raindrop *\/\r\n#define RAINDROPNEXTX(n,m) (int)((RAINDROPLEN\/m+n)*sin(RAINTANGLE*(PI\/180)))\r\n#define RAINDROPNEXTY(n,m) (int)((RAINDROPLEN\/m+n)*cos(RAINTANGLE*(PI\/180)))\r\n\r\n#define RAINDROPS 100 \/*  The total numbers of raindrops *\/\r\n\r\n \r\n\r\nstruct raindrop\r\n{\r\n int posx;\r\n int posy;\r\n int state; \/* The current state of raindrop. 1 for raindrop. 2 for wave. *\/\r\n int wavelevel; \/* The current wave level *\/\r\n};\r\n\r\nvoid Init(struct raindrop *drops);\r\nvoid DrawDrops(struct raindrop *drops); \/* Draw all the raindrops *\/\r\nvoid CalDrops(struct raindrop *drops); \/* Calculate the next raindrops position *\/\r\n\r\n \r\n\r\nint main(void)\r\n{\r\n struct raindrop drops[RAINDROPS];\r\n int gdriver=DETECT,gmode,i=0;\r\n initgraph(&gdriver,&gmode,\"\"); \/* Init graphic mode *\/\r\n Init(drops);\r\n setbkcolor(0);\r\n while(!kbhit())\r\n {\r\n  cleardevice();\r\n  DrawDrops(drops);\r\n  delay(DELAYTIME);\r\n  CalDrops(drops);\r\n }\r\n return 0;\r\n}\r\n\r\n\r\nvoid Init(struct raindrop *drops)\r\n{\r\n int i;\r\n randomize();\r\n for(i=0;i<RAINDROPS;i++,drops++)\r\n {\r\n  drops->posx=random(600);\r\n  drops->posy=random(300);\r\n  drops->state=1;\r\n  drops->wavelevel=0;\r\n }\r\n}\r\n\r\nvoid DrawDrops(struct raindrop *drops)\r\n{\r\n int i;\r\n int endx,endy;\r\n setcolor(WHITE);\r\n for(i=0;i<RAINDROPS;i++,drops++)\r\n {\r\n  if (drops->state==1)\r\n  {\r\n   endx=RAINDROPNEXTX(0,1);\r\n   endy=RAINDROPNEXTY(0,1);\r\n   line(drops->posx,drops->posy,drops->posx+endx,drops->posy+endy);\r\n  }\r\n  else\r\n  {\r\n\r\n    ellipse(drops->posx,drops->posy,0,360,1+(drops->wavelevel)*0.75,0.05+(drops->wavelevel)*0.15);\r\n  }\r\n }\r\n}\r\n\r\nvoid CalDrops(struct raindrop *drops)\r\n{\r\n int i;\r\n int endx,endy;\r\n int temp;\r\n for(i=0;i<RAINDROPS;i++,drops++)\r\n {\r\n  if (drops->state==1)\r\n  {\r\n   endx=RAINDROPNEXTX(RAINDROPZ,10);\r\n   endy=RAINDROPNEXTY(RAINDROPZ,10);\r\n   if ((endx+drops->posx)>=640||(endy+drops->posy)>=400)\r\n   {\r\n    temp=random(100);\r\n    if (temp%2==0||(endx+drops->posx)>=680||(endy+drops->posy)>=550)\r\n    {\r\n     drops->state=2;\r\n     drops->wavelevel=1;\r\n    }\r\n    else\r\n    {\r\n     drops->posx=drops->posx+endx;\r\n     drops->posy=drops->posy+endy;\r\n    }\r\n\r\n   }\r\n   else\r\n   {\r\n    drops->posx=drops->posx+endx;\r\n    drops->posy=drops->posy+endy;\r\n   }\r\n  }\r\n  else\r\n  {\r\n   if ((drops->wavelevel)<RAINWAVELEVEL)\r\n   {\r\n\r\n     drops->wavelevel++;\r\n   }\r\n   else\r\n   {\r\n    drops->posx=random(600);\r\n    drops->posy=random(100);\r\n    drops->wavelevel=0;\r\n    drops->state=1;\r\n   }\r\n  }\r\n }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6628\u5929\u628a\u4e0b\u96e8\u7684\u9898\u7ec8\u4e8e\u7f16\u5b8c\u4e86\u3002\u5bf9Graphics.h\u91cc\u9762\u7684\u4e00\u4e9b\u51fd\u6570\u6709\u4e86\u4e00\u4e2a\u521d\u6b65\u7684\u4e86\u89e3\u3002\u6211\u89c9\u5f97\u6211\u8bbe\u8ba1\u7684\u8fd9\u4e2a\u7a0b\u5e8f\u662f\u4e00\u79cd\u591a\u7ebf\u7a0b\u7684\u7a0b\u5e8f\u7684\u96cf\u5f62\uff0c\u56e0\u4e3a\u4e24\u4e2a\u96e8\u6ef4\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u4e92\u4e0d\u5f71\u54cd\u3002\u8fd9\u662f\u653e\u5728\u4e00\u4e2a\u6570\u7ec4\u91cc\u9762\u5b9e\u73b0\u7684\u3002\u76ee\u524d\u7684\u95ee\u9898\u662f\u5982\u679c\u628a\u95f4\u9694\u65f6\u95f4\u8bbe\u7f6e\u7684\u76f8\u5bf9\u77ed\u4e9b\u7684\u8bdd\uff0c\u52a8\u753b\u8981\u5149\u6ed1\u4e9b\uff0c\u4f46\u662f\u6709\u95ea\u70c1\u7684\u611f\u89c9\u3002\u8fd9\u4e5f\u662f\u6240\u6709\u7f16\u7a0b\u8bed\u8a00\u7684\u64e6\u576a\u51fd\u6570\u6240\u5e26\u6765\u7684\uff0c\u600e\u4e48\u89e3\u51b3\uff0c\u786e\u5b9e\u662f\u4e00\u4e2a\u95ee\u9898\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[8],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-thinking-on-the-keyboard","tag-8"],"_links":{"self":[{"href":"https:\/\/www.hongliangjie.com\/blog\/wp-json\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongliangjie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongliangjie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongliangjie.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongliangjie.com\/blog\/wp-json\/wp\/v2\/comments?post=7"}],"version-history":[{"count":0,"href":"https:\/\/www.hongliangjie.com\/blog\/wp-json\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hongliangjie.com\/blog\/wp-json\/wp\/v2\/media?parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongliangjie.com\/blog\/wp-json\/wp\/v2\/categories?post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongliangjie.com\/blog\/wp-json\/wp\/v2\/tags?post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}