From 2c5d750aebb2e2aeda72e8ad7de08d59221e327e Mon Sep 17 00:00:00 2001 From: Marc Date: Tue, 18 Apr 2023 16:58:22 -0700 Subject: [PATCH 01/11] refactored graphics_v4.py - Modified to add a function. - Changed variable names to be capitalized as they are constant variables. --- .../graphics_v4.py | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index a05c6d8..9374dc2 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -3,6 +3,7 @@ import math import random + # Initialize game engine pygame.init() @@ -16,7 +17,7 @@ # Timer clock = pygame.time.Clock() -refresh_rate = 60 +REFRESH_RATE = 60 # Colors @@ -36,7 +37,7 @@ NIGHT_GREEN = (0, 64, 0) BRIGHT_YELLOW = (255, 244, 47) NIGHT_GRAY = (104, 98, 115) -ck = (127, 33, 33) +CK = (127, 33, 33) DARKNESS = pygame.Surface(SIZE) DARKNESS.set_alpha(200) @@ -47,17 +48,51 @@ SEE_THROUGH.fill((124, 118, 135)) def draw_cloud(x, y): + ''' + This function draws a cloud shape on the Pygame surface specified by the global variable SEE_THROUGH. + The cloud shape consists of four ellipses and one rectangle, all with the same color specified by the + global variable cloud_color. The coordinates of the ellipses and rectangle are calculated based on the + given x and y coordinates. + + Parameters: + x (int): The x-coordinate of the top-left corner of the cloud shape. + y (int): The y-coordinate of the top-left corner of the cloud shape. + + Returns: + None + ''' + pygame.draw.ellipse(SEE_THROUGH, cloud_color, [x, y + 8, 10, 10]) pygame.draw.ellipse(SEE_THROUGH, cloud_color, [x + 6, y + 4, 8, 8]) pygame.draw.ellipse(SEE_THROUGH, cloud_color, [x + 10, y, 16, 16]) pygame.draw.ellipse(SEE_THROUGH, cloud_color, [x + 20, y + 8, 10, 10]) pygame.draw.rect(SEE_THROUGH, cloud_color, [x + 6, y + 8, 18, 10]) +def lights(a, b): + '''lights(a,b) function creates the head of a stadium lights + + :param: a determines positioning of the stadium head graphic + :param: b figures out the length of where the pygame draws + ''' + pygame.draw.line(screen, GRAY, [a, 60], [b, 60], 2) + pygame.draw.ellipse(screen, light_color, [a, 40, 20, 20]) + pygame.draw.ellipse(screen, light_color, [a+20, 40, 20, 20]) + pygame.draw.ellipse(screen, light_color, [a+40, 40, 20, 20]) + pygame.draw.ellipse(screen, light_color, [a+60, 40, 20, 20]) + pygame.draw.ellipse(screen, light_color, [a+80, 40, 20, 20]) + pygame.draw.line(screen, GRAY, [a, 40], [b, 40], 2) + pygame.draw.ellipse(screen, light_color, [a, 20, 20, 20]) + pygame.draw.ellipse(screen, light_color, [a+20, 20, 20, 20]) + pygame.draw.ellipse(screen, light_color, [a+40, 20, 20, 20]) + pygame.draw.ellipse(screen, light_color, [a+60, 20, 20, 20]) + pygame.draw.ellipse(screen, light_color, [a+80, 20, 20, 20]) + pygame.draw.line(screen, GRAY, [a, 20], [b, 20], 2) # Config lights_on = True day = True + stars = [] for n in range(200): x = random.randrange(0, 800) @@ -113,17 +148,14 @@ def draw_cloud(x, y): # Drawing code (Describe the picture. It isn't actually drawn yet.) screen.fill(sky_color) - SEE_THROUGH.fill(ck) - SEE_THROUGH.set_colorkey(ck) + SEE_THROUGH.fill(CK) + SEE_THROUGH.set_colorkey(CK) if not day: #stars for s in stars: pygame.draw.ellipse(screen, WHITE, s) - - - pygame.draw.rect(screen, field_color, [0, 180, 800 , 420]) pygame.draw.rect(screen, stripe_color, [0, 180, 800, 42]) pygame.draw.rect(screen, stripe_color, [0, 264, 800, 52]) @@ -158,11 +190,15 @@ def draw_cloud(x, y): #out of bounds lines + + #bottom side of out of bounds pygame.draw.line(screen, WHITE, [0, 580], [800, 580], 5) - #left + + #left side of out of bounds pygame.draw.line(screen, WHITE, [0, 360], [140, 220], 5) pygame.draw.line(screen, WHITE, [140, 220], [660, 220], 3) - #right + + #right side of out of bounds pygame.draw.line(screen, WHITE, [660, 220], [800, 360], 5) #safety circle @@ -183,7 +219,6 @@ def draw_cloud(x, y): pygame.draw.rect(screen, BLACK, [300, 40, 200, 90]) pygame.draw.rect(screen, WHITE, [302, 42, 198, 88], 2) - #goal pygame.draw.rect(screen, WHITE, [320, 140, 160, 80], 5) pygame.draw.line(screen, WHITE, [340, 200], [460, 200], 3) @@ -201,44 +236,18 @@ def draw_cloud(x, y): pygame.draw.rect(screen, GRAY, [150, 60, 20, 140]) pygame.draw.ellipse(screen, GRAY, [150, 195, 20, 10]) - #lights - pygame.draw.line(screen, GRAY, [110, 60], [210, 60], 2) - pygame.draw.ellipse(screen, light_color, [110, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [130, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [150, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [170, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [190, 40, 20, 20]) - pygame.draw.line(screen, GRAY, [110, 40], [210, 40], 2) - pygame.draw.ellipse(screen, light_color, [110, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [130, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [150, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [170, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [190, 20, 20, 20]) - pygame.draw.line(screen, GRAY, [110, 20], [210, 20], 2) + #lights pole 1 + lights(110,210) #light pole 2 pygame.draw.rect(screen, GRAY, [630, 60, 20, 140]) pygame.draw.ellipse(screen, GRAY, [630, 195, 20, 10]) #lights - - - pygame.draw.line(screen, GRAY, [590, 60], [690, 60], 2) - pygame.draw.ellipse(screen, light_color, [590, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [610, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [630, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [650, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [670, 40, 20, 20]) - pygame.draw.line(screen, GRAY, [590, 40], [690, 40], 2) - pygame.draw.ellipse(screen, light_color, [590, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [610, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [630, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [650, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [670, 20, 20, 20]) - pygame.draw.line(screen, GRAY, [590, 20], [690, 20], 2) + lights(590,690) #net - pygame.draw.line(screen, WHITE, [325, 140], [341, 200], 1) + pygame.draw.line(screen, WHITE, [325, 140], [341, 200], 1) pygame.draw.line(screen, WHITE, [330, 140], [344, 200], 1) pygame.draw.line(screen, WHITE, [335, 140], [347, 200], 1) pygame.draw.line(screen, WHITE, [340, 140], [350, 200], 1) @@ -314,12 +323,9 @@ def draw_cloud(x, y): pygame.draw.polygon(screen, RED, [[680, 220], [800, 340], [800, 290], [680, 180]]) pygame.draw.polygon(screen, WHITE, [[680, 180], [800, 100], [800, 290]]) - #stands left pygame.draw.polygon(screen, RED, [[120, 220], [0, 340], [0, 290], [120, 180]]) pygame.draw.polygon(screen, WHITE, [[120, 180], [0, 100], [0, 290]]) - #people - #corner flag right pygame.draw.line(screen, BRIGHT_YELLOW, [140, 220], [135, 190], 3) @@ -335,17 +341,11 @@ def draw_cloud(x, y): #pygame.draw.polygon(screen, BLACK, [[200, 200], [50,400], [600, 500]], 10) - ''' angles for arcs are measured in radians (a pre-cal topic) ''' - #pygame.draw.arc(screen, ORANGE, [100, 100, 100, 100], 0, math.pi/2, 1) - #pygame.draw.arc(screen, BLACK, [100, 100, 100, 100], 0, math.pi/2, 50) - - # Update screen (Actually draw the picture in the window.) pygame.display.flip() - # Limit refresh rate of game loop - clock.tick(refresh_rate) + clock.tick(REFRESH_RATE) # Close window and quit From 34f916d79cf760489c1e67f5f80018749def176d Mon Sep 17 00:00:00 2001 From: crystalle77 Date: Thu, 20 Apr 2023 15:22:42 -0700 Subject: [PATCH 02/11] Update graphics_v4.py --- .../graphics_v4.py | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index 9374dc2..38f13b3 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -88,6 +88,24 @@ def lights(a, b): pygame.draw.ellipse(screen, light_color, [a+80, 20, 20, 20]) pygame.draw.line(screen, GRAY, [a, 20], [b, 20], 2) +def netPartTwo(color, StartingXAxis, StartingYAxis, width): + endingXAxis = 324 + endingYAxis = 216 + for i in range(8): + pygame.draw.line(screen, color, [StartingXAxis, StartingYAxis], [endingXAxis, endingYAxis], width) + endingXAxis += 2 + endingYAxis -= 2 + + +def netPartThree(color, StartingXAxis, StartingYAxis, width): + endingXAxis = 476 + endingYAxis = 216 + for i in range(8): + pygame.draw.line(screen, color, [StartingXAxis, StartingYAxis], [endingXAxis, endingYAxis], width) + endingXAxis -= 2 + endingYAxis -= 2 + + # Config lights_on = True day = True @@ -283,25 +301,9 @@ def lights(a, b): pygame.draw.line(screen, WHITE, [470, 140], [456, 200], 1) pygame.draw.line(screen, WHITE, [475, 140], [459, 200], 1) - #net part 2 - pygame.draw.line(screen, WHITE, [320, 140], [324, 216], 1) - pygame.draw.line(screen, WHITE, [320, 140], [326, 214], 1) - pygame.draw.line(screen, WHITE, [320, 140], [328, 212], 1) - pygame.draw.line(screen, WHITE, [320, 140], [330, 210], 1) - pygame.draw.line(screen, WHITE, [320, 140], [332, 208], 1) - pygame.draw.line(screen, WHITE, [320, 140], [334, 206], 1) - pygame.draw.line(screen, WHITE, [320, 140], [336, 204], 1) - pygame.draw.line(screen, WHITE, [320, 140], [338, 202], 1) - - #net part 3 - pygame.draw.line(screen, WHITE, [480, 140], [476, 216], 1) - pygame.draw.line(screen, WHITE, [480, 140], [474, 214], 1) - pygame.draw.line(screen, WHITE, [480, 140], [472, 212], 1) - pygame.draw.line(screen, WHITE, [480, 140], [470, 210], 1) - pygame.draw.line(screen, WHITE, [480, 140], [468, 208], 1) - pygame.draw.line(screen, WHITE, [480, 140], [466, 206], 1) - pygame.draw.line(screen, WHITE, [480, 140], [464, 204], 1) - pygame.draw.line(screen, WHITE, [480, 140], [462, 202], 1) + netPartTwo(WHITE,320,140,1) + netPartThree(WHITE,480,140,1) + #net part 4 pygame.draw.line(screen, WHITE, [324, 144], [476, 144], 1) From 802965284508b47c46646c978b8f29ef88767aa3 Mon Sep 17 00:00:00 2001 From: crystalle77 Date: Thu, 20 Apr 2023 15:54:51 -0700 Subject: [PATCH 03/11] Update graphics_v4.py --- .../major league soccer animation/graphics_v4.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index 38f13b3..82c5529 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -88,18 +88,16 @@ def lights(a, b): pygame.draw.ellipse(screen, light_color, [a+80, 20, 20, 20]) pygame.draw.line(screen, GRAY, [a, 20], [b, 20], 2) -def netPartTwo(color, StartingXAxis, StartingYAxis, width): - endingXAxis = 324 - endingYAxis = 216 +def netPartTwo(color, StartingXAxis, StartingYAxis, endingXAxis, endingYAxis, width): + for i in range(8): pygame.draw.line(screen, color, [StartingXAxis, StartingYAxis], [endingXAxis, endingYAxis], width) endingXAxis += 2 endingYAxis -= 2 -def netPartThree(color, StartingXAxis, StartingYAxis, width): - endingXAxis = 476 - endingYAxis = 216 +def netPartThree(color, StartingXAxis, StartingYAxis, endingXAxis, endingYAxis, width): + for i in range(8): pygame.draw.line(screen, color, [StartingXAxis, StartingYAxis], [endingXAxis, endingYAxis], width) endingXAxis -= 2 @@ -301,8 +299,8 @@ def netPartThree(color, StartingXAxis, StartingYAxis, width): pygame.draw.line(screen, WHITE, [470, 140], [456, 200], 1) pygame.draw.line(screen, WHITE, [475, 140], [459, 200], 1) - netPartTwo(WHITE,320,140,1) - netPartThree(WHITE,480,140,1) + netPartTwo(WHITE,320,140,324,216, 1) + netPartThree(WHITE,480,140,476,216,1) #net part 4 From 26978e5d1349d2872424324398c20ab810f24db2 Mon Sep 17 00:00:00 2001 From: crystalle77 Date: Sat, 22 Apr 2023 04:33:23 -0700 Subject: [PATCH 04/11] Update graphics_v4.py Put net parts into one function called drawGoalPost and called it. Made a drawStands function for the stands and called it. --- .../graphics_v4.py | 153 ++++++++++-------- 1 file changed, 88 insertions(+), 65 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index 82c5529..32d42f9 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -88,22 +88,105 @@ def lights(a, b): pygame.draw.ellipse(screen, light_color, [a+80, 20, 20, 20]) pygame.draw.line(screen, GRAY, [a, 20], [b, 20], 2) -def netPartTwo(color, StartingXAxis, StartingYAxis, endingXAxis, endingYAxis, width): +def netPartOne(color, width): + #net + pygame.draw.line(screen, color, [325, 140], [341, 200], width) + pygame.draw.line(screen, color, [330, 140], [344, 200], width) + pygame.draw.line(screen, color, [335, 140], [347, 200], width) + pygame.draw.line(screen, color, [340, 140], [350, 200], width) + pygame.draw.line(screen, color, [345, 140], [353, 200], width) + pygame.draw.line(screen, color, [350, 140], [356, 200], width) + pygame.draw.line(screen, color, [355, 140], [359, 200], width) + pygame.draw.line(screen, color, [360, 140], [362, 200], width) + pygame.draw.line(screen, color, [364, 140], [365, 200], width) + pygame.draw.line(screen, color, [368, 140], [369, 200], width) + pygame.draw.line(screen, color, [372, 140], [373, 200], width) + pygame.draw.line(screen, color, [376, 140], [377, 200], width) + pygame.draw.line(screen, color, [380, 140], [380, 200], width) + pygame.draw.line(screen, color, [384, 140], [384, 200], width) + pygame.draw.line(screen, color, [388, 140], [388, 200], width) + pygame.draw.line(screen, color, [392, 140], [392, 200], width) + pygame.draw.line(screen, color, [396, 140], [396, 200], width) + pygame.draw.line(screen, color, [400, 140], [400, 200], width) + pygame.draw.line(screen, color, [404, 140], [404, 200], width) + pygame.draw.line(screen, color, [408, 140], [408, 200], width) + pygame.draw.line(screen, color, [412, 140], [412, 200], width) + pygame.draw.line(screen, color, [416, 140], [416, 200], width) + pygame.draw.line(screen, color, [420, 140], [420, 200], width) + pygame.draw.line(screen, color, [424, 140], [423, 200], width) + pygame.draw.line(screen, color, [428, 140], [427, 200], width) + pygame.draw.line(screen, color, [432, 140], [431, 200], width) + pygame.draw.line(screen, color, [436, 140], [435, 200], width) + pygame.draw.line(screen, color, [440, 140], [438, 200], width) + pygame.draw.line(screen, color, [445, 140], [441, 200], width) + pygame.draw.line(screen, color, [450, 140], [444, 200], width) + pygame.draw.line(screen, color, [455, 140], [447, 200], width) + pygame.draw.line(screen, color, [460, 140], [450, 200], width) + pygame.draw.line(screen, color, [465, 140], [453, 200], width) + pygame.draw.line(screen, color, [470, 140], [456, 200], width) + pygame.draw.line(screen, color, [475, 140], [459, 200], width) + +def netPartTwo(color, width): + StartingXAxis = 320 + StartingYAxis = 140 + endingXAxis =324 + endingYAxis = 216 + for i in range(8): pygame.draw.line(screen, color, [StartingXAxis, StartingYAxis], [endingXAxis, endingYAxis], width) endingXAxis += 2 endingYAxis -= 2 -def netPartThree(color, StartingXAxis, StartingYAxis, endingXAxis, endingYAxis, width): +def netPartThree(color, width): + + StartingXAxis = 480 + StartingYAxis = 140 + endingXAxis = 476 + endingYAxis = 216 for i in range(8): pygame.draw.line(screen, color, [StartingXAxis, StartingYAxis], [endingXAxis, endingYAxis], width) endingXAxis -= 2 endingYAxis -= 2 +def netPartFour(color, width): + + #net part 4 + pygame.draw.line(screen, color, [324, 144], [476, 144], width) + pygame.draw.line(screen, color, [324, 148], [476, 148], width) + pygame.draw.line(screen, color, [324, 152], [476, 152], width) + pygame.draw.line(screen, color, [324, 156], [476, 156], width) + pygame.draw.line(screen, color, [324, 160], [476, 160], width) + pygame.draw.line(screen, color, [324, 164], [476, 164], width) + pygame.draw.line(screen, color, [324, 168], [476, 168], width) + pygame.draw.line(screen, color, [324, 172], [476, 172], width) + pygame.draw.line(screen, color, [324, 176], [476, 176], width) + pygame.draw.line(screen, color, [335, 180], [470, 180], width) + pygame.draw.line(screen, color, [335, 184], [465, 184], width) + pygame.draw.line(screen, color, [335, 188], [465, 188], width) + pygame.draw.line(screen, color, [335, 192], [465, 192], width) + pygame.draw.line(screen, color, [335, 196], [465, 196], width) + +def drawGoalPost(color, width): + netPartOne(color,width) + netPartTwo(color, width) + netPartThree(color,width) + netPartFour(color, width) + +def drawStands (upperStandColor, lowerStandColor): + #stands right + pygame.draw.polygon(screen, lowerStandColor, [[680, 220], [800, 340], [800, 290], [680, 180]]) + pygame.draw.polygon(screen, upperStandColor, [[680, 180], [800, 100], [800, 290]]) + + #stands left + pygame.draw.polygon(screen, lowerStandColor, [[120, 220], [0, 340], [0, 290], [120, 180]]) + pygame.draw.polygon(screen, upperStandColor, [[120, 180], [0, 100], [0, 290]]) + + + # Config lights_on = True day = True @@ -262,71 +345,11 @@ def netPartThree(color, StartingXAxis, StartingYAxis, endingXAxis, endingYAxis, #lights lights(590,690) - #net - pygame.draw.line(screen, WHITE, [325, 140], [341, 200], 1) - pygame.draw.line(screen, WHITE, [330, 140], [344, 200], 1) - pygame.draw.line(screen, WHITE, [335, 140], [347, 200], 1) - pygame.draw.line(screen, WHITE, [340, 140], [350, 200], 1) - pygame.draw.line(screen, WHITE, [345, 140], [353, 200], 1) - pygame.draw.line(screen, WHITE, [350, 140], [356, 200], 1) - pygame.draw.line(screen, WHITE, [355, 140], [359, 200], 1) - pygame.draw.line(screen, WHITE, [360, 140], [362, 200], 1) - pygame.draw.line(screen, WHITE, [364, 140], [365, 200], 1) - pygame.draw.line(screen, WHITE, [368, 140], [369, 200], 1) - pygame.draw.line(screen, WHITE, [372, 140], [373, 200], 1) - pygame.draw.line(screen, WHITE, [376, 140], [377, 200], 1) - pygame.draw.line(screen, WHITE, [380, 140], [380, 200], 1) - pygame.draw.line(screen, WHITE, [384, 140], [384, 200], 1) - pygame.draw.line(screen, WHITE, [388, 140], [388, 200], 1) - pygame.draw.line(screen, WHITE, [392, 140], [392, 200], 1) - pygame.draw.line(screen, WHITE, [396, 140], [396, 200], 1) - pygame.draw.line(screen, WHITE, [400, 140], [400, 200], 1) - pygame.draw.line(screen, WHITE, [404, 140], [404, 200], 1) - pygame.draw.line(screen, WHITE, [408, 140], [408, 200], 1) - pygame.draw.line(screen, WHITE, [412, 140], [412, 200], 1) - pygame.draw.line(screen, WHITE, [416, 140], [416, 200], 1) - pygame.draw.line(screen, WHITE, [420, 140], [420, 200], 1) - pygame.draw.line(screen, WHITE, [424, 140], [423, 200], 1) - pygame.draw.line(screen, WHITE, [428, 140], [427, 200], 1) - pygame.draw.line(screen, WHITE, [432, 140], [431, 200], 1) - pygame.draw.line(screen, WHITE, [436, 140], [435, 200], 1) - pygame.draw.line(screen, WHITE, [440, 140], [438, 200], 1) - pygame.draw.line(screen, WHITE, [445, 140], [441, 200], 1) - pygame.draw.line(screen, WHITE, [450, 140], [444, 200], 1) - pygame.draw.line(screen, WHITE, [455, 140], [447, 200], 1) - pygame.draw.line(screen, WHITE, [460, 140], [450, 200], 1) - pygame.draw.line(screen, WHITE, [465, 140], [453, 200], 1) - pygame.draw.line(screen, WHITE, [470, 140], [456, 200], 1) - pygame.draw.line(screen, WHITE, [475, 140], [459, 200], 1) - - netPartTwo(WHITE,320,140,324,216, 1) - netPartThree(WHITE,480,140,476,216,1) + #Function to draw the goal post with parameters Colour and width + drawGoalPost(WHITE,1) + drawStands(WHITE, RED) - #net part 4 - pygame.draw.line(screen, WHITE, [324, 144], [476, 144], 1) - pygame.draw.line(screen, WHITE, [324, 148], [476, 148], 1) - pygame.draw.line(screen, WHITE, [324, 152], [476, 152], 1) - pygame.draw.line(screen, WHITE, [324, 156], [476, 156], 1) - pygame.draw.line(screen, WHITE, [324, 160], [476, 160], 1) - pygame.draw.line(screen, WHITE, [324, 164], [476, 164], 1) - pygame.draw.line(screen, WHITE, [324, 168], [476, 168], 1) - pygame.draw.line(screen, WHITE, [324, 172], [476, 172], 1) - pygame.draw.line(screen, WHITE, [324, 176], [476, 176], 1) - pygame.draw.line(screen, WHITE, [335, 180], [470, 180], 1) - pygame.draw.line(screen, WHITE, [335, 184], [465, 184], 1) - pygame.draw.line(screen, WHITE, [335, 188], [465, 188], 1) - pygame.draw.line(screen, WHITE, [335, 192], [465, 192], 1) - pygame.draw.line(screen, WHITE, [335, 196], [465, 196], 1) - - #stands right - pygame.draw.polygon(screen, RED, [[680, 220], [800, 340], [800, 290], [680, 180]]) - pygame.draw.polygon(screen, WHITE, [[680, 180], [800, 100], [800, 290]]) - - #stands left - pygame.draw.polygon(screen, RED, [[120, 220], [0, 340], [0, 290], [120, 180]]) - pygame.draw.polygon(screen, WHITE, [[120, 180], [0, 100], [0, 290]]) - #corner flag right pygame.draw.line(screen, BRIGHT_YELLOW, [140, 220], [135, 190], 3) pygame.draw.polygon(screen, RED, [[132, 190], [125, 196], [135, 205]]) From 0f683b1d8706ba1e15be19ffa62d394e034c1aea Mon Sep 17 00:00:00 2001 From: johnathanmitri Date: Mon, 24 Apr 2023 01:39:05 -0700 Subject: [PATCH 05/11] Resizable and Recolorable clouds Clouds can be resized and recolored. Set clouds to 3x size. --- .../major league soccer animation/graphics_v4.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index 32d42f9..0a83882 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -47,7 +47,7 @@ SEE_THROUGH.set_alpha(150) SEE_THROUGH.fill((124, 118, 135)) -def draw_cloud(x, y): +def draw_cloud(color, x, y, scale): ''' This function draws a cloud shape on the Pygame surface specified by the global variable SEE_THROUGH. The cloud shape consists of four ellipses and one rectangle, all with the same color specified by the @@ -55,18 +55,20 @@ def draw_cloud(x, y): given x and y coordinates. Parameters: + color (tuple): The color for the cloud as a tuple of 3 integers representing the RGB color. x (int): The x-coordinate of the top-left corner of the cloud shape. y (int): The y-coordinate of the top-left corner of the cloud shape. + scale (float): Scale factor to resize the cloud. Returns: None ''' - pygame.draw.ellipse(SEE_THROUGH, cloud_color, [x, y + 8, 10, 10]) - pygame.draw.ellipse(SEE_THROUGH, cloud_color, [x + 6, y + 4, 8, 8]) - pygame.draw.ellipse(SEE_THROUGH, cloud_color, [x + 10, y, 16, 16]) - pygame.draw.ellipse(SEE_THROUGH, cloud_color, [x + 20, y + 8, 10, 10]) - pygame.draw.rect(SEE_THROUGH, cloud_color, [x + 6, y + 8, 18, 10]) + pygame.draw.ellipse(SEE_THROUGH, color, [x, y + 8*scale, 10*scale, 10*scale]) + pygame.draw.ellipse(SEE_THROUGH, color, [x + 6*scale, y + 4*scale, 8*scale, 8*scale]) + pygame.draw.ellipse(SEE_THROUGH, color, [x + 10*scale, y, 16*scale, 16*scale]) + pygame.draw.ellipse(SEE_THROUGH, color, [x + 20*scale, y + 8*scale, 10*scale, 10*scale]) + pygame.draw.rect(SEE_THROUGH, color, [x + 6*scale, y + 8*scale, 18*scale, 10*scale]) def lights(a, b): '''lights(a,b) function creates the head of a stadium lights @@ -284,7 +286,7 @@ def drawStands (upperStandColor, lowerStandColor): for c in clouds: - draw_cloud(c[0], c[1]) + draw_cloud(cloud_color, c[0], c[1], 3) screen.blit(SEE_THROUGH, (0, 0)) From 6728c512da57bece5ae269bdd75608f370fdc76b Mon Sep 17 00:00:00 2001 From: johnathanmitri Date: Mon, 24 Apr 2023 02:34:29 -0700 Subject: [PATCH 06/11] Refactored and added changes Refactored star code, and gave stars random colors and sizes. Refactored the field line code into one function. Refactored the flag code, and made them bounce up and down. Made clouds random sizes. --- .../graphics_v4.py | 91 ++++++++++++------- 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index 0a83882..c7925c2 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -186,9 +186,44 @@ def drawStands (upperStandColor, lowerStandColor): pygame.draw.polygon(screen, lowerStandColor, [[120, 220], [0, 340], [0, 290], [120, 180]]) pygame.draw.polygon(screen, upperStandColor, [[120, 180], [0, 100], [0, 290]]) +def drawLeftFlag(x, y, poleColor, flagColor): + pygame.draw.line(screen, poleColor, [x, y], [x-5, y-30], 3) + pygame.draw.polygon(screen, flagColor, [[x-8, y-30], [x-15, y-24], [x-5, y-15]]) +def drawRightFlag(x, y, poleColor, flagColor): + pygame.draw.line(screen, poleColor, [x, y], [x+5, y-30], 3) + pygame.draw.polygon(screen, flagColor, [[x+8, y-30], [x+15, y-24], [x+5, y-15]]) +def drawFieldLines(color): + #bottom side of out of bounds + pygame.draw.line(screen, color, [0, 580], [800, 580], 5) + + #left side of out of bounds + pygame.draw.line(screen, color, [0, 360], [140, 220], 5) + pygame.draw.line(screen, color, [140, 220], [660, 220], 3) + + #right side of out of bounds + pygame.draw.line(screen, color, [660, 220], [800, 360], 5) + + #safety circle + pygame.draw.ellipse(screen, color, [240, 500, 320, 160], 5) + + #18 yard line goal box + pygame.draw.line(screen, color, [260, 220], [180, 300], 5) + pygame.draw.line(screen, color, [180, 300], [620, 300], 3) + pygame.draw.line(screen, color, [620, 300], [540, 220], 5) + + #6 yard line goal box + pygame.draw.line(screen, color, [310, 220], [270, 270], 3) + pygame.draw.line(screen, color, [270, 270], [530, 270], 2) + pygame.draw.line(screen, color, [530, 270], [490, 220], 3) + + #arc at the top of the goal box + pygame.draw.arc(screen, color, [330, 280, 140, 40], math.pi, 2 * math.pi, 5) +def drawStar(x, y, color, scale): + pygame.draw.ellipse(screen, color, [x,y,scale,scale]) + # Config lights_on = True day = True @@ -199,17 +234,23 @@ def drawStands (upperStandColor, lowerStandColor): x = random.randrange(0, 800) y = random.randrange(0, 200) r = random.randrange(1, 2) - stars.append([x, y, r, r]) + color = random.choice([RED,GREEN,BLUE,YELLOW,WHITE]) + scale = random.uniform(0.5, 3) + stars.append([x, y, color, scale]) clouds = [] for i in range(20): x = random.randrange(-100, 1600) y = random.randrange(0, 150) - clouds.append([x, y]) + scale = random.uniform(0.5, 3) + clouds.append([x, y, scale]) # Game loop done = False +# Y to allow flags to move side to side +flagHorizontalCounter = 0 + while not done: # Event processing (React to key presses, mouse clicks, etc.) ''' for now, we'll just check to see if the X is clicked ''' @@ -255,7 +296,8 @@ def drawStands (upperStandColor, lowerStandColor): if not day: #stars for s in stars: - pygame.draw.ellipse(screen, WHITE, s) + drawStar(s[0], s[1], s[2], s[3]) + #pygame.draw.ellipse(screen, WHITE, s) pygame.draw.rect(screen, field_color, [0, 180, 800 , 420]) pygame.draw.rect(screen, stripe_color, [0, 180, 800, 42]) @@ -286,32 +328,11 @@ def drawStands (upperStandColor, lowerStandColor): for c in clouds: - draw_cloud(cloud_color, c[0], c[1], 3) + draw_cloud(cloud_color, c[0], c[1], c[2]) screen.blit(SEE_THROUGH, (0, 0)) - #out of bounds lines - - #bottom side of out of bounds - pygame.draw.line(screen, WHITE, [0, 580], [800, 580], 5) - - #left side of out of bounds - pygame.draw.line(screen, WHITE, [0, 360], [140, 220], 5) - pygame.draw.line(screen, WHITE, [140, 220], [660, 220], 3) - - #right side of out of bounds - pygame.draw.line(screen, WHITE, [660, 220], [800, 360], 5) - - #safety circle - pygame.draw.ellipse(screen, WHITE, [240, 500, 320, 160], 5) - - #18 yard line goal box - pygame.draw.line(screen, WHITE, [260, 220], [180, 300], 5) - pygame.draw.line(screen, WHITE, [180, 300], [620, 300], 3) - pygame.draw.line(screen, WHITE, [620, 300], [540, 220], 5) - - #arc at the top of the goal box - pygame.draw.arc(screen, WHITE, [330, 280, 140, 40], math.pi, 2 * math.pi, 5) + drawFieldLines(WHITE) #score board pole pygame.draw.rect(screen, GRAY, [390, 120, 20, 70]) @@ -328,10 +349,6 @@ def drawStands (upperStandColor, lowerStandColor): pygame.draw.line(screen, WHITE, [320, 140], [340, 200], 3) pygame.draw.line(screen, WHITE, [480, 140], [460, 200], 3) - #6 yard line goal box - pygame.draw.line(screen, WHITE, [310, 220], [270, 270], 3) - pygame.draw.line(screen, WHITE, [270, 270], [530, 270], 2) - pygame.draw.line(screen, WHITE, [530, 270], [490, 220], 3) #light pole 1 pygame.draw.rect(screen, GRAY, [150, 60, 20, 140]) @@ -352,13 +369,17 @@ def drawStands (upperStandColor, lowerStandColor): drawStands(WHITE, RED) - #corner flag right - pygame.draw.line(screen, BRIGHT_YELLOW, [140, 220], [135, 190], 3) - pygame.draw.polygon(screen, RED, [[132, 190], [125, 196], [135, 205]]) + #flag moving code + flagHorizontalCounter+=0.75 + offset = flagHorizontalCounter % 40 - 20 + if (offset > 0): + offset *= -1 #corner flag left - pygame.draw.line(screen, BRIGHT_YELLOW, [660, 220], [665, 190], 3) - pygame.draw.polygon(screen, RED, [[668, 190], [675, 196], [665, 205]]) + drawLeftFlag(140, 220 + offset, YELLOW, RED) + + #corner flag right + drawRightFlag(660, 220 + offset, YELLOW, RED) # DARKNESS if not day and not lights_on: From 4944e579c97a8300d6536f1b1067be07476610e9 Mon Sep 17 00:00:00 2001 From: johnathanmitri Date: Mon, 24 Apr 2023 09:07:51 -0700 Subject: [PATCH 07/11] Refactor grass Refactored grass code, and also fixed a typo --- .../graphics_v4.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index c7925c2..51ae3c9 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -70,6 +70,13 @@ def draw_cloud(color, x, y, scale): pygame.draw.ellipse(SEE_THROUGH, color, [x + 20*scale, y + 8*scale, 10*scale, 10*scale]) pygame.draw.rect(SEE_THROUGH, color, [x + 6*scale, y + 8*scale, 18*scale, 10*scale]) +def drawGrass(color1, color2): + pygame.draw.rect(screen, color1, [0, 180, 800 , 420]) + pygame.draw.rect(screen, color2, [0, 180, 800, 42]) + pygame.draw.rect(screen, color2, [0, 264, 800, 52]) + pygame.draw.rect(screen, color2, [0, 368, 800, 62]) + pygame.draw.rect(screen, color2, [0, 492, 800, 82]) + def lights(a, b): '''lights(a,b) function creates the head of a stadium lights @@ -248,8 +255,9 @@ def drawStar(x, y, color, scale): # Game loop done = False -# Y to allow flags to move side to side -flagHorizontalCounter = 0 + +# Counter to allow flags to bounce up and down +flagVerticalCounter = 0 while not done: # Event processing (React to key presses, mouse clicks, etc.) @@ -297,13 +305,9 @@ def drawStar(x, y, color, scale): #stars for s in stars: drawStar(s[0], s[1], s[2], s[3]) - #pygame.draw.ellipse(screen, WHITE, s) - - pygame.draw.rect(screen, field_color, [0, 180, 800 , 420]) - pygame.draw.rect(screen, stripe_color, [0, 180, 800, 42]) - pygame.draw.rect(screen, stripe_color, [0, 264, 800, 52]) - pygame.draw.rect(screen, stripe_color, [0, 368, 800, 62]) - pygame.draw.rect(screen, stripe_color, [0, 492, 800, 82]) + + drawGrass(field_color, stripe_color) + '''fence''' @@ -370,8 +374,8 @@ def drawStar(x, y, color, scale): #flag moving code - flagHorizontalCounter+=0.75 - offset = flagHorizontalCounter % 40 - 20 + flagVerticalCounter+=0.75 + offset = flagVerticalCounter % 40 - 20 if (offset > 0): offset *= -1 From 7d17a291d7e8b6ada8787f565f01bbc7239d784e Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 24 Apr 2023 10:33:08 -0700 Subject: [PATCH 08/11] Update graphics_v4.py --- .../graphics_v4.py | 103 ++++++++++-------- 1 file changed, 59 insertions(+), 44 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index 9374dc2..9506529 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -3,7 +3,7 @@ import math import random - +#easy modifications such as altering object locations, quantities, and sizes # Initialize game engine pygame.init() @@ -68,31 +68,66 @@ def draw_cloud(x, y): pygame.draw.ellipse(SEE_THROUGH, cloud_color, [x + 20, y + 8, 10, 10]) pygame.draw.rect(SEE_THROUGH, cloud_color, [x + 6, y + 8, 18, 10]) -def lights(a, b): - '''lights(a,b) function creates the head of a stadium lights +def stadium_light(pole_color, pole_dimensions, lights_color, light_dimension_x, light_dimension_y ): + '''stadium_light function creates the stadium lights that include the pole and 10 lights. The parameters allow the change of + colors and positioning of the pole and lights. + + Parameters: + pole_color (String): desired color for the pole + pole_dimensions (int List): dimensions of the pole. [left, top, width, height] + lights_color (String): desired color for the lights + light_dimension_x: where the desired rows of lights would start being drawn from + light_dimension_y: where the desired rows of lights would end at + + Returns: + None + ''' - :param: a determines positioning of the stadium head graphic - :param: b figures out the length of where the pygame draws + pygame.draw.rect(screen, pole_color, pole_dimensions) + pygame.draw.ellipse(screen, pole_color, [pole_dimensions[0],pole_dimensions[1]+135, pole_dimensions[2], pole_dimensions[3]-130]) + n = 0 + height = 0 + for i in range(2): + pygame.draw.line(screen, pole_color, [light_dimension_x, 60-height], [light_dimension_y, 60-height], 2) + for i in range(5): + pygame.draw.ellipse(screen, lights_color, [light_dimension_x + n, 40 - height, 20, 20]) + n += 20 + n = 0 + height += 20 + pygame.draw.line(screen, pole_color, [light_dimension_x, 20], [light_dimension_y, 20], 2) + + #pygame.draw.rect(screen, GRAY, [150, 60, 20, 140]) + #pygame.draw.ellipse(screen, GRAY, [150, 195, 20, 10]) + #lights(110,210) + +def fence(color): + '''fence function determines the background fence of the graphic. With the parameters able to change the color and positioning + of the fence. + + Parameters: + color (String): desired color of the fence + x_pos (int): x position of the fence + y_pos (int): y position of the fence + + Returns: + None ''' - pygame.draw.line(screen, GRAY, [a, 60], [b, 60], 2) - pygame.draw.ellipse(screen, light_color, [a, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [a+20, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [a+40, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [a+60, 40, 20, 20]) - pygame.draw.ellipse(screen, light_color, [a+80, 40, 20, 20]) - pygame.draw.line(screen, GRAY, [a, 40], [b, 40], 2) - pygame.draw.ellipse(screen, light_color, [a, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [a+20, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [a+40, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [a+60, 20, 20, 20]) - pygame.draw.ellipse(screen, light_color, [a+80, 20, 20, 20]) - pygame.draw.line(screen, GRAY, [a, 20], [b, 20], 2) + y = 170 + for x in range(5, 800, 30): + pygame.draw.polygon(screen, color, [[x + 2, y], [x + 2, y + 15], [x, y + 15], [x, y]]) + + y = 170 + for x in range(5, 800, 3): + pygame.draw.line(screen, color, [x, y], [x, y + 15], 1) + + x = 0 + for y in range(170, 185, 4): + pygame.draw.line(screen, color, [x, y], [x + 800, y], 1) # Config lights_on = True day = True - stars = [] for n in range(200): x = random.randrange(0, 800) @@ -164,17 +199,7 @@ def lights(a, b): '''fence''' - y = 170 - for x in range(5, 800, 30): - pygame.draw.polygon(screen, NIGHT_GRAY, [[x + 2, y], [x + 2, y + 15], [x, y + 15], [x, y]]) - - y = 170 - for x in range(5, 800, 3): - pygame.draw.line(screen, NIGHT_GRAY, [x, y], [x, y + 15], 1) - - x = 0 - for y in range(170, 185, 4): - pygame.draw.line(screen, NIGHT_GRAY, [x, y], [x + 800, y], 1) + fence(NIGHT_GRAY) if day: pygame.draw.ellipse(screen, BRIGHT_YELLOW, [520, 50, 40, 40]) @@ -182,8 +207,6 @@ def lights(a, b): pygame.draw.ellipse(screen, WHITE, [520, 50, 40, 40]) pygame.draw.ellipse(screen, sky_color, [530, 45, 40, 40]) - - for c in clouds: draw_cloud(c[0], c[1]) screen.blit(SEE_THROUGH, (0, 0)) @@ -232,19 +255,11 @@ def lights(a, b): pygame.draw.line(screen, WHITE, [270, 270], [530, 270], 2) pygame.draw.line(screen, WHITE, [530, 270], [490, 220], 3) - #light pole 1 - pygame.draw.rect(screen, GRAY, [150, 60, 20, 140]) - pygame.draw.ellipse(screen, GRAY, [150, 195, 20, 10]) - - #lights pole 1 - lights(110,210) - - #light pole 2 - pygame.draw.rect(screen, GRAY, [630, 60, 20, 140]) - pygame.draw.ellipse(screen, GRAY, [630, 195, 20, 10]) + #light pole and lights 1 + stadium_light(GRAY,[150, 60, 20, 140], YELLOW, 110,210) - #lights - lights(590,690) + #light pole and lights 2 + stadium_light(GRAY,[630, 60, 20, 140], YELLOW, 590,690) #net pygame.draw.line(screen, WHITE, [325, 140], [341, 200], 1) From 5784370b4600893d3105e5c88f355b1aa5bfa0ac Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 24 Apr 2023 13:44:51 -0700 Subject: [PATCH 09/11] Update graphics_v4.py --- .../major league soccer animation/graphics_v4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index 414c201..103dd69 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -378,10 +378,10 @@ def drawStar(x, y, color, scale): #light pole and lights 1 - stadium_light(GRAY,[150, 60, 20, 140], YELLOW, 110,210) + stadium_light(GRAY,[150, 60, 20, 140], light_color, 110,210) #light pole and lights 2 - stadium_light(GRAY,[630, 60, 20, 140], YELLOW, 590,690) + stadium_light(GRAY,[630, 60, 20, 140], light_color, 590,690) #Function to draw the goal post with parameters Colour and width drawGoalPost(WHITE,1) From 0d14ab9f2ff16fbca397f6209cfb326b843c8929 Mon Sep 17 00:00:00 2001 From: zackgeek <131562039+zackgeek@users.noreply.github.com> Date: Tue, 25 Apr 2023 22:15:02 -0700 Subject: [PATCH 10/11] Update graphics_v4.py --- .../graphics_v4.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index 103dd69..92b6ebd 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -197,7 +197,6 @@ def netPartThree(color, width): endingYAxis -= 2 def netPartFour(color, width): - #net part 4 pygame.draw.line(screen, color, [324, 144], [476, 144], width) pygame.draw.line(screen, color, [324, 148], [476, 148], width) @@ -214,11 +213,21 @@ def netPartFour(color, width): pygame.draw.line(screen, color, [335, 192], [465, 192], width) pygame.draw.line(screen, color, [335, 196], [465, 196], width) +def goalPostBars(color): + #draw bars for goal post + pygame.draw.rect(screen, color, [320, 140, 160, 80], 5) + pygame.draw.line(screen, color, [340, 200], [460, 200], 3) + pygame.draw.line(screen, color, [320, 220], [340, 200], 3) + pygame.draw.line(screen, color, [480, 220], [460, 200], 3) + pygame.draw.line(screen, color, [320, 140], [340, 200], 3) + pygame.draw.line(screen, color, [480, 140], [460, 200], 3) + def drawGoalPost(color, width): netPartOne(color,width) netPartTwo(color, width) netPartThree(color,width) netPartFour(color, width) + goalPostBars(color) def drawStands (upperStandColor, lowerStandColor): #stands right @@ -366,15 +375,7 @@ def drawStar(x, y, color, scale): #score board pygame.draw.rect(screen, BLACK, [300, 40, 200, 90]) - pygame.draw.rect(screen, WHITE, [302, 42, 198, 88], 2) - - #goal - pygame.draw.rect(screen, WHITE, [320, 140, 160, 80], 5) - pygame.draw.line(screen, WHITE, [340, 200], [460, 200], 3) - pygame.draw.line(screen, WHITE, [320, 220], [340, 200], 3) - pygame.draw.line(screen, WHITE, [480, 220], [460, 200], 3) - pygame.draw.line(screen, WHITE, [320, 140], [340, 200], 3) - pygame.draw.line(screen, WHITE, [480, 140], [460, 200], 3) + pygame.draw.rect(screen, WHITE, [301, 41, 198, 88], 2) #light pole and lights 1 @@ -383,8 +384,9 @@ def drawStar(x, y, color, scale): #light pole and lights 2 stadium_light(GRAY,[630, 60, 20, 140], light_color, 590,690) - #Function to draw the goal post with parameters Colour and width + #Function to draw the goal post with parameters Colour and width for net lines drawGoalPost(WHITE,1) + drawStands(WHITE, RED) From ff0ceeda9d8f2e86b8ddcc6171333af47a2ad426 Mon Sep 17 00:00:00 2001 From: zackgeek <131562039+zackgeek@users.noreply.github.com> Date: Tue, 25 Apr 2023 22:46:52 -0700 Subject: [PATCH 11/11] Update graphics_v4.py --- .../graphics_v4.py | 69 ++++++++++++++----- 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py index 92b6ebd..ff92b76 100644 --- a/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py +++ b/Intro to Pygame Graphics/major league soccer animation/graphics_v4.py @@ -1,3 +1,4 @@ + # Imports import pygame import math @@ -53,13 +54,11 @@ def draw_cloud(color, x, y, scale): The cloud shape consists of four ellipses and one rectangle, all with the same color specified by the global variable cloud_color. The coordinates of the ellipses and rectangle are calculated based on the given x and y coordinates. - Parameters: color (tuple): The color for the cloud as a tuple of 3 integers representing the RGB color. x (int): The x-coordinate of the top-left corner of the cloud shape. y (int): The y-coordinate of the top-left corner of the cloud shape. scale (float): Scale factor to resize the cloud. - Returns: None ''' @@ -80,14 +79,12 @@ def drawGrass(color1, color2): def stadium_light(pole_color, pole_dimensions, lights_color, light_dimension_x, light_dimension_y ): '''stadium_light function creates the stadium lights that include the pole and 10 lights. The parameters allow the change of colors and positioning of the pole and lights. - Parameters: pole_color (String): desired color for the pole pole_dimensions (int List): dimensions of the pole. [left, top, width, height] lights_color (String): desired color for the lights light_dimension_x: where the desired rows of lights would start being drawn from light_dimension_y: where the desired rows of lights would end at - Returns: None ''' @@ -117,7 +114,6 @@ def fence(color): color (String): desired color of the fence x_pos (int): x position of the fence y_pos (int): y position of the fence - Returns: None ''' @@ -170,6 +166,8 @@ def netPartOne(color, width): pygame.draw.line(screen, color, [465, 140], [453, 200], width) pygame.draw.line(screen, color, [470, 140], [456, 200], width) pygame.draw.line(screen, color, [475, 140], [459, 200], width) + '''pygame draw line function are commands used to draw the net. The color and width specified in the function + parameter are applied to each line drawing. each line beginning and end points coordinates''' def netPartTwo(color, width): @@ -182,7 +180,13 @@ def netPartTwo(color, width): pygame.draw.line(screen, color, [StartingXAxis, StartingYAxis], [endingXAxis, endingYAxis], width) endingXAxis += 2 endingYAxis -= 2 +'''uses a for loop to draw a series of diagonal lines with a constant slope. The loop iterates 8 times, and on each iteration + a new diagonal line is drawn using pygame.draw.line. + +StartingXAxis, StartingYAxis, endingXAxis, and endingYAxis variables. These variables are initialized before the loop, and their values are updated on each iteration to create the diagonal slope. +variables are updated on each iteration of the loop using the += operator to increase the X. +''' def netPartThree(color, width): @@ -194,9 +198,11 @@ def netPartThree(color, width): for i in range(8): pygame.draw.line(screen, color, [StartingXAxis, StartingYAxis], [endingXAxis, endingYAxis], width) endingXAxis -= 2 - endingYAxis -= 2 + endingYAxis -= 2 + '''same as above expect in the loop using the -= operator to decrease the x that creates a diagonal slope with a constant slope of +1''' def netPartFour(color, width): + #net part 4 pygame.draw.line(screen, color, [324, 144], [476, 144], width) pygame.draw.line(screen, color, [324, 148], [476, 148], width) @@ -212,7 +218,11 @@ def netPartFour(color, width): pygame.draw.line(screen, color, [335, 188], [465, 188], width) pygame.draw.line(screen, color, [335, 192], [465, 192], width) pygame.draw.line(screen, color, [335, 196], [465, 196], width) - + '''netPartFour uses a combination of horizontal and diagonal lines to create the net shape. The first 9 lines are drawn horizontally using pygame.draw.line + to create the top of the net, while the remaining 5 lines are drawn diagonally to create the bottom part of the net. + + a combination of horizontal and diagonal lines to create the overall shape''' + def goalPostBars(color): #draw bars for goal post pygame.draw.rect(screen, color, [320, 140, 160, 80], 5) @@ -222,12 +232,14 @@ def goalPostBars(color): pygame.draw.line(screen, color, [320, 140], [340, 200], 3) pygame.draw.line(screen, color, [480, 140], [460, 200], 3) + def drawGoalPost(color, width): netPartOne(color,width) netPartTwo(color, width) netPartThree(color,width) netPartFour(color, width) goalPostBars(color) + '''this function calls and all parts of the net to complete the shape of the goal post.''' def drawStands (upperStandColor, lowerStandColor): #stands right @@ -237,6 +249,11 @@ def drawStands (upperStandColor, lowerStandColor): #stands left pygame.draw.polygon(screen, lowerStandColor, [[120, 220], [0, 340], [0, 290], [120, 180]]) pygame.draw.polygon(screen, upperStandColor, [[120, 180], [0, 100], [0, 290]]) + '''Each set of stands is drawn using pygame.draw.polygon, which allows for the drawing of irregular shapes with multiple vertices. + The lowerStandColor argument is used to color the lower parts of the stands, while the upperStandColor argument is used to color the upper parts of the stands. + + The vertices of each polygon are hardcoded into the function using a series of [x, y] coordinate pairs. + The first pair in each polygon corresponds to the bottom left corner of the stand, and the subsequent pairs define the shape of the polygon.''' def drawLeftFlag(x, y, poleColor, flagColor): pygame.draw.line(screen, poleColor, [x, y], [x-5, y-30], 3) @@ -245,6 +262,8 @@ def drawLeftFlag(x, y, poleColor, flagColor): def drawRightFlag(x, y, poleColor, flagColor): pygame.draw.line(screen, poleColor, [x, y], [x+5, y-30], 3) pygame.draw.polygon(screen, flagColor, [[x+8, y-30], [x+15, y-24], [x+5, y-15]]) + '''The vertices of the polygon are hardcoded into the function using a series of [x, y] coordinate pairs. + The coordinates of these pairs determine the shape of the flag.''' def drawFieldLines(color): #bottom side of out of bounds @@ -259,7 +278,8 @@ def drawFieldLines(color): #safety circle pygame.draw.ellipse(screen, color, [240, 500, 320, 160], 5) - + '''The function begins by drawing a line along the bottom edge of the screen to mark the out-of-bounds area. + It then draws lines along the left and right edges of the field to define the out-of-bounds areas on those sides. Next, it draws an ellipse to mark the "safety circle" in the center of the field.''' #18 yard line goal box pygame.draw.line(screen, color, [260, 220], [180, 300], 5) pygame.draw.line(screen, color, [180, 300], [620, 300], 3) @@ -272,13 +292,15 @@ def drawFieldLines(color): #arc at the top of the goal box pygame.draw.arc(screen, color, [330, 280, 140, 40], math.pi, 2 * math.pi, 5) + '''The function then draws the 18-yard line goal box, which is the rectangular area in front of each goal where certain rules apply. + Finally, it draws the smaller 6-yard line goal box within the larger box, and the curved arc at the top of the larger box that defines the penalty area''' def drawStar(x, y, color, scale): pygame.draw.ellipse(screen, color, [x,y,scale,scale]) - + '''The size of the ellipse is determined by the scale argument specifies the width and height of the ellipse in pixels''' # Config -lights_on = True -day = True +lights_on = True #This variable could be used to control whether or not the lights in a game or application are turned on or off. +day = True #This variable could be used to control the appearance or behavior of the game or application based on the time of day. stars = [] for n in range(200): @@ -288,6 +310,11 @@ def drawStar(x, y, color, scale): color = random.choice([RED,GREEN,BLUE,YELLOW,WHITE]) scale = random.uniform(0.5, 3) stars.append([x, y, color, scale]) + '''for loop to generate 200 stars + x,y are set randomly generates color and scale also has a certain range + r is the radius of the star + color is also randomly generated from 5 different colors + scale is also randomly generated size between 0.5 to 3 f''' clouds = [] for i in range(20): @@ -295,10 +322,14 @@ def drawStar(x, y, color, scale): y = random.randrange(0, 150) scale = random.uniform(0.5, 3) clouds.append([x, y, scale]) - + '''for loop generate 20 clouds + x,y make a random integer between two values for the size of the cloud + scale is also a random floating point for the size of each cloud + ''' + # Game loop done = False - +'''the done variable can be set to True to stop the game loop and exit the program.''' # Counter to allow flags to bounce up and down flagVerticalCounter = 0 @@ -355,7 +386,7 @@ def drawStar(x, y, color, scale): '''fence''' - fence(NIGHT_GRAY) + fence(NIGHT_GRAY) if day: pygame.draw.ellipse(screen, BRIGHT_YELLOW, [520, 50, 40, 40]) @@ -365,8 +396,8 @@ def drawStar(x, y, color, scale): for c in clouds: draw_cloud(cloud_color, c[0], c[1], c[2]) - screen.blit(SEE_THROUGH, (0, 0)) - + screen.blit(SEE_THROUGH, (0, 0)) #transparency + '''to draw the fence set the color for night and day and loop that iterates over the colouds''' drawFieldLines(WHITE) @@ -376,6 +407,7 @@ def drawStar(x, y, color, scale): #score board pygame.draw.rect(screen, BLACK, [300, 40, 200, 90]) pygame.draw.rect(screen, WHITE, [301, 41, 198, 88], 2) + #light pole and lights 1 @@ -384,9 +416,8 @@ def drawStar(x, y, color, scale): #light pole and lights 2 stadium_light(GRAY,[630, 60, 20, 140], light_color, 590,690) - #Function to draw the goal post with parameters Colour and width for net lines + #Function to draw the goal post with parameters Color and width for net lines drawGoalPost(WHITE,1) - drawStands(WHITE, RED) @@ -416,4 +447,4 @@ def drawStar(x, y, color, scale): # Close window and quit -pygame.quit() +pygame.quit() \ No newline at end of file