1 Star 0 Fork 0

张小三/ComputerGraphics

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
drawPoly__example_190711.cpp 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
贱人张 提交于 2019-07-11 22:16 . blur
#include <graphics.h>
#include <cmath>
#include <ctime>
const double pi = 3.14159265;
void drawPloy (int x = ege::getwidth () / 2, int y = ege::getheight () / 2,
int n = 3, int r = 100, double R = 0.0) {
int x1 = x + r * sin (R);
int y1 = y + r * cos (R);
// 第一条边的起点
int x2, y2;
for (int i = 0; i <= n; i ++) {
double deviation = R + i*(2*pi/n);
// 偏差角度
x2 = x + r * sin (deviation);
y2 = y + r * cos (deviation);
// 计算新的坐标
line (x1, y1, x2, y2);
// 画线
x1 = x2; y1 = y2;
}
}
int main () {
ege::setinitmode (INIT_RENDERMANUAL);
// 设定更新方式为手动更新
ege::initgraph (800, 800);
double x = 400, y = 400, n = 3, r = 100, R = 0;
// 原始坐标(初始化用)
double nx, ny, nn, nr, nR;
// 新的坐标
int timer = 0; // 计时器
const int second = 2; // 一次动画持续的时间
const int fps = 60; // 帧率
srand (time (NULL));
for (;ege::is_run (); delay_fps (fps)) {
ege::cleardevice ();
if (timer % (fps * second) == 0) {
nx = rand () % 800; // x 坐标
ny = rand () % 800; // y 坐标
nn = rand () % 20; // 边数
nr = rand () % 400; // 半径
nR = rand () / 1000; // 旋转角度
}
timer = timer + 1;
x += (nx - x) / (fps * second);
y += (ny - y) / (fps * second);
n += (nn - n) / (fps * second);
r += (nr - r) / (fps * second);
R += (nR - R) / (fps * second);
// 进行渐变
// ege::floodfillsurface (x, y, EGERGB (0, 0, 0));
// 内部填充,以线条颜色为依据
drawPloy (x, y, n, r, R);
// ege::imagefilter_blurring(NULL, 0x60, 0xff);
// 去掉 cleardevice 运行这句
}
ege::getch ();
ege::closegraph ();
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/TheBadZhang/ComputerGraphics.git
git@gitee.com:TheBadZhang/ComputerGraphics.git
TheBadZhang
ComputerGraphics
ComputerGraphics
master

搜索帮助