forked from AndriiGoz/football_game_stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FCPython.py
255 lines (203 loc) · 10.1 KB
/
FCPython.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 25 17:32:00 2020
@author: davsu428
"""
import matplotlib.pyplot as plt
from matplotlib.patches import Arc
def createPitch(length, width, unity, linecolor): # in meters
# Code by @JPJ_dejong
"""
creates a plot in which the 'length' is the length of the pitch (goal to goal).
And 'width' is the width of the pitch (sideline to sideline).
Fill in the unity in meters or in yards.
"""
# Set unity
if unity == "meters":
# Set boundaries
if length >= 120.5 or width >= 75.5:
return (str("Field dimensions are too big for meters as unity, didn't you mean yards as unity?\
Otherwise the maximum length is 120 meters and the maximum width is 75 meters. Please try again"))
# Run program if unity and boundaries are accepted
else:
# Create figure
fig = plt.figure()
# fig.set_size_inches(7, 5)
ax = fig.add_subplot(1, 1, 1)
# Pitch Outline & Centre Line
plt.plot([0, 0], [0, width], color=linecolor)
plt.plot([0, length], [width, width], color=linecolor)
plt.plot([length, length], [width, 0], color=linecolor)
plt.plot([length, 0], [0, 0], color=linecolor)
plt.plot([length / 2, length / 2], [0, width], color=linecolor)
# Left Penalty Area
plt.plot([16.5, 16.5], [(width / 2 + 16.5), (width / 2 - 16.5)], color=linecolor)
plt.plot([0, 16.5], [(width / 2 + 16.5), (width / 2 + 16.5)], color=linecolor)
plt.plot([16.5, 0], [(width / 2 - 16.5), (width / 2 - 16.5)], color=linecolor)
# Right Penalty Area
plt.plot([(length - 16.5), length], [(width / 2 + 16.5), (width / 2 + 16.5)], color=linecolor)
plt.plot([(length - 16.5), (length - 16.5)], [(width / 2 + 16.5), (width / 2 - 16.5)], color=linecolor)
plt.plot([(length - 16.5), length], [(width / 2 - 16.5), (width / 2 - 16.5)], color=linecolor)
# Left 5-meters Box
plt.plot([0, 5.5], [(width / 2 + 7.32 / 2 + 5.5), (width / 2 + 7.32 / 2 + 5.5)], color=linecolor)
plt.plot([5.5, 5.5], [(width / 2 + 7.32 / 2 + 5.5), (width / 2 - 7.32 / 2 - 5.5)], color=linecolor)
plt.plot([5.5, 0.5], [(width / 2 - 7.32 / 2 - 5.5), (width / 2 - 7.32 / 2 - 5.5)], color=linecolor)
# Right 5 -eters Box
plt.plot([length, length - 5.5], [(width / 2 + 7.32 / 2 + 5.5), (width / 2 + 7.32 / 2 + 5.5)],
color=linecolor)
plt.plot([length - 5.5, length - 5.5], [(width / 2 + 7.32 / 2 + 5.5), width / 2 - 7.32 / 2 - 5.5],
color=linecolor)
plt.plot([length - 5.5, length], [width / 2 - 7.32 / 2 - 5.5, width / 2 - 7.32 / 2 - 5.5], color=linecolor)
# Prepare Circles
centreCircle = plt.Circle((length / 2, width / 2), 9.15, color=linecolor, fill=False)
centreSpot = plt.Circle((length / 2, width / 2), 0.8, color=linecolor)
leftPenSpot = plt.Circle((11, width / 2), 0.8, color=linecolor)
rightPenSpot = plt.Circle((length - 11, width / 2), 0.8, color=linecolor)
# Draw Circles
ax.add_patch(centreCircle)
ax.add_patch(centreSpot)
ax.add_patch(leftPenSpot)
ax.add_patch(rightPenSpot)
# Prepare Arcs
leftArc = Arc((11, width / 2), height=18.3, width=18.3, angle=0, theta1=308, theta2=52, color=linecolor)
rightArc = Arc((length - 11, width / 2), height=18.3, width=18.3, angle=0, theta1=128, theta2=232,
color=linecolor)
# Draw Arcs
ax.add_patch(leftArc)
ax.add_patch(rightArc)
# Axis titles
# check unity again
elif unity == "yards":
# check boundaries again
if length <= 95:
return (str("Didn't you mean meters as unity?"))
elif length >= 131 or width >= 101:
return (str("Field dimensions are too big. Maximum length is 130, maximum width is 100"))
# Run program if unity and boundaries are accepted
else:
# Create figure
fig = plt.figure()
# fig.set_size_inches(7, 5)
ax = fig.add_subplot(1, 1, 1)
# Pitch Outline & Centre Line
plt.plot([0, 0], [0, width], color=linecolor)
plt.plot([0, length], [width, width], color=linecolor)
plt.plot([length, length], [width, 0], color=linecolor)
plt.plot([length, 0], [0, 0], color=linecolor)
plt.plot([length / 2, length / 2], [0, width], color=linecolor)
# Left Penalty Area
plt.plot([18, 18], [(width / 2 + 18), (width / 2 - 18)], color=linecolor)
plt.plot([0, 18], [(width / 2 + 18), (width / 2 + 18)], color=linecolor)
plt.plot([18, 0], [(width / 2 - 18), (width / 2 - 18)], color=linecolor)
# Right Penalty Area
plt.plot([(length - 18), length], [(width / 2 + 18), (width / 2 + 18)], color=linecolor)
plt.plot([(length - 18), (length - 18)], [(width / 2 + 18), (width / 2 - 18)], color=linecolor)
plt.plot([(length - 18), length], [(width / 2 - 18), (width / 2 - 18)], color=linecolor)
# Left 6-yard Box
plt.plot([0, 6], [(width / 2 + 7.32 / 2 + 6), (width / 2 + 7.32 / 2 + 6)], color=linecolor)
plt.plot([6, 6], [(width / 2 + 7.32 / 2 + 6), (width / 2 - 7.32 / 2 - 6)], color=linecolor)
plt.plot([6, 0], [(width / 2 - 7.32 / 2 - 6), (width / 2 - 7.32 / 2 - 6)], color=linecolor)
# Right 6-yard Box
plt.plot([length, length - 6], [(width / 2 + 7.32 / 2 + 6), (width / 2 + 7.32 / 2 + 6)], color=linecolor)
plt.plot([length - 6, length - 6], [(width / 2 + 7.32 / 2 + 6), width / 2 - 7.32 / 2 - 6], color=linecolor)
plt.plot([length - 6, length], [(width / 2 - 7.32 / 2 - 6), width / 2 - 7.32 / 2 - 6], color=linecolor)
# Prepare Circles; 10 yards distance. penalty on 12 yards
centreCircle = plt.Circle((length / 2, width / 2), 10, color=linecolor, fill=False)
centreSpot = plt.Circle((length / 2, width / 2), 0.8, color=linecolor)
leftPenSpot = plt.Circle((12, width / 2), 0.8, color=linecolor)
rightPenSpot = plt.Circle((length - 12, width / 2), 0.8, color=linecolor)
# Draw Circles
ax.add_patch(centreCircle)
ax.add_patch(centreSpot)
ax.add_patch(leftPenSpot)
ax.add_patch(rightPenSpot)
# Prepare Arcs
leftArc = Arc((11, width / 2), height=20, width=20, angle=0, theta1=312, theta2=48, color=linecolor)
rightArc = Arc((length - 11, width / 2), height=20, width=20, angle=0, theta1=130, theta2=230,
color=linecolor)
# Draw Arcs
ax.add_patch(leftArc)
ax.add_patch(rightArc)
# Tidy Axes
plt.axis('off')
return fig, ax
def createPitchOld():
# Taken from FC Python
# Create figure
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
# Pitch Outline & Centre Line
plt.plot([0, 0], [0, 90], color=linecolor)
plt.plot([0, 130], [90, 90], color=linecolor)
plt.plot([130, 130], [90, 0], color=linecolor)
plt.plot([130, 0], [0, 0], color=linecolor)
plt.plot([65, 65], [0, 90], color=linecolor)
# Left Penalty Area
plt.plot([16.5, 16.5], [65, 25], color=linecolor)
plt.plot([0, 16.5], [65, 65], color=linecolor)
plt.plot([16.5, 0], [25, 25], color=linecolor)
# Right Penalty Area
plt.plot([130, 113.5], [65, 65], color=linecolor)
plt.plot([113.5, 113.5], [65, 25], color=linecolor)
plt.plot([113.5, 130], [25, 25], color=linecolor)
# Left 6-yard Box
plt.plot([0, 5.5], [54, 54], color=linecolor)
plt.plot([5.5, 5.5], [54, 36], color=linecolor)
plt.plot([5.5, 0.5], [36, 36], color=linecolor)
# Right 6-yard Box
plt.plot([130, 124.5], [54, 54], color=linecolor)
plt.plot([124.5, 124.5], [54, 36], color=linecolor)
plt.plot([124.5, 130], [36, 36], color=linecolor)
# Prepare Circles
centreCircle = plt.Circle((65, 45), 9.15, color=linecolor, fill=False)
centreSpot = plt.Circle((65, 45), 0.8, color=linecolor)
leftPenSpot = plt.Circle((11, 45), 0.8, color=linecolor)
rightPenSpot = plt.Circle((119, 45), 0.8, color=linecolor)
# Draw Circles
ax.add_patch(centreCircle)
ax.add_patch(centreSpot)
ax.add_patch(leftPenSpot)
ax.add_patch(rightPenSpot)
# Prepare Arcs
leftArc = Arc((11, 45), height=18.3, width=18.3, angle=0, theta1=310, theta2=50, color=linecolor)
rightArc = Arc((119, 45), height=18.3, width=18.3, angle=0, theta1=130, theta2=230, color=linecolor)
# Draw Arcs
ax.add_patch(leftArc)
ax.add_patch(rightArc)
# Tidy Axes
plt.axis('off')
return fig, ax
def createGoalMouth():
# Adopted from FC Python
# Create figure
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
linecolor = 'black'
# Pitch Outline & Centre Line
plt.plot([0, 65], [0, 0], color=linecolor)
plt.plot([65, 65], [50, 0], color=linecolor)
plt.plot([0, 0], [50, 0], color=linecolor)
# Left Penalty Area
plt.plot([12.5, 52.5], [16.5, 16.5], color=linecolor)
plt.plot([52.5, 52.5], [16.5, 0], color=linecolor)
plt.plot([12.5, 12.5], [0, 16.5], color=linecolor)
# Left 6-yard Box
plt.plot([41.5, 41.5], [5.5, 0], color=linecolor)
plt.plot([23.5, 41.5], [5.5, 5.5], color=linecolor)
plt.plot([23.5, 23.5], [0, 5.5], color=linecolor)
# Goal
plt.plot([41.5 - 5.34, 41.5 - 5.34], [-2, 0], color=linecolor)
plt.plot([23.5 + 5.34, 41.5 - 5.34], [-2, -2], color=linecolor)
plt.plot([23.5 + 5.34, 23.5 + 5.34], [0, -2], color=linecolor)
# Prepare Circles
leftPenSpot = plt.Circle((65 / 2, 11), 0.8, color=linecolor)
# Draw Circles
ax.add_patch(leftPenSpot)
# Prepare Arcs
leftArc = Arc((32.5, 11), height=18.3, width=18.3, angle=0, theta1=38, theta2=142, color=linecolor)
# Draw Arcs
ax.add_patch(leftArc)
# Tidy Axes
plt.axis('off')
return fig, ax