コミットを比較
9 コミット
39cf64149f
...
sicawke
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
| 7277819b6e | |||
| 0b8e9812b9 | |||
| a00eaf7ff2 | |||
| 80d6c09967 | |||
| 37618c5df1 | |||
| d80d03db46 | |||
| fa6b5ba68b | |||
| cff0ec27d8 | |||
| d676372276 |
バイナリ
バイナリファイルは表示されません.
|
変更後 幅: | 高さ: | サイズ: 99 KiB |
バイナリ
バイナリファイルは表示されません.
|
変更前 幅: | 高さ: | サイズ: 38 KiB 変更後 幅: | 高さ: | サイズ: 53 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
|
||||||
|
|
||||||
|
|||||||
+20
-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,7 +35,12 @@ 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)]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# vim: nosmartindent autoindent
|
# vim: nosmartindent autoindent
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import math
|
||||||
import random
|
import random
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@@ -10,6 +11,7 @@ from datetime import datetime, timedelta
|
|||||||
import emoji
|
import emoji
|
||||||
import ephem
|
import ephem
|
||||||
import pygame
|
import pygame
|
||||||
|
import pygame.gfxdraw
|
||||||
import pytchat
|
import pytchat
|
||||||
from playsound import playsound
|
from playsound import playsound
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
@@ -52,10 +54,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 +81,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)
|
||||||
|
|
||||||
@@ -106,11 +121,11 @@ class Main:
|
|||||||
# Youtube Chat から取得したコメントたち
|
# Youtube Chat から取得したコメントたち
|
||||||
chat_items: list = []
|
chat_items: list = []
|
||||||
|
|
||||||
# 会話の履歴(3 件分保持)
|
# 会話の履歴
|
||||||
histories: list = []
|
histories: list = []
|
||||||
|
|
||||||
while (True):
|
while (True):
|
||||||
# 観測値の日づけ更新
|
# 観測地の日づけ更新
|
||||||
observer.date: datetime = datetime.now ().date ()
|
observer.date: datetime = datetime.now ().date ()
|
||||||
|
|
||||||
# 日の出開始
|
# 日の出開始
|
||||||
@@ -129,8 +144,32 @@ 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)
|
observer_with_time: ephem.Observer = observer
|
||||||
|
observer_with_time.date = datetime.now () - timedelta (hours = 9)
|
||||||
|
|
||||||
|
# 日の角度
|
||||||
|
sun.compute (observer_with_time)
|
||||||
|
sun_alt: float = math.degrees (sun.alt)
|
||||||
|
sun_az: float = math.degrees (sun.az)
|
||||||
|
|
||||||
|
# 月の角度
|
||||||
|
moon.compute (observer_with_time)
|
||||||
|
moon_alt: float = math.degrees (moon.alt)
|
||||||
|
moon_az: float = math.degrees (moon.az)
|
||||||
|
|
||||||
|
# 月齢
|
||||||
|
new_moon_dt: datetime = ephem.localtime (
|
||||||
|
ephem.previous_new_moon (observer_with_time.date))
|
||||||
|
moon_days_old: float = (
|
||||||
|
(datetime.now () - new_moon_dt).total_seconds ()
|
||||||
|
/ 60 / 60 / 24)
|
||||||
|
|
||||||
|
# 背景描画
|
||||||
|
cls.draw_bg (screen, bg_day, bg_evening, bg_night, bg_grass,
|
||||||
|
kita, jojoko,
|
||||||
|
sunrise_start, sunrise_end, sunset_start, sunset_end,
|
||||||
|
sun_alt, sun_az, moon_alt, moon_az, moon_days_old)
|
||||||
|
|
||||||
# 左上に時刻表示
|
# 左上に時刻表示
|
||||||
for i in range (4):
|
for i in range (4):
|
||||||
@@ -174,7 +213,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:
|
||||||
@@ -192,7 +233,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)
|
||||||
@@ -254,8 +296,11 @@ 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, sun_az, moon_alt, moon_az,
|
||||||
|
moon_days_old)
|
||||||
|
|
||||||
chat_item.author = {'name': 'ゴートうひとり' if goatoh_talking else '伊地知ニジカ',
|
chat_item.author = {'name': 'ゴートうひとり' if goatoh_talking else '伊地知ニジカ',
|
||||||
'id': '',
|
'id': '',
|
||||||
@@ -285,16 +330,27 @@ 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_original: 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,
|
||||||
|
sun_az: float,
|
||||||
|
moon_alt: float,
|
||||||
|
moon_az: float,
|
||||||
|
moon_days_old: float) \
|
||||||
-> None:
|
-> None:
|
||||||
sunrise_centre: datetime = (
|
sunrise_centre: datetime = (
|
||||||
sunrise_start + (sunrise_end - sunrise_start) / 2)
|
sunrise_start + (sunrise_end - sunrise_start) / 2)
|
||||||
sunset_centre: datetime = (
|
sunset_centre: datetime = (
|
||||||
sunset_start + (sunset_end - sunset_start) / 2)
|
sunset_start + (sunset_end - sunset_start) / 2)
|
||||||
|
|
||||||
|
jojoko: pygame.Surface = cls.get_jojoko (jojoko_original,
|
||||||
|
moon_days_old)
|
||||||
|
|
||||||
dt: datetime = datetime.now ()
|
dt: datetime = datetime.now ()
|
||||||
|
|
||||||
if sunrise_centre <= dt < sunset_centre:
|
if sunrise_centre <= dt < sunset_centre:
|
||||||
@@ -309,10 +365,50 @@ 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)
|
||||||
|
|
||||||
|
if sunrise_start <= dt < sunset_end:
|
||||||
|
jojoko.set_alpha (255 - 255 / 15 * abs (moon_days_old - 15))
|
||||||
|
else:
|
||||||
|
jojoko.set_alpha (255)
|
||||||
|
|
||||||
screen.blit (bg_evening, (0, 0))
|
screen.blit (bg_evening, (0, 0))
|
||||||
|
|
||||||
|
if (moon_az < 180) and (-10 <= moon_alt < 40):
|
||||||
|
y = ((CWindow.HEIGHT / 2 + 100)
|
||||||
|
- (CWindow.HEIGHT / 2 + 200) / 30 * moon_alt)
|
||||||
|
screen.blit (jojoko, jojoko.get_rect (center = (400, y)))
|
||||||
|
|
||||||
|
screen.blit (bg_grass, (0, 0))
|
||||||
|
|
||||||
|
if (sun_az < 180) and (-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))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_jojoko (
|
||||||
|
jojoko_original: pygame.Surface,
|
||||||
|
moon_days_old: float) \
|
||||||
|
-> pygame.Surface:
|
||||||
|
jojoko: pygame.Surface = jojoko_original.copy ()
|
||||||
|
|
||||||
|
jojoko.set_colorkey ((0, 255, 0))
|
||||||
|
|
||||||
|
for i in range (200):
|
||||||
|
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))
|
||||||
|
elif moon_days_old < 16:
|
||||||
|
pass
|
||||||
|
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))
|
||||||
|
else:
|
||||||
|
jojoko.fill ((0, 255, 0))
|
||||||
|
|
||||||
|
return jojoko
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
Main.main (sys.argv, len (sys.argv))
|
Main.main (sys.argv, len (sys.argv))
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする