#include "stdafx.h"
#include "iostream"
#include "vector"
#include "algorithm"
#include "GL/glut.h"
#define color_0 color(0,0,0)
#define color_1 color(0.25,0.9,0.8)
#define color_2 color(0.15,0.8,0.6)
#define color_3 color(1,0,0)
#define color_4 color(0,0,1)
#define color_5 color(1,1,0)
using namespace std;
const unsigned int maxn = 700;
int win_width = 700;
int win_hight = 700;
int flag[maxn]; //用于标记边那些特定的 要y-1的点
int visit[maxn]; //用于在寻找 特定点 时 标记删除掉的点
int point_amount = 0; //顶点的个数(边的个数)
int Point[maxn][2];
int EDGE_PRO[maxn][2][2]; //没有处理的边
int minx_y = INT_MAX;
int setpoint_[maxn][maxn];
struct edge {
float y2;
float x1;
float m;
edge *next;
friend bool operator <(const edge&e1, const edge&e2) {
return e1.x1 < e2.x1;
}
}; //用vector 构建活化边表
edge *edge_table[maxn]; // edge_table
struct node {
int x, y;
node(int a, int b) {
x = a, y = b;
}
};
int ans = 0;
int time = 0;
int keytime = 0;
int time3 = 0;
float x1, y1_, x2, y2; //划线算法的 两个端点
float x3, y3, x4, y4, x5, y5, xmove0, ymove0, xmove1, ymove1;
float xr3, yr3;
float r1, c1, r2, c2;
int rx, ry; //画圆算法 中的长轴 短轴
int xc, yc; //画圆算法 中的中心坐标
int time_mouse_3 = 0;
int xpro, ypro;
int r;
float sf = 1;
int asn = 0;
bool determine = false;
bool check = true;
class color {
public:
float r, g, b;
color(float r_, float g_, float b_) {
r = r_, g = g_, b = b_;
}
color() {};
};
class screen
{
private:
color p[maxn][maxn];
int hight;
int width;
int length;
int xo, yo;
public:
screen(int a, int b, int c, int d, int e);
void initscreen();
void setpoint(int x, int y, color rgb);
void reviselength(int x); //修改方格的长度
int getlength();
void newxoyo(int x, int y); //修改方格左下角的x,y
int getxo();
int getyo();
int mapped_x(int x);
int mapped_y(int y);
void show();
void filling(int a, int b, int c);
};
screen::screen(int a, int b, int c, int d, int e) {
hight = a, width = b, length = c, xo = d, yo = e;
for (int i = 0; i < width; i++)
for (int j = 0; j < hight; j++) {
p[i][j] = color_0;
}
}
int screen::getlength() {
return length;
}
void screen::initscreen() {
memset(setpoint_, 0, sizeof setpoint_);
for (int i = 0; i < width; i++)
for (int j = 0; j < hight; j++) {
p[i][j] = color_0;
}
}
void screen::setpoint(int x, int y, color rgb) {
if (x < 0 || y < 0 || x >= win_width || y >= win_hight)
return;
p[x][y] = rgb;
}
void screen::reviselength(int x) {
length = length + x;
}
void screen::newxoyo(int x, int y) {
xo = x;
yo = y;
}
int screen::getxo() {
return xo;
}
int screen::getyo() {
return yo;
}
int screen::mapped_x(int x) {
return int(float(x - xo) / float(length));
}
int screen::mapped_y(int y) {
return int(float(700 - y - yo) / float(length));
}
void screen::show() {
glColor3f(0.5, 0.5, 0.5);
glBegin(GL_QUADS);
glVertex2i(xo, yo);
glVertex2i(xo, yo + hight*length);
glVertex2i(xo + width*length, yo + hight*length);
glVertex2i(xo + width*length, yo);
glEnd();
glFlush();
glColor3f(0.4, 0.6, 0.7);
glBegin(GL_LINES);
for (int i = 0; i <= hight; i++) {
glVertex2i(xo, yo + i*length);
glVertex2i(xo + width*length, yo + i*length);
}
for (int i = 0; i <= width; i++) {
glVertex2i(xo + i*length, yo);
glVertex2i(xo + i*length, yo + hight*length);
}
glEnd();
glFlush();
glBegin(GL_QUA
OPengl 方格程序
最新推荐文章于 2023-04-14 10:54:14 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)