diff --git a/moon.png b/assets/moon.png old mode 100755 new mode 100644 similarity index 100% rename from moon.png rename to assets/moon.png diff --git a/main.py b/main.py index 91c1f61..b658bec 100644 --- a/main.py +++ b/main.py @@ -180,7 +180,7 @@ class Main: 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 () + (datetime.now () - new_moon_dt).total_seconds () / 60 / 60 / 24) # 背景描画 diff --git a/test.py b/test.py index 6b986a2..0730305 100644 --- a/test.py +++ b/test.py @@ -7,7 +7,9 @@ from enum import Enum, auto from typing import Callable, TypedDict import cv2 +import ephem # type: ignore import pygame +import pygame.gfxdraw from cv2 import VideoCapture from ephem import Moon, Observer, Sun # type: ignore from pygame import Rect, Surface @@ -482,22 +484,50 @@ class Jojoko (GameObject): 大月ヨヨコ Attributes: - phase (float): 月齢 + base (Surface): 満月ヨヨコ Surface + moon (Moon): ephem の月オブゼクト + surface (Surface): 缺けたヨヨコ Surface """ - phase: float + base: Surface + moon: Moon def __init__ ( self, game: Game, ): - ... + super ().__init__ (game) + self.base = pygame.transform.scale (pygame.image.load ('assets/moon.png'), (200, 200)) def redraw ( self, ) -> None: ... + @property + def phase ( + self, + ) -> float: + dt: datetime = ephem.localtime (ephem.previous_new_moon (self.game.sky.observer.date)) + return (datetime.now () - dt).total_seconds () / 60 / 60 / 24 + + @property + def surface ( + self, + ) -> Surface: + jojoko = self.base.copy () + jojoko.set_colorkey ((0, 255, 0)) + for i in range (200): + if 1 <= self.phase < 15: + pygame.gfxdraw.bezier (jojoko, ((0, 100 + i), (100, 180 * self.phase / 7 - 80 + i), (200, 100 + i)), 3, (0, 255, 0)) + elif self.phase < 16: + pass + elif self.phase < 30: + pygame.gfxdraw.bezier (jojoko, ((0, 100 - i), (100, 180 * (self.phase - 15) / 7 - 80 - i), (200, 100 - i)), 3, (0, 255, 0)) + else: + jojoko.fill ((0, 255, 0)) + return jojoko + class Sky: """