き太く陽を昇らせる
このコミットが含まれているのは:
バイナリ
バイナリファイルは表示されません.
|
変更後 幅: | 高さ: | サイズ: 99 KiB |
@@ -2,3 +2,7 @@ class CWindow:
|
|||||||
WIDTH: int = 1024
|
WIDTH: int = 1024
|
||||||
HEIGHT: int = 768
|
HEIGHT: int = 768
|
||||||
|
|
||||||
|
|
||||||
|
class CMath:
|
||||||
|
PI: float = 3.14159265358979323846
|
||||||
|
|
||||||
|
|||||||
+26
-4
@@ -1,17 +1,28 @@
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
|
from common_const import *
|
||||||
|
|
||||||
|
|
||||||
class CommonModule:
|
class CommonModule:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_wide (c: str) -> bool:
|
def is_wide (
|
||||||
|
c: str) \
|
||||||
|
-> bool:
|
||||||
return unicodedata.east_asian_width (c) in ['F', 'W', 'A']
|
return unicodedata.east_asian_width (c) in ['F', 'W', 'A']
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def len_by_full (cls, string: str) -> float:
|
def len_by_full (
|
||||||
|
cls,
|
||||||
|
string: str) \
|
||||||
|
-> float:
|
||||||
return sum (1 if cls.is_wide (c) else .5 for c in string)
|
return sum (1 if cls.is_wide (c) else .5 for c in string)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def index_by_f2c (cls, string: str, index: float) -> int:
|
def index_by_f2c (
|
||||||
|
cls,
|
||||||
|
string: str,
|
||||||
|
index: float) \
|
||||||
|
-> int:
|
||||||
i: int = 0
|
i: int = 0
|
||||||
work: str = ''
|
work: str = ''
|
||||||
for c in string:
|
for c in string:
|
||||||
@@ -24,8 +35,19 @@ class CommonModule:
|
|||||||
return i
|
return i
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def mid_by_full (cls, string: str, start: float, length: float) -> str:
|
def mid_by_full (
|
||||||
|
cls,
|
||||||
|
string: str,
|
||||||
|
start: float,
|
||||||
|
length: float) \
|
||||||
|
-> str:
|
||||||
trimmed_left: str = string[cls.index_by_f2c (string, start):]
|
trimmed_left: str = string[cls.index_by_f2c (string, start):]
|
||||||
|
|
||||||
return trimmed_left[:cls.index_by_f2c (trimmed_left, length)]
|
return trimmed_left[:cls.index_by_f2c (trimmed_left, length)]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def rad_to_deg (
|
||||||
|
rad: float) \
|
||||||
|
-> float:
|
||||||
|
return rad * 180 / CMath.PI
|
||||||
|
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ class Main:
|
|||||||
observer = ephem.Observer ()
|
observer = ephem.Observer ()
|
||||||
observer.lat, observer.lon = '35', '139'
|
observer.lat, observer.lon = '35', '139'
|
||||||
|
|
||||||
# き太く陽
|
# き太く陽オブジェクト
|
||||||
sun = ephem.Sun ()
|
sun = ephem.Sun ()
|
||||||
|
|
||||||
# 大月ヨヨコ
|
# 大月ヨヨコ・オブジェクト
|
||||||
moon = ephem.Moon ()
|
moon = ephem.Moon ()
|
||||||
|
|
||||||
# 吹き出し
|
# 吹き出し
|
||||||
@@ -79,6 +79,19 @@ class Main:
|
|||||||
pygame.image.load ('bg-night.jpg'),
|
pygame.image.load ('bg-night.jpg'),
|
||||||
(CWindow.WIDTH, CWindow.HEIGHT))
|
(CWindow.WIDTH, CWindow.HEIGHT))
|
||||||
|
|
||||||
|
# 背景の草
|
||||||
|
bg_grass: pygame.Surface = pygame.transform.scale (
|
||||||
|
pygame.image.load ('bg-grass.png'),
|
||||||
|
(CWindow.WIDTH, CWindow.HEIGHT))
|
||||||
|
|
||||||
|
# き太く陽
|
||||||
|
kita: pygame.Surface = pygame.transform.scale (
|
||||||
|
pygame.image.load ('sun.png'), (200, 200))
|
||||||
|
|
||||||
|
# 大月ヨヨコ
|
||||||
|
jojoko: pygame.Surface = pygame.transform.scale (
|
||||||
|
pygame.image.load ('moon.png'), (200, 200))
|
||||||
|
|
||||||
# 音声再生器の初期化
|
# 音声再生器の初期化
|
||||||
pygame.mixer.init (frequency = 44100)
|
pygame.mixer.init (frequency = 44100)
|
||||||
|
|
||||||
@@ -110,7 +123,7 @@ class Main:
|
|||||||
histories: list = []
|
histories: list = []
|
||||||
|
|
||||||
while (True):
|
while (True):
|
||||||
# 観測値の日づけ更新
|
# 観測地の日づけ更新
|
||||||
observer.date: datetime = datetime.now ().date ()
|
observer.date: datetime = datetime.now ().date ()
|
||||||
|
|
||||||
# 日の出開始
|
# 日の出開始
|
||||||
@@ -129,9 +142,6 @@ class Main:
|
|||||||
# 日の入終了
|
# 日の入終了
|
||||||
sunset_end: datetime = sunset_start + timedelta (hours = 1)
|
sunset_end: datetime = sunset_start + timedelta (hours = 1)
|
||||||
|
|
||||||
cls.draw_bg (screen, bg_day, bg_evening, bg_night,
|
|
||||||
sunrise_start, sunrise_end, sunset_start, sunset_end)
|
|
||||||
|
|
||||||
# 月の出開始
|
# 月の出開始
|
||||||
'todo'
|
'todo'
|
||||||
|
|
||||||
@@ -144,6 +154,18 @@ class Main:
|
|||||||
# 月の入終了
|
# 月の入終了
|
||||||
'todo'
|
'todo'
|
||||||
|
|
||||||
|
# 日の角度
|
||||||
|
observer_with_time: ephem.Observer = observer
|
||||||
|
observer_with_time.date = datetime.now () - timedelta (hours = 9)
|
||||||
|
sun.compute (observer_with_time)
|
||||||
|
sun_alt: float = CommonModule.rad_to_deg (sun.alt)
|
||||||
|
|
||||||
|
# 背景描画
|
||||||
|
cls.draw_bg (screen, bg_day, bg_evening, bg_night, bg_grass,
|
||||||
|
kita, jojoko,
|
||||||
|
sunrise_start, sunrise_end, sunset_start, sunset_end,
|
||||||
|
sun_alt)
|
||||||
|
|
||||||
# 左上に時刻表示
|
# 左上に時刻表示
|
||||||
for i in range (4):
|
for i in range (4):
|
||||||
screen.blit (
|
screen.blit (
|
||||||
@@ -186,7 +208,9 @@ class Main:
|
|||||||
|
|
||||||
# ログ書込み
|
# ログ書込み
|
||||||
with open ('log.txt', 'a') as f:
|
with open ('log.txt', 'a') as f:
|
||||||
f.write (f'{datetime.now ()}\t{json.dumps (chat_item.__dict__)}\t{answer}\n')
|
f.write (f'{datetime.now ()}\t'
|
||||||
|
+ f'{json.dumps (chat_item.__dict__)}\t'
|
||||||
|
+ f'{answer}\n')
|
||||||
|
|
||||||
# 吹出し描画(ニジカは上,ゴートうは下)
|
# 吹出し描画(ニジカは上,ゴートうは下)
|
||||||
if nizika_mode:
|
if nizika_mode:
|
||||||
@@ -204,7 +228,8 @@ class Main:
|
|||||||
screen.blit (
|
screen.blit (
|
||||||
user_font.render (
|
user_font.render (
|
||||||
'> ' + (message
|
'> ' + (message
|
||||||
if (CommonModule.len_by_full (message)
|
if (CommonModule.len_by_full (
|
||||||
|
message)
|
||||||
<= 21)
|
<= 21)
|
||||||
else (CommonModule.mid_by_full (
|
else (CommonModule.mid_by_full (
|
||||||
message, 0, 19.5)
|
message, 0, 19.5)
|
||||||
@@ -266,8 +291,10 @@ class Main:
|
|||||||
break
|
break
|
||||||
|
|
||||||
cls.draw_bg (screen, bg_day, bg_evening, bg_night,
|
cls.draw_bg (screen, bg_day, bg_evening, bg_night,
|
||||||
|
bg_grass, kita, jojoko,
|
||||||
sunrise_start, sunrise_end,
|
sunrise_start, sunrise_end,
|
||||||
sunset_start, sunset_end)
|
sunset_start, sunset_end,
|
||||||
|
sun_alt)
|
||||||
|
|
||||||
chat_item.author = {'name': 'ゴートうひとり' if goatoh_talking else '伊地知ニジカ',
|
chat_item.author = {'name': 'ゴートうひとり' if goatoh_talking else '伊地知ニジカ',
|
||||||
'id': '',
|
'id': '',
|
||||||
@@ -297,10 +324,14 @@ class Main:
|
|||||||
bg_day: pygame.Surface,
|
bg_day: pygame.Surface,
|
||||||
bg_evening: pygame.Surface,
|
bg_evening: pygame.Surface,
|
||||||
bg_night: pygame.Surface,
|
bg_night: pygame.Surface,
|
||||||
|
bg_grass: pygame.Surface,
|
||||||
|
kita: pygame.Surface,
|
||||||
|
jojoko: pygame.Surface,
|
||||||
sunrise_start: datetime,
|
sunrise_start: datetime,
|
||||||
sunrise_end: datetime,
|
sunrise_end: datetime,
|
||||||
sunset_start: datetime,
|
sunset_start: datetime,
|
||||||
sunset_end: datetime) \
|
sunset_end: datetime,
|
||||||
|
sun_alt: float) \
|
||||||
-> None:
|
-> None:
|
||||||
sunrise_centre: datetime = (
|
sunrise_centre: datetime = (
|
||||||
sunrise_start + (sunrise_end - sunrise_start) / 2)
|
sunrise_start + (sunrise_end - sunrise_start) / 2)
|
||||||
@@ -321,10 +352,17 @@ class Main:
|
|||||||
bg_evening.set_alpha (255 - ((abs (dt - sunset_centre) * 510)
|
bg_evening.set_alpha (255 - ((abs (dt - sunset_centre) * 510)
|
||||||
/ (sunset_end - sunset_centre)))
|
/ (sunset_end - sunset_centre)))
|
||||||
else:
|
else:
|
||||||
return
|
bg_evening.set_alpha (0)
|
||||||
|
|
||||||
screen.blit (bg_evening, (0, 0))
|
screen.blit (bg_evening, (0, 0))
|
||||||
|
|
||||||
|
if -10 <= sun_alt < 40:
|
||||||
|
y = ((CWindow.HEIGHT / 2 + 100)
|
||||||
|
- (CWindow.HEIGHT / 2 + 200) / 30 * sun_alt)
|
||||||
|
screen.blit (kita, kita.get_rect (center = (400, y)))
|
||||||
|
|
||||||
|
screen.blit (bg_grass, (0, 0))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
Main.main (sys.argv, len (sys.argv))
|
Main.main (sys.argv, len (sys.argv))
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする