星空(C语言)

标签:
it教育 |
分类: 程序 |
#include "acllib.h"
#include "math.h"
#include“stdio.h”
#include“time.h”
void star(double s, int x, int y)
{
double SR1 = s * sin(72), SR2 = s * sin(54),
CR1 = s * cos(72), CR2 = s * cos(54);
int xA = x, yA = y - s;
int xB = x + CR1, yB = y - SR1;
int xC = x + SR2, yC = y - CR2;
int xD = x - SR2, yD = y - CR2;
int xE = x - CR1, yE = y - SR1;
line(xA, yA, xC, yC);
line(xC, yC, xE, yE);
line(xE, yE, xB, yB);
line(xB, yB, xD, yD);
line(xD, yD, xA, yA);
}
void timer()
{
int i;
beginPaint();
setPenColor(BLACK);
setBrushColor(BLACK);
rectangle(0, 0, 640, 480);
srand((unsigned)time(NULL));
for (i = 0; i < 80;i++)
{
int R = rand() % 255;
int G = rand() % 255;
int B = rand() % 255;
int X = rand() % 640;
int Y = rand() % 480;
setPenColor(RGB(R, G, B));
star(rand() % 30, X, Y);
}
endPaint();
}
int Setup()
{
initWindow("星空", DEFAULT, DEFAULT, 640, 480);
registerTimerEvent(timer);
startTimer(0, 1000);
return 0;
}