Advertisement
Toliak

ЛР1 ИУ8

Sep 20th, 2018
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. import math
  2.  
  3. class VectorImage:
  4.     def __init__(self, x, y, color_depth = 1):
  5.         self.x = x
  6.         self.y = y
  7.         self.color_depth = color_depth
  8.  
  9.     def size(self):
  10.         return tuple(
  11.             [
  12.                 math.ceil(math.log2(a)) for a in [
  13.                     self.x,
  14.                     self.y,
  15.                     (self.x**2 + self.y**2)**0.5
  16.                 ]
  17.             ]
  18.         )
  19.  
  20.     def to_byte(self, bit):
  21.         return math.ceil(bit/8)
  22.  
  23.  
  24. class VectorImageShape(VectorImage):
  25.     def rect(self):
  26.         point_size = self.size()
  27.         point_volume_bit = point_size[0] + point_size[1]
  28.         volumes_bit = [
  29.             point_volume_bit * 3 + self.color_depth * 2 + point_size[2],                    # По 3м точкам
  30.             point_volume_bit * 2 + self.color_depth * 2 + point_size[2] + 9,                # По 2м точкам и углу
  31.             point_volume_bit + self.color_depth * 2 + point_size[2] * 2 + 9 * 2,            # По центру, половине диагонали, углу, углу
  32.         ]
  33.         volumes_byte = tuple(
  34.             [
  35.                 self.to_byte(a) for a in volumes_bit
  36.             ]
  37.         )
  38.         return volumes_byte
  39.  
  40.     def circle(self):
  41.         point_size = self.size()
  42.         point_volume_bit = point_size[0] + point_size[1]
  43.         volume_bit = point_volume_bit + point_size[2] * 2 + self.color_depth * 2
  44.         return self.to_byte(volume_bit)
  45.  
  46.     def custom(self, points):
  47.         point_size = self.size()
  48.         point_volume_bit = point_size[0] + point_size[1]
  49.         volume_bit = point_volume_bit * points + point_size[2] + self.color_depth
  50.         return self.to_byte(volume_bit)
  51.  
  52.  
  53.  
  54. if __name__ == "__main__":
  55.     img1 = VectorImageShape(127, 127, 24)
  56.     print(img1.rect())
  57.     print(img1.circle())
  58.     print(img1.custom(5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement