Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyglet
- from pyglet import shapes
- from pyglet.window import key
- from pyglet import clock
- import numpy as np
- import math
- def dist(c1, c2):
- di = (((c1[0] - c2[0])**2)+((c1[1] - c2[1])**2)+((c1[2] - c2[2])**2)+((c1[3] - c2[3])**2))**(1/2)
- return di
- def calc_point():
- pass
- def draw_lines(C, A):
- lne = []
- for i in range(16):
- for e in range(16):
- if ((dist(A[i], A[e])) != 0) and ((dist(A[i], A[e])) < 280):
- lne.append(shapes.Line(C[i][0], C[i][1], C[e][0], C[e][1], 5, color=(255, 255, 255), batch=batch))
- return lne
- #########################################################################################################
- #########################################################################################################
- #########################################################################################################
- #########################################################################################################
- angleXY = math.pi
- turnXY = False
- angleYZ = math.pi
- turnYZ = False
- angleXZ = math.pi
- turnXZ = False
- angleXU = math.pi
- turnXU = False
- angleYU = math.pi
- turnYU = False
- angleZU = math.pi
- turnZU = False
- A = np.array([[-100, -100, -100, -100],
- [-100, 100, -100, -100],
- [100, -100, -100, -100],
- [100, 100, -100, -100],
- [-100, -100, 100, -100],
- [-100, 100, 100, -100],
- [100, -100, 100, -100],
- [100, 100, 100, -100],
- [-100, -100, -100, 100],
- [-100, 100, -100, 100],
- [100, -100, -100, 100],
- [100, 100, -100, 100],
- [-100, -100, 100, 100],
- [-100, 100, 100, 100],
- [100, -100, 100, 100],
- [100, 100, 100, 100]])
- B = np.array([[0, 0],
- [0, 1],
- [1, 0],
- [0, 0]])
- #########################################################################################################
- #########################################################################################################
- #########################################################################################################
- #########################################################################################################
- # Window Draw
- #########################################################################################################
- window = pyglet.window.Window(960, 540)
- batch = pyglet.graphics.Batch()
- #########################################################################################################
- @window.event
- def on_key_press(symbol, modifier):
- global turnXY
- global turnYZ
- global turnXZ
- global turnXU
- global turnYU
- global turnZU
- if symbol == key.Z:
- turnXY = True
- if symbol == key.X:
- turnYZ = True
- if symbol == key.C:
- turnXZ = True
- if symbol == key.A:
- turnXU = True
- if symbol == key.S:
- turnYU = True
- if symbol == key.D:
- turnZU = True
- @window.event
- def on_key_release(symbol, modifier):
- global turnXY
- global turnYZ
- global turnXZ
- global turnXU
- global turnYU
- global turnZU
- if symbol == key.Z:
- turnXY = False
- if symbol == key.X:
- turnYZ = False
- if symbol == key.C:
- turnXZ = False
- if symbol == key.A:
- turnXU = False
- if symbol == key.S:
- turnYU = False
- if symbol == key.D:
- turnZU = False
- @window.event
- def on_draw():
- global angleXY
- global angleYZ
- global angleXZ
- global angleXU
- global angleYU
- global angleZU
- if turnXY:
- angleXY += math.pi * clock.tick() * 10000 / 180
- if turnYZ:
- angleYZ += math.pi * clock.tick() * 10000 / 180
- if turnXZ:
- angleXZ += math.pi * clock.tick() * 10000 / 180
- if turnXU:
- angleXU += math.pi * clock.tick() * 10000 / 180
- if turnYU:
- angleYU += math.pi * clock.tick() * 10000 / 180
- if turnZU:
- angleZU += math.pi * clock.tick() * 10000 / 180
- window.clear()
- ###################################
- # Calculate points after rotating
- ###################################
- rotXY = np.array([[math.cos(angleXY), math.sin(angleXY), 0, 0],
- [-math.sin(angleXY), math.cos(angleXY), 0, 0],
- [0, 0, 1, 0],
- [0, 0, 0, 1]])
- rotYZ = np.array([[1, 0, 0, 0],
- [0, math.cos(angleYZ), math.sin(angleYZ), 0],
- [0, -math.sin(angleYZ), math.cos(angleYZ), 0],
- [0, 0, 0, 1]])
- rotXZ = np.array([[math.cos(angleXZ), 0, -math.sin(angleXZ), 0],
- [0, 1, 0, 0],
- [math.sin(angleXZ), 0, math.cos(angleXZ), 0],
- [0, 0, 0, 1]])
- rotXU = np.array([[math.cos(angleXU), 0, 0, math.sin(angleXU)],
- [0, 1, 0, 0],
- [0, 0, 1, 0],
- [-math.sin(angleXU), 0, 0, math.cos(angleXU)]])
- rotYU = np.array([[1, 0, 0, 0],
- [0, math.cos(angleYU), 0, -math.sin(angleYU)],
- [0, 0, 1, 0],
- [0, math.sin(angleYU), 0, math.cos(angleYU)]])
- rotZU = np.array([[1, 0, 0, 0],
- [0, 1, 0, 0],
- [0, 0, math.cos(angleZU), -math.sin(angleZU)],
- [0, 0, math.sin(angleZU), math.cos(angleZU)]])
- rt = np.dot(A, rotXY)
- rt = np.dot(rt, rotYZ)
- rt = np.dot(rt, rotXZ)
- rt = np.dot(rt, rotXU)
- rt = np.dot(rt, rotYU)
- rt = np.dot(rt, rotZU)
- ######################################
- # Calculate point projection on plane
- ######################################
- C = np.dot(rt, B)
- for i in range (16):
- C[i][0] = C[i][0] + 400
- C[i][1] = C[i][1] + 265
- lne = draw_lines(C, rt)
- batch.draw()
- pyglet.app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement