|
|
@@ -5,9 +5,10 @@ import random |
|
|
|
import subprocess |
|
|
|
import sys |
|
|
|
import time |
|
|
|
from datetime import datetime |
|
|
|
from datetime import datetime, timedelta |
|
|
|
|
|
|
|
import emoji |
|
|
|
import ephem |
|
|
|
import pygame |
|
|
|
import pytchat |
|
|
|
from playsound import playsound |
|
|
@@ -47,6 +48,16 @@ class Main: |
|
|
|
screen: pygame.Surface = pygame.display.set_mode ( |
|
|
|
(CWindow.WIDTH, CWindow.HEIGHT)) |
|
|
|
|
|
|
|
# 大月ヨヨコの観測値 |
|
|
|
observer = ephem.Observer () |
|
|
|
observer.lat, observer.lon = '35', '139' |
|
|
|
|
|
|
|
# き太く陽 |
|
|
|
sun = ephem.Sun () |
|
|
|
|
|
|
|
# 大月ヨヨコ |
|
|
|
moon = ephem.Moon () |
|
|
|
|
|
|
|
# 吹き出し |
|
|
|
balloon = pygame.transform.scale (pygame.image.load ('talking.png'), |
|
|
|
(CWindow.WIDTH, 384)) |
|
|
@@ -55,13 +66,13 @@ class Main: |
|
|
|
|
|
|
|
# 背景(夕方) |
|
|
|
bg_evening: pygame.Surface = pygame.transform.scale ( |
|
|
|
pygame.image.load ('bg-evening.jpg'), |
|
|
|
(CWindow.WIDTH, CWindow.HEIGHT)) |
|
|
|
pygame.image.load ('bg-evening.jpg'), |
|
|
|
(CWindow.WIDTH, CWindow.HEIGHT)) |
|
|
|
|
|
|
|
# 背景(夜) |
|
|
|
bg_night: pygame.Surface = pygame.transform.scale ( |
|
|
|
pygame.image.load ('bg-night.jpg'), |
|
|
|
(CWindow.WIDTH, CWindow.HEIGHT)) |
|
|
|
pygame.image.load ('bg-night.jpg'), |
|
|
|
(CWindow.WIDTH, CWindow.HEIGHT)) |
|
|
|
|
|
|
|
# 音声再生器の初期化 |
|
|
|
pygame.mixer.init (frequency = 44100) |
|
|
@@ -94,7 +105,27 @@ class Main: |
|
|
|
histories: list = [] |
|
|
|
|
|
|
|
while (True): |
|
|
|
cls.draw_bg (screen, bg_evening, bg_night) |
|
|
|
# 観測値の日づけ更新 |
|
|
|
observer.date: datetime = datetime.now ().date () |
|
|
|
|
|
|
|
# 日の出開始 |
|
|
|
sunrise_start: datetime = ( |
|
|
|
(ephem.localtime (observer.previous_rising (sun)) |
|
|
|
- timedelta (minutes = 30))) |
|
|
|
|
|
|
|
# 日の出終了 |
|
|
|
sunrise_end: datetime = sunrise_start + timedelta (hours = 1) |
|
|
|
|
|
|
|
# 日の入開始 |
|
|
|
sunset_start: datetime = ( |
|
|
|
(ephem.localtime (observer.next_setting (sun)) |
|
|
|
- timedelta (minutes = 30))) |
|
|
|
|
|
|
|
# 日の入終了 |
|
|
|
sunset_end: datetime = sunset_start + timedelta (hours = 1) |
|
|
|
|
|
|
|
cls.draw_bg (screen, bg_evening, bg_night, |
|
|
|
sunrise_start, sunrise_end, sunset_start, sunset_end) |
|
|
|
|
|
|
|
# 左上に時刻表示 |
|
|
|
for i in range (4): |
|
|
@@ -217,7 +248,9 @@ class Main: |
|
|
|
if not double_mode or random.random () < .5: |
|
|
|
break |
|
|
|
|
|
|
|
cls.draw_bg (screen, bg_evening, bg_night) |
|
|
|
cls.draw_bg (screen, bg_evening, bg_night, |
|
|
|
sunrise_start, sunrise_end, |
|
|
|
sunset_start, sunset_end) |
|
|
|
|
|
|
|
chat_item.author = {'name': 'ゴートうひとり' if goatoh_talking else '伊地知ニジカ', |
|
|
|
'id': '', |
|
|
@@ -243,14 +276,29 @@ class Main: |
|
|
|
@classmethod |
|
|
|
def draw_bg ( |
|
|
|
cls, |
|
|
|
screen: pygame.Surface, |
|
|
|
bg_evening: pygame.Surface, |
|
|
|
bg_night: pygame.Surface) \ |
|
|
|
screen: pygame.Surface, |
|
|
|
bg_evening: pygame.Surface, |
|
|
|
bg_night: pygame.Surface, |
|
|
|
sunrise_start: datetime, |
|
|
|
sunrise_end: datetime, |
|
|
|
sunset_start: datetime, |
|
|
|
sunset_end: datetime) \ |
|
|
|
-> None: |
|
|
|
if 17 <= (h := datetime.now ().hour) < 18: |
|
|
|
screen.blit (bg_evening, (0, 0)) |
|
|
|
elif (h < 6) or (18 <= h): |
|
|
|
dt: datetime = datetime.now () |
|
|
|
|
|
|
|
if (dt < sunrise_end) or (sunset_start <= dt): |
|
|
|
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)) |
|
|
|
else: |
|
|
|
screen.fill ((0, 255, 0)) |
|
|
|
|
|
|
|