Passed
Pull Request — master (#11)
by Erik
02:58
created

example_007.Icon.update()   A

Complexity

Conditions 5

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
nop 1
dl 0
loc 17
rs 9.3333
c 0
b 0
f 0
1
from pypen import *
2
3
4
class Icon():
5
    def __init__(self, x, y):
6
        self.x = x
7
        self.y = y
8
        self.types = 2
9
        self.type = int(random(self.types))
10
        self.variation = random(1)
11
        self.width = 20
12
        self.color = "#383838"
13
        self.secondary_color = "#565656"
14
15
    def update(self):
16
        save()
17
        translate(self.x, self.y)
18
        rotate(TIME)
19
20
        self.color = "#fe3060" if sqrt((self.x-MOUSE.x)**2 + (self.y-MOUSE.y)**2) <= 100 else "#383838"
21
22
        if self.variation > 0.5:
23
            rotate(90)
24
25
        if self.type == 0:
26
            self.rectangle()
27
28
        elif self.type == 1:
29
            self.circle()
30
31
        restore()
32
33
    def rectangle(self):
34
        if self.variation > 0.9:
35
            rectangle(0 - self.width/2, 0 - self.width/2, self.width, self.width, self.secondary_color)
36
            return
37
38
        rectangle(0 - self.width/2, 0 - self.width/2, self.width, self.width, self.color)
39
40
    def circle(self):
41
        circle(0, 0, self.width/2, self.color)
42
        if self.variation > 0.6:
43
            arc(0, 0, self.width/2, 0, PI, self.secondary_color)
44
45
46
def start():
47
    settings.fps = 60
48
49
    global icons
50
    icons = []
51
    for x, y in grid(50):
52
        icons.append(Icon(x, y))
53
54
55
def update():
56
    global current_x, current_y
57
    fill_screen("#343434")
58
    for icon in icons:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable icons does not seem to be defined.
Loading history...
59
        icon.update()
60
61
    circle(MOUSE.x, MOUSE.y, 100, (0, 0, 0, 100))
62