Browse Source

31 ヨヨコぼちぼち

ai-migration
みてるぞ 1 month ago
parent
commit
75f3f1cff3
3 changed files with 34 additions and 4 deletions
  1. +0
    -0
      assets/moon.png
  2. +1
    -1
      main.py
  3. +33
    -3
      test.py

moon.png → assets/moon.png View File

Before After
Width: 1329  |  Height: 1329  |  Size: 641 KiB Width: 1329  |  Height: 1329  |  Size: 641 KiB

+ 1
- 1
main.py View File

@@ -180,7 +180,7 @@ class Main:
new_moon_dt: datetime = ephem.localtime ( new_moon_dt: datetime = ephem.localtime (
ephem.previous_new_moon (observer_with_time.date)) ephem.previous_new_moon (observer_with_time.date))
moon_days_old: float = ( moon_days_old: float = (
(datetime.now () - new_moon_dt).total_seconds ()
(datetime.now () - new_moon_dt).total_seconds ()
/ 60 / 60 / 24) / 60 / 60 / 24)


# 背景描画 # 背景描画


+ 33
- 3
test.py View File

@@ -7,7 +7,9 @@ from enum import Enum, auto
from typing import Callable, TypedDict from typing import Callable, TypedDict


import cv2 import cv2
import ephem # type: ignore
import pygame import pygame
import pygame.gfxdraw
from cv2 import VideoCapture from cv2 import VideoCapture
from ephem import Moon, Observer, Sun # type: ignore from ephem import Moon, Observer, Sun # type: ignore
from pygame import Rect, Surface from pygame import Rect, Surface
@@ -482,22 +484,50 @@ class Jojoko (GameObject):
大月ヨヨコ 大月ヨヨコ


Attributes: Attributes:
phase (float): 月齢
base (Surface): 満月ヨヨコ Surface
moon (Moon): ephem の月オブゼクト
surface (Surface): 缺けたヨヨコ Surface
""" """


phase: float
base: Surface
moon: Moon


def __init__ ( def __init__ (
self, self,
game: Game, game: Game,
): ):
...
super ().__init__ (game)
self.base = pygame.transform.scale (pygame.image.load ('assets/moon.png'), (200, 200))


def redraw ( def redraw (
self, self,
) -> None: ) -> 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: class Sky:
""" """


Loading…
Cancel
Save