From 7bd857b351b3b83e3b8d717d43934b7a5c3475d9 Mon Sep 17 00:00:00 2001 From: Sathish <62458381+sathishprasad@users.noreply.github.com> Date: Fri, 12 Jun 2020 02:17:20 -0700 Subject: [PATCH] Add files via upload --- Pitch.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Pitch.py diff --git a/Pitch.py b/Pitch.py new file mode 100644 index 0000000..76c2f97 --- /dev/null +++ b/Pitch.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Jun 11 22:56:58 2020 + +@author: Sathish +""" +from matplotlib.patches import Arc +import matplotlib.pyplot as plt +import matplotlib + +def createPitch(length,width,linecolour,pitchcolour): + #Create figure + fig=plt.figure() + ax=fig.add_subplot(1,1,1) + + #Pitch Outline & Centre Line + plt.plot([0,0],[0,width], color=linecolour) + plt.plot([0,length],[width,width], color=linecolour) + plt.plot([length,length],[width,0], color=linecolour) + plt.plot([length,0],[0,0], color=linecolour) + plt.plot([length/2,length/2],[0,width], color=linecolour) + + #Left Penalty Area + ax.plot([18 ,18],[(width/2 +18),(width/2-18)],color=linecolour) + ax.plot([0,18],[(width/2 +18),(width/2 +18)],color=linecolour) + ax.plot([18,0],[(width/2 -18),(width/2 -18)],color=linecolour) + + + #Right Penalty Area + ax.plot([(length-18),length],[(width/2 +18),(width/2 +18)],color=linecolour, zorder=2) + ax.plot([(length-18), (length-18)],[(width/2 +18),(width/2-18)],color=linecolour, zorder=2) + ax.plot([(length-18),length],[(width/2 -18),(width/2 -18)],color=linecolour, zorder=2) + + #Left 6-yard Box + ax.plot([0,6],[(width/2+7.32/2+6),(width/2+7.32/2+6)],color=linecolour) + ax.plot([6,6],[(width/2+7.32/2+6),(width/2-7.32/2-6)],color=linecolour) + ax.plot([6,0],[(width/2-7.32/2-6),(width/2-7.32/2-6)],color=linecolour) + + + #Right 6-yard Box + ax.plot([length,length-6],[(width/2+7.32/2+6),(width/2+7.32/2+6)],color=linecolour) + ax.plot([length-6,length-6],[(width/2+7.32/2+6),width/2-7.32/2-6],color=linecolour) + ax.plot([length-6,length],[(width/2-7.32/2-6),width/2-7.32/2-6],color=linecolour) + + #Prepare Circles; 10 yards distance. penalty on 12 yards + centreCircle = plt.Circle((length/2,width/2),10,color=linecolour,fill=False) + centreSpot = plt.Circle((length/2,width/2),0.4,color=linecolour) + leftPenSpot = plt.Circle((12,width/2),0.4,color=linecolour) + rightPenSpot = plt.Circle((length-12,width/2),0.4,color=linecolour) + + + + #Prepare Arcs + leftArc = Arc((11,width/2),height=20,width=20,angle=0,theta1=312,theta2=48,color=linecolour) + rightArc = Arc((length-11,width/2),height=20,width=20,angle=0,theta1=130,theta2=230,color=linecolour) + + + + + #Remove axis + plt.axis('off') + + rect1 = matplotlib.patches.Rectangle((-3,-3), length+6, length+12, color=pitchcolour) + + #Display Circles and Arcs + ax.add_patch(rect1) + ax.add_patch(centreCircle) + ax.add_patch(centreSpot) + ax.add_patch(leftPenSpot) + ax.add_patch(rightPenSpot) + ax.add_patch(leftArc) + ax.add_patch(rightArc) + + plt.show() + + return fig,ax + + + + + + +