Browse Source

昼から夕方への遷移をスムーズに

sicawke
みてるぞ 6 months ago
parent
commit
436f21244d
2 changed files with 25 additions and 14 deletions
  1. BIN
      bg.jpg
  2. +25
    -14
      main.py

BIN
bg.jpg View File

Before After
Width: 480  |  Height: 360  |  Size: 40 KiB

+ 25
- 14
main.py View File

@@ -64,6 +64,11 @@ class Main:
if goatoh_mode:
balloon = pygame.transform.flip (balloon, False, True)

# 背景(昼)
bg_day: pygame.Surface = pygame.transform.scale (
pygame.image.load ('bg.jpg'),
(CWindow.WIDTH, CWindow.HEIGHT))

# 背景(夕方)
bg_evening: pygame.Surface = pygame.transform.scale (
pygame.image.load ('bg-evening.jpg'),
@@ -124,7 +129,7 @@ class Main:
# 日の入終了
sunset_end: datetime = sunset_start + timedelta (hours = 1)

cls.draw_bg (screen, bg_evening, bg_night,
cls.draw_bg (screen, bg_day, bg_evening, bg_night,
sunrise_start, sunrise_end, sunset_start, sunset_end)

# 左上に時刻表示
@@ -248,7 +253,7 @@ class Main:
if not double_mode or random.random () < .5:
break

cls.draw_bg (screen, bg_evening, bg_night,
cls.draw_bg (screen, bg_day, bg_evening, bg_night,
sunrise_start, sunrise_end,
sunset_start, sunset_end)

@@ -277,6 +282,7 @@ class Main:
def draw_bg (
cls,
screen: pygame.Surface,
bg_day: pygame.Surface,
bg_evening: pygame.Surface,
bg_night: pygame.Surface,
sunrise_start: datetime,
@@ -284,23 +290,28 @@ class Main:
sunset_start: datetime,
sunset_end: datetime) \
-> None:
sunrise_centre: datetime = (
sunrise_start + (sunrise_end - sunrise_start) / 2)
sunset_centre: datetime = (
sunset_start + (sunset_end - sunset_start) / 2)

dt: datetime = datetime.now ()

if (dt < sunrise_end) or (sunset_start <= dt):
if sunrise_centre <= dt < sunset_centre:
screen.blit (bg_day, (0, 0))
else:
screen.blit (bg_night, (0, 0))

if sunrise_start <= dt < sunrise_end:
bg_evening.set_alpha (((dt - sunrise_start) * 255)
/ (sunrise_end - sunrise_start))
elif sunset_start <= dt < sunset_end:
bg_evening.set_alpha (((sunset_end - dt) * 255)
/ (sunset_end - sunset_start))
else:
bg_evening.set_alpha (0)

screen.blit (bg_evening, (0, 0))
if sunrise_start <= dt < sunrise_end:
bg_evening.set_alpha (255 - ((abs (dt - sunrise_centre) * 510)
/ (sunrise_end - sunrise_centre)))
elif sunset_start <= dt < sunset_end:
bg_evening.set_alpha (255 - ((abs (dt - sunset_centre) * 510)
/ (sunset_end - sunset_centre)))
else:
screen.fill ((0, 255, 0))
return

screen.blit (bg_evening, (0, 0))


if __name__ == '__main__':


Loading…
Cancel
Save