-
Notifications
You must be signed in to change notification settings - Fork 0
/
sun-and-moon.py
87 lines (66 loc) · 2.81 KB
/
sun-and-moon.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
"""
Rohan Shah
Mouseclick to draw sun -- moon will follow """
import pygame
SIENNA = (160, 82, 45)
FORESTGREEN = (34, 139, 34)
SADDLEBROWN = (139, 69, 19)
LIGHTSKYBLUE = (135, 206, 250)
GOLD = (255, 215, 0)
LIGHTGRAY = (211, 211, 211)
pygame.init()
screen = pygame.display.set_mode((400, 400), 0, 32)
pygame.display.set_caption("Sun and Moon")
#skies
screen.fill(LIGHTSKYBLUE)
pygame.draw.rect(screen, (0, 0, 0), (0, 200, 400, 200))
#top trees
pygame.draw.rect(screen, SIENNA, (305, 190, 5, 10))
pygame.draw.polygon(screen, FORESTGREEN, ((300, 190), (315, 190),( 307, 160)))
pygame.draw.rect(screen, SIENNA, (335, 190, 5, 10))
pygame.draw.polygon(screen, FORESTGREEN, ((330, 190),( 345, 190), (337, 140)))
# bottom trees
pygame.draw.polygon(screen, SADDLEBROWN, ((305, 200), (310, 200), (307, 250)))
pygame.draw.line(screen, SADDLEBROWN, (305, 210), (300, 215), 3)
pygame.draw.line(screen, SADDLEBROWN, (308, 215), (315, 220), 3)
pygame.draw.polygon(screen, SADDLEBROWN, ((335, 200), (340, 200), (337, 270)))
pygame.draw.line(screen, SADDLEBROWN, (338, 215), (345, 220), 3)
pygame.draw.line(screen, SADDLEBROWN, (335, 225), (330, 230), 3)
pygame.draw.line(screen, SADDLEBROWN, (338, 235), (345, 240), 3)
# sun/moon
sunX = 100
sunY = 100
moonX = 100
moonY = 300
pygame.draw.circle(screen, GOLD, (sunX, sunY), 20)
pygame.draw.circle(screen, LIGHTGRAY, (moonX, moonY), 20)
while True:
#skies
screen.fill(LIGHTSKYBLUE)
pygame.draw.rect(screen, (0, 0, 0), (0, 200, 400, 200))
#top trees
pygame.draw.rect(screen, SIENNA, (305, 190, 5, 10))
pygame.draw.polygon(screen, FORESTGREEN, ((300, 190), (315, 190),( 307, 160)))
pygame.draw.rect(screen, SIENNA, (335, 190, 5, 10))
pygame.draw.polygon(screen, FORESTGREEN, ((330, 190),( 345, 190), (337, 140)))
# bottom trees
pygame.draw.polygon(screen, SADDLEBROWN, ((305, 200), (310, 200), (307, 250)))
pygame.draw.line(screen, SADDLEBROWN, (305, 210), (300, 215), 3)
pygame.draw.line(screen, SADDLEBROWN, (308, 215), (315, 220), 3)
pygame.draw.polygon(screen, SADDLEBROWN, ((335, 200), (340, 200), (337, 270)))
pygame.draw.line(screen, SADDLEBROWN, (338, 215), (345, 220), 3)
pygame.draw.line(screen, SADDLEBROWN, (335, 225), (330, 230), 3)
pygame.draw.line(screen, SADDLEBROWN, (338, 235), (345, 240), 3)
pygame.draw.circle(screen, GOLD, (sunX, sunY), 20)
pygame.draw.circle(screen, LIGHTGRAY, (moonX, moonY), 20)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if pos[1] < 180:
sunX = pos[0]
sunY = pos[1]
moonX = pos[0]
moonY = 400 - pos[1]
pygame.display.update()