-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransformation.py
114 lines (93 loc) · 2.52 KB
/
transformation.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
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import math
import numpy as np
def transform():
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(.5, .3, .7)
glPointSize(5)
glBegin(GL_LINES)
glVertex2f(250, 500)
glVertex2f(250, 0)
glVertex2f(0, 250)
glVertex2f(500, 250)
glEnd()
glBegin(GL_QUADS)
glColor3f(0, 1, 0)
glVertex2f(200, 300)
glVertex2f(200, 200)
glVertex2f(300, 200)
glVertex2f(300, 300)
glEnd()
a = math.cos(math.radians(45))
b = math.sin(math.radians(45))
r = np.array([[a, -b, 0],
[b, a, 0],
[0, 0, 1]])
sc = 0.5
s = np.array([[sc, 0, 0],
[0, sc, 0],
[0, 0, 1]])
rs = np.matmul(r, s)
v1 = np.array([[-50],
[50],
[1]])
v2 = np.array([[-50],
[-50],
[1]])
v3 = np.array([[50],
[-50],
[1]])
v4 = np.array([[50],
[50],
[1]])
# rotation
# v11 = np.matmul(r,v1)
# v22 = np.matmul(r,v2)
# v33 = np.matmul(r,v3)
# v44 = np.matmul(r,v4)
# scaling
# v11 = np.matmul(s,v1)
# v22 = np.matmul(s,v2)
# v33 = np.matmul(s,v3)
# v44 = np.matmul(s,v4)
# rotation - scaling
v11 = np.matmul(rs, v1)
v22 = np.matmul(rs, v2)
v33 = np.matmul(rs, v3)
v44 = np.matmul(rs, v4)
#
glColor3f(1, 0, 0)
glBegin(GL_QUADS)
glVertex2f(v11[0][0] + 250, v11[1][0] + 250)
glVertex2f(v22[0][0] + 250, v22[1][0] + 250)
glVertex2f(v33[0][0] + 250, v33[1][0] + 250)
glVertex2f(v44[0][0] + 250, v44[1][0] + 250)
glEnd()
def iterate():
glViewport(0, 0, 500, 500)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, 500, 0.0, 500, 0.0, 1.0)
glMatrixMode (GL_MODELVIEW)
glLoadIdentity()
def draw_points(x, y):
glPointSize(5) #pixel size. by default 1 thake
glBegin(GL_POINTS)
glVertex2f(x,y) #jekhane show korbe pixel
glEnd()
def showScreen():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
#tasks
iterate()
transform()
glutSwapBuffers()
glutInit()
glutInitDisplayMode(GLUT_RGBA)
glutInitWindowSize(500, 500) #window size
glutInitWindowPosition(0, 0)
wind = glutCreateWindow(b"Transformation") #window name
glutDisplayFunc(showScreen)
glutMainLoop()