Yesterday, the problem of rain was finally completed. There is a preliminary understanding of some of the functions in Graphics.h. I think this program I have designed is a multi-threaded procedure, because two raindrops are independent of each other and does not affect each other. This is put in an array implementation. The current problem is that if the interval time setting is relatively short, the animation is smooth, but there is a flashing feel. This is also brought about by all programming language, how to solve it, is indeed a problem.
Rear at home:
#include
#define pi 3.1415926
#define RAINDROPLEN 15 / * The length of a raindrop * / # define RAINTANGLE 0 / * The tangle of each raindrop * / # define RAINDROPZ 0 / * The internal of each raindrop * / # define RAINCOLOR white / * The color of each raindrop * / # define rainwaveelevel 40 / * the level of each Wave * / # define delayTime 2000 / * The in International of Each Flash of the Screen * /
/ * Calculate the next x, y of a raindrop * / # define raindropnextX (N, M) (INT) (RAINDROPLEN / M N) * SIN (Raintangle * (PI / 180))) # Define Raindropnexty (N, M) (INT) * COS (Raintangle * (PI / 180)))))
#define raindrops 100 / * The Total NumBers of RainDrops * /
Struct raust raindrop {int POSX; INT POSY; int State; / * The current state of raate; / * The current state of raindrop. 1 for raindrop. 2 for Wave. * / int WAVELEVEL; / * The current wave level * /};
void Init (struct raindrop * drops); void DrawDrops (struct raindrop * drops); / * Draw all the raindrops * / void CalDrops (struct raindrop * drops); / * Calculate the next raindrops position * /
INT main (void) {structure; int gDriver = detect, gmode, i = 0; INITGRAPH (& gDriver, & gmode, ""); / * init graphic mode * / init (drops); setbkcolor (0) While (! Kbhit ()) {clearDevice (); DrawDrops (DROPS); DelayTime; Caldrops (Drops);} return 0;}