-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbz1.cpp
129 lines (107 loc) · 2.43 KB
/
bz1.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.1415926536
void clip(float,float,float);
float xc[100],yc[100],t=0,c=0.0002;
static int n=4,r=3;
float k=9;
void line(float a, float b, float c, float d)
{
glBegin(GL_LINES);
glVertex2f(a,b);
glVertex2f(c,d);
glEnd();
glutPostRedisplay();
glFlush();
}
void plot_point(float a, float b)
{
glBegin(GL_POINTS);
glVertex2f(a,b);
glEnd();
glFlush();
glutPostRedisplay();
}
void foo(int i,float x0, float y0,float x_prev,float y_prev){
float a,b;
if(i<r)
{a=(k*x0+x_prev)/(k+1);
b=(k*y0+y_prev)/(k+1);
x0=a;
y0=b;
k-=1;
}
}
void coords(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3){
float x,y;
while(t<=1)
{
x=(x0*(1-t)*(1-t)*(1-t))+(3*x1*(1-t)*(1-t)*t)+(3*t*t*(1-t)*x2)+(t*t*t*x3);
y=(y0*(1-t)*(1-t)*(1-t))+(3*y1*(1-t)*(1-t)*t)+(3*t*t*(1-t)*y2)+(t*t*t*y3);
t+=c;
plot_point(x,y);
}
t=0;
}
void petal()
{
glColor3f(1,1,1);
glBegin(GL_LINE_LOOP);
glVertex2f(-110,110);
glVertex2f(110,110);
glVertex2f(110,-110);
glVertex2f(-110,-110);
glFlush();
glEnd();
glColor3f(1,0,0);
//coords(-20,0,-130,130,-50,50,10,65);
coords(-5,0,-130,130,130,130,5,0);
coords(0,5,130,130,130,-130,0,-5);
coords(-5,0,-130,-130,130,-130,5,0);
coords(0,5,-130,130,-130,-130,0,-5);
glColor3f(0,1,0);
coords(-2,0,-110,110,110,110,2,0);
coords(0,2,110,110,110,-110,0,-2);
coords(-2,0,-110,-110,110,-110,2,0);
coords(0,2,-110,110,-110,-110,0,-2);
glColor3f(0,0,1);
coords(-2,0,-90,90,90,90,2,0);
coords(0,2,90,90,90,-90,0,-2);
coords(-2,0,-90,-90,90,-90,2,0);
coords(0,2,-90,90,-90,-90,0,-2);
//coords(-20,0,-130,-130,-50,-50,10,-65);
glFlush();
}
void init()
{
glClearColor(0, 0, 0,0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-250, 250, -250,250);
}
void keypress(unsigned char key,int x, int y){
t=0;
glClear(GL_COLOR_BUFFER_BIT);
if(key=='i'){
glClearColor(0, 0, 0,0);
glClear(GL_COLOR_BUFFER_BIT);
petal();
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(30, 50);
glutInitWindowSize(500, 500);
glutCreateWindow("Flower");
init();
glutKeyboardFunc(keypress);
glutMainLoop();
return 0;
}