#include "GL/glut.h"
#include <stdio.h>
#include<windows.h>
#define MAX_POINT_NUM 20
int a[MAX_POINT_NUM][2],judge[MAX_POINT_NUM][2];
int i=0,j;
int sign[30][30];
void init(void)
{
glClearColor(1.0,1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 600.0, 0.0, 600.0);
glPointSize(20.0);//点的大小
}
void plotpoint(int x,int y)
{
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void displayFcn()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0,0.0,0.0);
for(i=0;i<600;i+=20)
{glBegin(GL_LINES);
glVertex2i(0,i);
glVertex2i(600,i);
glEnd();
}
for(i=0;i<600;i+=20)
{
glColor3f(0.0,0.0,0.0);
glBegin(GL_LINES);
glVertex2i(i,0);
glVertex2i(i,600);
glEnd();
}
glFlush();
}
void boundaryFill4(int x,int y)
{
if(x>0&&x<600&&y>0&&y<600)
if((sign[x/20][y/20]!=0)&&(sign[x/20][y/20]!=1))
{
glColor3f(0.0,1.0,0.0);
plotpoint(x,y);
sign[x/20][y/20]=0;
boundaryFill4(x+20,y);
boundaryFill4(x-20,y);
boundaryFill4(x,y+20);
boundaryFill4(x,y-20);
}
}
void mouse(GLint button, GLint action, GLint x,GLint y)
{y=600-y;
x=x/20*20+10;
y=y/20*20+10;
if (button==GLUT_LEFT_BUTTON && action==GLUT_DOWN)
{
glColor3f(1.0,0.0,0.0);
plotpoint(x,y);
sign[x/20][y/20]=1;
}
if (button==GLUT_RIGHT_BUTTON && action==GLUT_DOWN)
{
boundaryFill4(x,y);
}
glFlush();
}
void main(int argc, char** argv)
{
for(int i=0;i<30;i++)
{
for(int j=0;j<30;j++)
{
sign[i][j]=2;
}
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(50,100);
glutInitWindowSize(600, 600);
glutCreateWindow("mouse");
init();
glutDisplayFunc(displayFcn);
glutMouseFunc(mouse);
glutMainLoop();
}
- 1
- 2
- 3
- 4
- 5
前往页