Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- class VectorImage:
- def __init__(self, x, y, color_depth = 1):
- self.x = x
- self.y = y
- self.color_depth = color_depth
- def size(self):
- return tuple(
- [
- math.ceil(math.log2(a)) for a in [
- self.x,
- self.y,
- (self.x**2 + self.y**2)**0.5
- ]
- ]
- )
- def to_byte(self, bit):
- return math.ceil(bit/8)
- class VectorImageShape(VectorImage):
- def rect(self):
- point_size = self.size()
- point_volume_bit = point_size[0] + point_size[1]
- volumes_bit = [
- point_volume_bit * 3 + self.color_depth * 2 + point_size[2], # По 3м точкам
- point_volume_bit * 2 + self.color_depth * 2 + point_size[2] + 9, # По 2м точкам и углу
- point_volume_bit + self.color_depth * 2 + point_size[2] * 2 + 9 * 2, # По центру, половине диагонали, углу, углу
- ]
- volumes_byte = tuple(
- [
- self.to_byte(a) for a in volumes_bit
- ]
- )
- return volumes_byte
- def circle(self):
- point_size = self.size()
- point_volume_bit = point_size[0] + point_size[1]
- volume_bit = point_volume_bit + point_size[2] * 2 + self.color_depth * 2
- return self.to_byte(volume_bit)
- def custom(self, points):
- point_size = self.size()
- point_volume_bit = point_size[0] + point_size[1]
- volume_bit = point_volume_bit * points + point_size[2] + self.color_depth
- return self.to_byte(volume_bit)
- if __name__ == "__main__":
- img1 = VectorImageShape(127, 127, 24)
- print(img1.rect())
- print(img1.circle())
- print(img1.custom(5))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement