Passed
Pull Request — master (#21)
by Matt
02:43
created

PyDMXControl.design.parts._Pipe.Pipe.__init__()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 7
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
"""
2
 *  PyDMXControl: A Python 3 module to control DMX using uDMX.
3
 *                Featuring fixture profiles, built-in effects and a web control panel.
4
 *  <https://github.com/MattIPv4/PyDMXControl/>
5
 *  Copyright (C) 2018 Matt Cowley (MattIPv4) ([email protected])
6
"""
7
8
from math import floor
9
from typing import Union, List, Tuple
10
11
import pygame
12
13
from ._Part import Part
14
15
16
class Pipe(Part):
17
18
    def __init__(self, size: int, x: int, y: int, rotation: int = 0, *,
19
                 color: Union[List[int], Tuple[int]] = (90, 90, 90)):
20
        super().__init__()
21
        self.__rotation = rotation
22
        self.__length = size
23
        self.__color = color
24
        self.set_pos(x, y)
25
26
    def design_render(self, screen: 'Screen') -> Tuple[int, int, pygame.Surface]:
27
        # Create the surface
28
        surface = pygame.Surface((self.__length * screen.block_size, screen.block_size), pygame.SRCALPHA, 32)
29
        surface = surface.convert_alpha()
30
31
        # Draw the rect
32
        rect = pygame.Rect(0, 0, self.__length * screen.block_size, screen.block_size)
33
        pygame.draw.rect(surface, self.__color, rect)
34
35
        # Rotate
36
        surface = pygame.transform.rotate(surface, self.__rotation)
37
38
        # Render
39
        x, y = surface.get_size()
40
        x = int((self._x * screen.block_size) - floor(x / 2))
41
        y = int((self._y * screen.block_size) - floor(y / 2))
42
        return x, y, surface
43