-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.c
110 lines (100 loc) · 1.59 KB
/
6.c
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
//CYLINDER AND PARALLELOPIPED
#include <GL/glut.h>
void glow_pixel(int m,int n)
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_POINTS);
glVertex2i(m,n);
glEnd();
glFlush();
}
void symmetry(int h,int k,int x,int y)
{
glow_pixel(x+h,y+k);
glow_pixel(-x+h,y+k);
glow_pixel(x+h,-y+k);
glow_pixel(-x+h,-y+k);
glow_pixel(y+h,x+k);
glow_pixel(-y+h,x+k);
glow_pixel(y+h,-x+k);
glow_pixel(-y+h,-x+k);
}
void circle(int h,int k,int r)
{
int x=0;
int y=r;
int d=1-r;
symmetry(h,k,x,y);
while(y>x)
{
if(d<0)
{
x=x+1;
y=y;
d=d+2*x+3;
}
else
{
x=x+1;
y=y-1;
d=d+2*(x-y)+5;
}
symmetry(h,k,x,y);
}
}
void cylinder()
{
int h=100;
int k=100;
int r=50;
int i;
for(i=1;i<=50;i=i+3)
{
circle(h+i,k+i,r);
}
}
void rectangle(int x1,int y1,int x2,int y2)
{
glColor3f(0,0,1);
glBegin(GL_LINE_LOOP);
glVertex2i(x1,y1);
glVertex2i(x2,y1);
glVertex2i(x2,y2);
glVertex2i(x1,y2);
glEnd();
glFlush();
}
void parellopiped()
{
int x1=300;
int y1=200;
int x2=400;
int y2=300;
int i;
for(i=1;i<=50;i=i+3)
{
rectangle(x1+i,y1+i,x2+i,y2+i);
}
}
void myinit()
{
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0,500,0,500);
}
void cyl_parl()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
cylinder();
parellopiped();
}
void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100,100);
glutCreateWindow("Cylinder and parellopiped");
glutDisplayFunc(cyl_parl);
myinit();
glutMainLoop();
}