4 コミット

作成者 SHA1 メッセージ 日付
みてるぞ b6ae21bb59 定数化 2024-05-19 18:45:48 +09:00
みてるぞ 3874f838f1 ヨヨコと郁代回転,視野角拡大 2024-05-19 15:35:17 +09:00
みてるぞ f2683bca27 Merge branch 'main' into ofotukuy 2024-05-19 09:17:35 +09:00
みてるぞ 7277819b6e 'talk.py' を更新 2024-05-14 20:52:10 +09:00
3個のファイルの変更77行の追加29行の削除
+8 -2
ファイルの表示
@@ -3,6 +3,12 @@ class CWindow:
HEIGHT: int = 768 HEIGHT: int = 768
class CMath: class CKita:
PI: float = 3.14159265358979323846 WIDTH: float = CWindow.HEIGHT / 3.84
HEIGHT: float = WIDTH
class CJojoko:
WIDTH: float = CKita.HEIGHT * .75
HEIGHT: float = WIDTH
+51 -20
ファイルの表示
@@ -25,6 +25,14 @@ from youtube import *
class Main: class Main:
kita_x: float = CWindow.WIDTH / 2
kita_y: float = 1000000.
kita_arg: float = 0.
jojoko_x: float = CWindow.WIDTH / 2
jojoko_y: float = 1000000.
jojoko_arg: float = 0.
@classmethod @classmethod
def main ( def main (
cls, cls,
@@ -88,11 +96,11 @@ class Main:
# き太く陽 # き太く陽
kita: pygame.Surface = pygame.transform.scale ( kita: pygame.Surface = pygame.transform.scale (
pygame.image.load ('sun.png'), (200, 200)) pygame.image.load ('sun.png'), (CKita.WIDTH, CKita.HEIGHT))
# 大月ヨヨコ # 大月ヨヨコ
jojoko: pygame.Surface = pygame.transform.scale ( jojoko: pygame.Surface = pygame.transform.scale (
pygame.image.load ('moon.png'), (200, 200)) pygame.image.load ('moon.png'), (CJojoko.WIDTH, CJojoko.HEIGHT))
# 音声再生器の初期化 # 音声再生器の初期化
pygame.mixer.init (frequency = 44100) pygame.mixer.init (frequency = 44100)
@@ -262,7 +270,7 @@ class Main:
+ '...')), + '...')),
True, True,
(192, 0, 0)), (192, 0, 0)),
(100, 200 + 384) if goatoh_mode else (100 + (64 if (double_mode and not goatoh_talking) else 0), 200)) (100, 200 + CWindow.HEIGHT / 2) if goatoh_mode else (100 + (64 if (double_mode and not goatoh_talking) else 0), 200))
pygame.display.update () pygame.display.update ()
@@ -331,7 +339,7 @@ class Main:
bg_evening: pygame.Surface, bg_evening: pygame.Surface,
bg_night: pygame.Surface, bg_night: pygame.Surface,
bg_grass: pygame.Surface, bg_grass: pygame.Surface,
kita: pygame.Surface, kita_original: pygame.Surface,
jojoko_original: pygame.Surface, jojoko_original: pygame.Surface,
sunrise_start: datetime, sunrise_start: datetime,
sunrise_end: datetime, sunrise_end: datetime,
@@ -349,7 +357,20 @@ class Main:
sunset_start + (sunset_end - sunset_start) / 2) sunset_start + (sunset_end - sunset_start) / 2)
jojoko: pygame.Surface = cls.get_jojoko (jojoko_original, jojoko: pygame.Surface = cls.get_jojoko (jojoko_original,
moon_days_old, moon_alt) moon_days_old, moon_alt, moon_az)
# TODO: 大月と重複多いため修正すること
x = CWindow.WIDTH * (sun_az - 80) / 120
y = ((CWindow.HEIGHT / 2)
- (CWindow.HEIGHT / 2 + CKita.HEIGHT / 2) * math.sin (math.radians (sun_alt)) / math.sin ( math.radians (60)))
arg = math.degrees (math.atan2 (y - cls.kita_y, x - cls.kita_x))
cls.kita_x = x
cls.kita_y = y
if abs (arg - cls.kita_arg) > 3:
cls.kita_arg = arg
kita: pygame.Surface = pygame.transform.rotate (kita_original, -(90 + cls.kita_arg))
dt: datetime = datetime.now () dt: datetime = datetime.now ()
@@ -374,41 +395,51 @@ class Main:
screen.blit (bg_evening, (0, 0)) screen.blit (bg_evening, (0, 0))
if (moon_az < 180) and (-10 <= moon_alt < 40): if (moon_az < 220) and (-10 <= moon_alt):
y = ((CWindow.HEIGHT / 2 + 100) screen.blit (jojoko, jojoko.get_rect (center = (cls.jojoko_x, cls.jojoko_y)))
- (CWindow.HEIGHT / 2 + 200) / 30 * moon_alt)
screen.blit (jojoko, jojoko.get_rect (center = (400, y)))
screen.blit (bg_grass, (0, 0)) screen.blit (bg_grass, (0, 0))
if (sun_az < 180) and (-10 <= sun_alt < 40): if (sun_az < 220) and (-10 <= sun_alt):
y = ((CWindow.HEIGHT / 2 + 100) screen.blit (kita, kita.get_rect (center = (cls.kita_x, cls.kita_y)))
- (CWindow.HEIGHT / 2 + 200) / 30 * sun_alt)
screen.blit (kita, kita.get_rect (center = (400, y)))
screen.blit (bg_grass, (0, 0)) screen.blit (bg_grass, (0, 0))
@staticmethod @classmethod
def get_jojoko ( def get_jojoko (
cls,
jojoko_original: pygame.Surface, jojoko_original: pygame.Surface,
moon_days_old: float, moon_days_old: float,
moon_alt: float) \ moon_alt: float,
moon_az: float) \
-> pygame.Surface: -> pygame.Surface:
jojoko: pygame.Surface = pygame.transform.rotate (jojoko_original, -moon_alt) jojoko: pygame.Surface = jojoko_original.copy ()
jojoko.set_colorkey ((0, 255, 0)) jojoko.set_colorkey ((0, 255, 0))
for i in range (200): for i in range (int (CJojoko.HEIGHT)):
# TODO: 冗長かつ可読性に缺けるため修正すること
if 1 <= moon_days_old < 15: if 1 <= moon_days_old < 15:
pygame.gfxdraw.bezier (jojoko, ((0, 100 + i), (100, 180 * moon_days_old / 7 - 80 + i), (200, 100 + i)), 3, (0, 255, 0)) pygame.gfxdraw.bezier (jojoko, ((0, CJojoko.HEIGHT / 2 + i), (CJojoko.WIDTH / 2, (CJojoko.HEIGHT * 0.9) * moon_days_old / 7 - CJojoko.HEIGHT * 0.4 + i), (CJojoko.WIDTH, CJojoko.HEIGHT / 2 + i)), 3, (0, 255, 0))
elif moon_days_old < 16: elif moon_days_old < 16:
pass pass
elif moon_days_old < 30: elif moon_days_old < 30:
pygame.gfxdraw.bezier (jojoko, ((0, 100 - i), (100, 180 * (moon_days_old - 15) / 7 - 80 - i), (200, 100 - i)), 3, (0, 255, 0)) pygame.gfxdraw.bezier (jojoko, ((0, CJojoko.HEIGHT / 2 - i), (CJojoko.WIDTH / 2, (CJojoko.HEIGHT * 0.9) * (moon_days_old - 15) / 7 - CJojoko.HEIGHT * 0.4 - i), (CJojoko.WIDTH, CJojoko.HEIGHT / 2 - i)), 3, (0, 255, 0))
else: else:
jojoko.fill ((0, 255, 0)) jojoko.fill ((0, 255, 0))
return jojoko # TODO: き太く陽生成と重複多いため外出しすること
x = CWindow.WIDTH * (moon_az - 80) / 120
y = ((CWindow.HEIGHT / 2)
- (CWindow.HEIGHT / 2 + CJojoko.HEIGHT / 2) * math.sin (math.radians (moon_alt)) / math.sin (math.radians (60)))
arg = math.degrees (math.atan2 (y - cls.jojoko_y, x - cls.jojoko_x))
cls.jojoko_x = x
cls.jojoko_y = y
if abs (arg - cls.jojoko_arg) > 3:
cls.jojoko_arg = arg
return pygame.transform.rotate (jojoko, -(90 + cls.jojoko_arg))
if __name__ == '__main__': if __name__ == '__main__':
+18 -7
ファイルの表示
@@ -24,7 +24,13 @@ class Talk:
top_p: float = 1. top_p: float = 1.
@classmethod @classmethod
def main (cls, message: str, name: str | None = None, histories: list = [], goatoh_mode: bool = False) -> str: def main (
cls,
message: str,
name: str | None = None,
histories: list = [],
goatoh_mode: bool = False,
) -> str:
# ChatGPT API Organisation ID # ChatGPT API Organisation ID
openai.organization = OPENAI_ORGANISATION openai.organization = OPENAI_ORGANISATION
@@ -38,8 +44,13 @@ class Talk:
return answer.content if answer is not None else cls.DUMMY_RESPONSE return answer.content if answer is not None else cls.DUMMY_RESPONSE
@classmethod @classmethod
def __get_message (cls, message: str, name: str | None, histories: list, goatoh_mode: bool = False) \ def __get_message (
-> chat.chat_completion_message.ChatCompletionMessage | None: cls,
message: str,
name: str | None,
histories: list,
goatoh_mode: bool = False,
) -> chat.chat_completion_message.ChatCompletionMessage | None:
# プロンプト(JSON 等外部ファイルに置くことを検討) # プロンプト(JSON 等外部ファイルに置くことを検討)
if goatoh_mode: if goatoh_mode:
messages: list = [{'role': 'system', messages: list = [{'role': 'system',
@@ -203,13 +214,13 @@ class Talk:
+ 'ふざけるのはいい加減にするぬ゛ぬ゛ん゛。'))}, + 'ふざけるのはいい加減にするぬ゛ぬ゛ん゛。'))},
{'role': 'system', {'role': 'system',
'content': '歌(しーざおぐあ)歌って'}, 'content': '歌(しーざおぐあ)歌って'},
{'role': 'assistant', {'role': 'assistant',
'content': ('おけだぬ゛~゛ん゛(苦笑)。' 'content': ('おけだぬ゛~゛ん゛(苦笑)。'
+ '毛巾浴帽小鸭鸭水温刚刚好♪' + '毛巾浴帽小鴨鴨水溫剛剛好♪'
+ '泼泼水来搓泡泡今天是美妙♪' + '潑潑水來搓泡泡今天是美妙♪'
+ '唱歌扭扭腰我洗洗澡♪' + '唱歌扭扭腰我洗洗澡♪'
+ 'だぬ゛ん♪')}, + 'だぬ゛ん♪')},
{'role': 'system', {'role': 'system',