From 75f3f1cff37dda48850021d52965063baa95b8ab Mon Sep 17 00:00:00 2001 From: miteruzo Date: Tue, 17 Dec 2024 08:26:48 +0900 Subject: [PATCH] =?UTF-8?q?31=20=E3=83=A8=E3=83=A8=E3=82=B3=E3=81=BC?= =?UTF-8?q?=E3=81=A1=E3=81=BC=E3=81=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moon.png => assets/moon.png | Bin main.py | 2 +- test.py | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) rename moon.png => assets/moon.png (100%) mode change 100755 => 100644 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: """