-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.py
405 lines (323 loc) · 10.4 KB
/
project.py
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import numpy as np
def findZone(x0, y0, x1, y1):
dy = y1-y0
dx = x1-x0
if abs(dx) > abs(dy): # Represents zone 0, 3, 4, 7.
if dx > 0 and dy > 0:
#print("FindZone: 0")
return 0
elif dx < 0 and dy > 0:
#print("FindZone: 3")
return 3
elif dx < 0 and dy < 0:
#print("FindZone: 4")
return 4
else:
#print("FindZone: 7")
return 7
else: # Represents zone 1, 2, 5, 6.
if dx > 0 and dy > 0:
#print("FindZone: 1")
return 1
elif dx < 0 and dy > 0:
#print("FindZone: 2")
return 2
elif dx < 0 and dy < 0:
#print("FindZone: 5")
return 5
else:
#print("FindZone: 6")
return 6
def ZoneZeroConversion(zone, x, y):
if zone == 0:
#print("Zone Zero Conversion Executed:", x, ",", y)
return x, y
elif zone == 1:
#print("Zone Zero Conversion Executed:", y, ",", x)
return y, x
elif zone == 2:
#print("Zone Zero Conversion Executed:", -y, ",", x)
return -y, x
elif zone == 3:
#print("Zone Zero Conversion Executed:", -x, ",", y)
return -x, y
elif zone == 4:
#print("Zone Zero Conversion Executed:", -x, ",", -y)
return -x, -y
elif zone == 5:
#print("Zone Zero Conversion Executed:", -y, ",", -x)
return -y, -x
elif zone == 6:
#print("Zone Zero Conversion Executed:", -y, ",", x)
return -y, x
elif zone == 7:
#print("Zone Zero Conversion Executed:", x, ",", -y)
return x, -y
def zero_to_original_zone(zone, x, y):
if zone == 0:
#print("Converted to original zone:", x, ",", y)
return x, y
if zone == 1:
#print("Converted to original zone:", y, ",", x)
return y, x
if zone == 2:
#print("Converted to original zone:", -y, ",", -x)
return -y, -x
if zone == 3:
#print("Converted to original zone:", -x, ",", y)
return -x, y
if zone == 4:
#print("Converted to original zone:", -x, ",", -y)
return -x, -y
if zone == 5:
#print("Converted to original zone:", -y, ",", -x)
return -y, -x
if zone == 6:
#print("Converted to original zone:", y, ",", -x)
return y, -x
if zone == 7:
#print("Converted to original zone:", x, ",", -y)
return x, -y
def MidPointLine(zone, x0, y0, x1, y1):
dy = y1-y0
dx = x1-x0
d_init = 2*dy - dx
e = 2*dy
ne = 2*(dy-dx)
x = x0
y = y0
while x <= x1:
a, b = zero_to_original_zone(zone, x, y)
draw_points(a, b)
if d_init <= 0:
x += 1
d_init += e
else:
x += 1
y += 1
d_init += ne
def eight_way_symmetry(x0, y0, x1, y1):
zone = findZone(x0, y0, x1, y1)
z0_x0, z0_y0 = ZoneZeroConversion(zone, x0, y0)
z0_x1, z0_y1 = ZoneZeroConversion(zone, x1, y1)
MidPointLine(zone, z0_x0, z0_y0, z0_x1, z0_y1)
def BackGroundColour(x):
if x > 24 or x < 0:
print("Invalid Time")
else:
if x>5 and x<=6:
glColor3f(0.0, 0.5, 0.74)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>6 and x<=7:
glColor3f(0.0, 0.5, 0.72)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>7 and x<=8:
glColor3f(0.0, 0.5, 0.7)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>8 and x<=9:
glColor3f(0.0, 0.5, 0.8)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>9 and x<=10:
glColor3f(0.0, 0.5, 0.9)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>10 and x<=11:
glColor3f(0.0, 0.5, 1.0)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>11 and x<=12:
glColor3f(0.0, 0.5, 0.9)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>12 and x<=13:
glColor3f(0.0, 0.5, 0.8)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>12 and x<=13:
glColor3f(0.0, 0.5, 0.7)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>13 and x<=14:
glColor3f(0.0, 0.5, 0.72)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>14 and x<=15:
glColor3f(0.0, 0.5, 0.74)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
elif x>15 and x<=18:
glColor3f(0.0, 0.5, 0.76)
for i in range(600):
eight_way_symmetry(0, i, 500, i)
else:
print("It is night!")
def building1():
for i in range(250):
eight_way_symmetry(0, i, 100, i)
for i in range(40):
eight_way_symmetry(40, i, 80, i)
def building1_entry():
for i in range(60):
eight_way_symmetry(30, i, 70, i)
def building2():
for i in range(150):
eight_way_symmetry(106, i, 300, i)
#glColor3f(0.6, 0.9, 0.9)
def building2_entry():
for i in range(40):
eight_way_symmetry(160, i, 240, i)
def building3():
for i in range(200):
eight_way_symmetry(306, i, 350, i)
def building3_entry():
for i in range(60):
eight_way_symmetry(330, i, 380, i)
def building4():
for i in range(230):
eight_way_symmetry(350, i, 400, i)
def building5():
for i in range(280):
eight_way_symmetry(406, i, 500, i)
def eightWay(x, y, x0, y0):
draw_points(x + x0, y + y0)
draw_points(y + x0, x + y0)
draw_points(y + x0, -x + y0)
draw_points(x + x0, -y + y0)
draw_points(-x + x0, -y + y0)
draw_points(-y + x0, -x + y0)
draw_points(-y + x0, x + y0)
draw_points(-x + x0, y + y0)
def midPoint(x0, y0, radius,s):
d = 1 - radius
x = 0
y = radius
scaling_matrix = np.array([[s, 0], [0, s]])
values = [x, y]
column = np.array(values).reshape(-1, 1)
scalled = np.dot(scaling_matrix, column)
x=scalled[0]
y=scalled[1]
eightWay(x, y, x0, y0)
while x < y:
if d >= 0:
d = d + 2 * x - 2 * y + 5
x = x + 1
y = y - 1
else:
d = d + 2 * x + 3
x = x + 1
eightWay(x, y, x0, y0)
def draw_circle(x, y, radius,s):
midPoint(x, y, radius,s)
glutSwapBuffers()
# Based on time this algorithm is plotting the position of the sun at different suitable co-ordinates
# and also slightly changing its colour.
def coordinating_circle(x):
if x >24 or x < 0:
print("Invalid Time.")
else:
if x > 5 and x <= 6:
for i in range(25, 0, -1):
s=2
glColor4f(1.0, 0.5, 0.0, 0.0)
draw_circle(0, 300, i,s)
elif x > 6 and x <= 7:
for i in range(25, 0, -1):
s=1.7
glColor4f(1.0, 0.6, 0.0, 0.0)
draw_circle(50, 350, i,s)
elif x > 7 and x <= 8:
for i in range(25, 0, -1):
s=1.4
glColor4f(1.0, 0.7, 0.0, 0.0)
draw_circle(100, 400, i,s)
elif x > 8 and x <= 9:
for i in range(25, 0, -1):
s=1.3
glColor4f(1.0, 0.8, 0.0, 0.0)
draw_circle(150, 450, i,s)
elif x > 9 and x <= 10:
for i in range(25, 0, -1):
s=1.3
glColor4f(1.0, 0.9, 0.0, 0.0)
draw_circle(200, 500, i,s)
elif x > 10 and x <= 11:
for i in range(25, 0, -1):
s=1.3
glColor4f(1.0, 1.0, 0.0, 0.0)
draw_circle(250, 550, i,s)
elif x > 11 and x <= 12:
for i in range(25, 0, -1):
s=1.3
glColor4f(1.0, 0.9, 0.0, 0.0)
draw_circle(300, 550, i,s)
elif x > 12 and x <= 13:
for i in range(25, 0, -1):
s=1.3
glColor4f(1.0, 0.8, 0.0, 0.0)
draw_circle(350, 500, i,s)
elif x > 13 and x <= 14:
for i in range(25, 0, -1):
s=1.4
glColor4f(1.0, 0.7, 0.0, 0.0)
draw_circle(400, 450, i,s)
elif x > 14 and x <= 15:
for i in range(25, 0, -1):
s=1.7
glColor4f(1.0, 0.6, 0.0, 0.0)
draw_circle(450, 400, i,s)
elif x > 15 and x <= 18:
for i in range(25, 0, -1):
s=2
glColor4f(1.0, 0.5, 0.0, 0.0)
draw_circle(500, 350, i,s)
else:
print("It is night!")
def draw_points(x, y):
glPointSize(5)
glBegin(GL_POINTS)
glVertex2f(x, y)
glEnd()
def iterate():
glViewport(0, 0, 500, 600)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, 500, 0.0, 600, 0.0, 1.0)
glMatrixMode (GL_MODELVIEW)
glLoadIdentity()
def showScreen():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
iterate()
x = float(input("ENTER THE INPUT IN MILITARY TIME ZONE IN HOUR ONLY!: ")) # Enter the time in hour.
# This function is colouring the background
BackGroundColour(x)
# These functions are drawing the buildings.
glColor3f(0.7, 0.0, 0.0)
building1()
building2()
building3()
building4()
building5()
# These functions are drawing the entry towards the buildings.
glColor3f(1.0, 1.0, 1.0)
building2_entry()
building1_entry()
building3_entry()
# This function will centre the sun based on the user input above.
coordinating_circle(x)
glutSwapBuffers()
glutInit()
glutInitDisplayMode(GLUT_RGBA)
glutInitWindowSize(500, 600)
glutInitWindowPosition(0, 0)
wind = glutCreateWindow(b"Project_CSE423_ComputerGraphics")
glutDisplayFunc(showScreen)
glutMainLoop()