Passed
Pull Request — master (#21)
by Matt
03:47 queued 01:54
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: Union[int, float], x: Union[int, float], y: Union[int, float],
19
                 rotation: Union[int, float] = 0, *, color: Union[List[int], Tuple[int, int, int]] = (80, 80, 80)):
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
        width = int(self.__length * screen.block_size)
29
        height = int(screen.block_size)
30
        surface = pygame.Surface((width, height), pygame.SRCALPHA, 32)
31
        surface = surface.convert_alpha()
32
33
        # Draw the rect
34
        rect = pygame.Rect(0, 0, width, height)
35
        pygame.draw.rect(surface, self.__color, rect)
36
37
        # Rotate
38
        surface = pygame.transform.rotate(surface, int(self.__rotation))
39
40
        # Render
41
        x, y = surface.get_size()
42
        x = int((self._x * screen.block_size) - floor(x / 2))
43
        y = int((self._y * screen.block_size) - floor(y / 2))
44
        return x, y, surface
45