Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from sys import stdin, exit as sys_exit
- import numpy as np
- import matplotlib.pyplot as plt
- class graphic_object:
- def __init__(self, object_matrix):
- self.object_matrix = object_matrix
- self.points_count = self.object_matrix.shape[0]
- def __mul__(self, other):
- return graphic_object(self.object_matrix.dot(other))
- def __rmul__(self, other):
- return graphic_object(self.object_matrix.dot(other))
- def draw(self):
- m = self.object_matrix
- print(m[1,2])
- for i in range(self.points_count - 1):
- plt.plot([m[i, 0], m[i + 1, 0]], [m[i, 1], m[i+1, 1]])
- plt.plot([m[self.points_count - 1, 0], m[0, 0]], [m[0, 1], m[self.points_count - 1, 1]])
- plt.axis([-10, 10, -10, 10])
- ax = plt.gca()
- ax.spines['left'].set_position('center')
- ax.spines['bottom'].set_position('center')
- ax.spines['top'].set_visible(False)
- ax.spines['right'].set_visible(False)
- plt.show()
- def map_axis_x(self):
- mapping_matrix = np.matrix(
- [[-1, 0, 0],
- [0, 1, 0],
- [0, 0, 1]])
- return self*mapping_matrix
- def map_axis_y(self):
- mapping_matrix = np.matrix(
- [[1, 0, 0],
- [0, -1, 0],
- [0, 0, 1]])
- return self*mapping_matrix
- def scale(self, x_scale, y_scale):
- scale_matrix = np.matrix(
- [[x_scale, 0, 0],
- [0, y_scale, 0],
- [0,0,1]])
- return self * scale_matrix
- x = graphic_object(np.matrix(
- [[1, 3, 1],
- [2, 2, 1],
- [0, 1, 1],
- [1, 4, 1]]))
- x.draw()
- answ = 0
- z = graphic_object(np.matrix([]))
- z = x
- while answ!=5:
- print ("""Выберите действие:
- 1: отобразить по оси X без изменения масштаба
- 2: отобразить по оси Y без изменения масштаба
- 3: отобразить по оси X c изменением масштаба
- 4: отобразить по оси Y с изменением масштаба
- 5: завершить работу""")
- answ = int(input())
- if answ == 1:
- y = z.map_axis_x()
- if answ == 2:
- y = z.map_axis_y()
- if answ == 3:
- y = z.map_axis_x()
- print ('Введите изменение масштаба по оси X')
- sc_x = float(input())
- print ('Введите изменение масштаба по оси Y')
- sc_y = float(input())
- y = z.scale(sc_x,sc_y)
- if answ == 4:
- y = z.map_axis_y()
- print ('Введите изменение масштаба по оси X')
- sc_x = float(input())
- print ('Введите изменение масштаба по оси Y')
- sc_y = float(input())
- y = z.scale(sc_x,sc_y)
- y.draw()
- z = y
- sys_exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement