[C++] 纯文本查看 复制代码
#include <graphics.h> //包含EGE的头文件
#include<bits/stdc++.h>
using namespace std;
PIMAGE Pimg1;
PIMAGE Pimg2;
#define PI 3.1415926
int width =800;
int height = 800;
int R=200;
int t_cnt;
struct dot{
float x;//x坐标
float y;//y坐标
float angle;//角度
float v;//角速度 每秒转多少度
float R;
int color;
}d[3];
void startup()//初始化 函数
{
initgraph(width,height,INIT_RENDERMANUAL); //初始化图形界面
setbkcolor(BLACK);//设置背景颜色为白色
setlinewidth(1);//设置线宽
setfillcolor(BLACK);//设置填充颜色为白色
setfont(25,0,"幼圆");//(字体高度,字体宽度(为0即为自适应),字形)设置字体为25,幼圆字体
setbkmode(TRANSPARENT); //设置文字背景色为透明(默认为有背景色)
Pimg1 = newimage(width, height);
Pimg2 = newimage(width, height);
// setcolor(YELLOW);
// circle(width/2, height/2, R);
d[1].R = 120;
d[1].x = width/2;
d[1].y = height/2-d[1].R;
d[1].v = 100;
d[2].R = 120;
d[2].x = width/2;
d[2].y = d[1].y-d[2].R;
d[2].v = 0.01*PI;
d[3].R = 44;
d[3].x = width/2;
d[3].y = d[2].y-d[3].R;
d[3].v = 444;
t_cnt = 0;
//line(0,height/2,line_len,height/2);
}
void update()
{
//d[1].v += 0.0001;
d[1].angle= fmod(d[1].angle+d[1].v,2*PI);
d[1].x = width/2 + d[1].R*sin(d[1].angle);
d[1].y = height/2- d[1].R*cos(d[1].angle);
d[2].angle= fmod(d[2].angle+d[2].v,2*PI);
d[2].x = d[1].x+d[2].R*sin(d[2].angle);//以上一个点为圆心
d[2].y = d[1].y-d[2].R*cos(d[2].angle);
d[3].angle= fmod(d[3].angle+d[3].v,2*PI);
d[3].x = d[2].x+d[3].R*sin(d[3].angle);
d[3].y = d[2].y-d[3].R*cos(d[3].angle);
t_cnt++;
}
void draw1(PIMAGE pimg)
{
//clearviewport(pimg);
cleardevice(pimg);
//setfillcolor(RED);//设置填充颜色为白色
//bar(0,0,800,800,pimg);
setcolor(CYAN,pimg); //设置画图线颜色
circle(width/2,height/2,d[1].R,pimg);
line(width/2,height/2,d[1].x,d[1].y,pimg);
circle(d[1].x,d[1].y,d[2].R,pimg);
line(d[1].x,d[1].y,d[2].x,d[2].y,pimg);
cleardevice();//?
putimage(0, 0, Pimg1, SRCPAINT);
//circle(d[2].x,d[2].y,d[3].R);
//line(d[2].x,d[2].y,d[3].x,d[3].y);
}
void draw2(PIMAGE pimg)
{
//cleardevice();
//line(width/2,height/2,d[1].x,d[1].y);
//circle(d[1].x,d[1].y,d[2].R);
//line(d[1].x,d[1].y,d[2].x,d[2].y);
//circle(d[2].x,d[2].y,d[3].R);
//line(d[2].x,d[2].y,d[3].x,d[3].y);
setcolor(YELLOW,pimg); //设置画图线颜色
circle(d[2].x,d[2].y,1,pimg);
putimage(0, 0, Pimg2, SRCPAINT);
}
int main()
{
startup();
while(1)
{
update();
draw1(Pimg1);
draw2(Pimg2);
//imagefilter_blurring(Pimg2, 0x0a, 0xff);
//缓存绘制到窗口,模式为(最终颜色 = 窗口像素颜色 Or 图像像素颜色), 这样颜色会叠加起来
Sleep(1);
}
getch(); //暂停,等待键盘按键
closegraph(); //关闭图形界面
return 0;
}