-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab3task.txt
106 lines (82 loc) · 2.81 KB
/
lab3task.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
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
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import math
def circlePoints(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 midpointLine(radius, x0, y0):
d = 1 - radius
x = 0
y = radius
circlePoints(x, y, x0, y0)
while x < y:
#print("y")
if d < 0:
# Choose East.
d = d + 2*x + 3
x += 1
else:
# Choose South East.
d = d + 2*x -2*y + 5
x += 1
y = y - 1
circlePoints(x, y, x0, y0)
def draw_circle(radius, x0, y0):
glColor3f(0.0, 1.0, 0.0)
midpointLine(radius, x0, y0) # outer circle
glColor3f(1.0, 1.0, 0.0)
midpointLine(radius/2, x0+radius/2, y0) # right inner circle
glColor3f(1.0, 1.0, 0.0)
midpointLine(radius / 2, x0 - radius / 2, y0) # left inner circle
glColor3f(1.0, 1.0, 0.0)
midpointLine(radius / 2, x0, y0 + radius/2) # upper inner circle
glColor3f(1.0, 1.0, 0.0)
midpointLine(radius / 2, x0, y0 - radius/2) # Lower inner circle
opposite = math.sin(math.radians(45)) * radius/2
glColor3f(1.0, 0.0, 1.0)
midpointLine(radius/2, x0+opposite, y0+opposite)
glColor3f(1.0, 0.0, 1.0) # Right upper diagonal
midpointLine(radius/2, x0+opposite, y0-opposite) # Right lower diagonal
glColor3f(1.0, 0.0, 1.0)
midpointLine(radius/2, x0-opposite, y0+opposite) # Left upper diagonal
glColor3f(1.0, 0.0, 1.0)
midpointLine(radius/2, x0-opposite, y0-opposite) # Left lower diagonal
# This function is used to draw pixels.
def draw_points(x, y):
# The parameter that is passed in the function dictates the size of the pixel.
glPointSize(2)
glBegin(GL_POINTS)
# Think of this as a co-ordinate. At the given x and y position the pixel will be drawn.
glVertex2f(x, y)
glEnd()
def iterate():
glViewport(0, 0, 1000, 1000)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, 1000, 0.0, 1000, 0.0, 1.0)
glMatrixMode (GL_MODELVIEW)
glLoadIdentity()
def showScreen():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
iterate()
glColor3f(1.0, 1.0, 1.0)
#calling draw methods here
draw_circle(300, 500, 500)
glutSwapBuffers()
glutInit()
glutInitDisplayMode(GLUT_RGBA)
# Size of the window.
glutInitWindowSize(1000, 1000)
glutInitWindowPosition(0, 0)
# window name
wind = glutCreateWindow(b"LAB3-SADAF")
glutDisplayFunc(showScreen)
glutMainLoop()