Total Complexity | 2 |
Total Lines | 43 |
Duplicated Lines | 62.79 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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 | View Code Duplication | class Pipe(Part): |
|
1 ignored issue
–
show
|
|||
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 |