-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMouse Click #6.txt
81 lines (64 loc) · 1.51 KB
/
Mouse Click #6.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<windows.h>
#include<GL/glut.h>
#include<GL/GL.h>
#include<math.h>
#include<stdio.h>
#include<iostream>
#include<list>
using namespace std;
void display();
static float R, G, B;
void init(void)
{
glClearColor(0.16, 0.24, 0.15, 0.0);
glLineWidth(10.0);
glPointSize(6.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 600, 0.0, 300);
}
bool location(float x, float y, float x1, float y1, float x2, float y2) {
if (x > x1 && x < x2 && y >y1&& y < y2) {
return true;
}
else
{
return false;
}
}
float Random() {
return rand() % 100;
}
void DrawRecti(float x1, float y1, float x2, float y2, float R, float G, float B) {
glColor3f(R, G, B);
glRecti(x1, y1, x2, y2);
}
void myMouse(int button, int state, int x, int y) {
y = 300 - y;
// test for mouse button as well as for a full array
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && location(x,y,100, 100, 500, 200) ) {
R = (Random()) / 100;
G = (Random()) / 100;
B = (Random()) / 100;
}
display();
}
void display()
{
DrawRecti(0, 0, 600, 300,1- R,1- G,1- B);
DrawRecti(100, 100, 500, 200, R, G, B);
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600,300 );
glutInitWindowPosition(250, 50);
glutCreateWindow("color Change");
glutMouseFunc(myMouse);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}