moondial

A sun clock that shows moon and planet positions along with the moon's terminator, a strip with mean time at every longitude, and selected cities with lines to their respective civil time.
git clone https://code.literati.org/moondial.git
Log | Files | Refs | README | LICENSE

commit 3f122e4e8c2c24eb8b597d726053504925040f59
parent 586b5a7acf5324dae2e50df98833555a7595a435
Author: Sean Lynch <seanl@literati.org>
Date:   Thu, 18 Jan 2018 23:29:02 -0800

Scale planets, clock band, and city markers by window height

Diffstat:
Mmoondial.py | 34+++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/moondial.py b/moondial.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import json, re, sys from datetime import datetime -from math import * +import math import pytz @@ -15,9 +15,12 @@ from astronomia.constants import sun_rst_altitude, standard_rst_altitude import planets -_CLOCK_HEIGHT = 20 +CLOCK_FRAC = 0.05 # Fraction of the height to use for the clock band +CITY_FRAC = 0.005 # Fraction of height to use for city circles +PLANET_FRAC = 0.02 # Size of planets relative to window height UTC = pytz.timezone('UTC') +# Corresponding characters for planets and zodiac signs planet_font = "QRSTUVWXYZ" zodiac_font = "ABCDEFGHIJKL" red = (255, 0, 0) @@ -30,9 +33,6 @@ zodiac_color = (red, yellow, green, blue, red, yellow, green, blue, red, \ yellow, green, blue) -#_proj = pyproj.Proj('+proj=laea +lat_0=90 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 ' -# '+datum=WGS84 +units=m +no_defs') - def lonlat2xy(lonlat, wh): lon, lat = lonlat w, h = wh @@ -72,11 +72,8 @@ class City(object): def draw(self, surface): w, h = surface.get_size() x, y = lonlat2xy((self.lon, self.lat), (w, h)) - #pygame.draw.circle(surface, (0, 0, 0), (x, y), 2, 1) - surface.set_at((x-1, y), (0, 0, 0)) - surface.set_at((x+1, y), (0, 0, 0)) - surface.set_at((x, y-1), (0, 0, 0)) - surface.set_at((x, y+1), (0, 0, 0)) + d = max(2, int(h * CITY_FRAC + 0.5)) + pygame.draw.circle(surface, (0, 0, 0), (x, y), d, 1) tz = self.tz if tz is not None: offset = self.utcoffset(datetime.utcnow()) @@ -105,7 +102,8 @@ class MoonDial(object): self.resize((0, 0)) def make_planets(self): - font = pygame.font.Font('ASTRO.TTF', 16) + font_size = max(8, int(round(self.surface.get_height() * PLANET_FRAC))) + font = pygame.font.Font('ASTRO.TTF', font_size) planets = [] for char, color in zip(planet_font, planet_color): planet_surface = font.render(char, True, color) @@ -151,13 +149,13 @@ class MoonDial(object): points = planets.get_terminator(lat, sun_rst_altitude, (w, h)) pygame.draw.polygon(surface, (0, 0, 0, 64), points) # civil twilight - points = planets.get_terminator(lat, -6.0/180.0*pi, (w, h)) + points = planets.get_terminator(lat, -6.0/180.0*math.pi, (w, h)) pygame.draw.polygon(surface, (0, 0, 0, 96), points) # nautical twilight - points = planets.get_terminator(lat, -12.0/180.0*pi, (w, h)) + points = planets.get_terminator(lat, -12.0/180.0*math.pi, (w, h)) pygame.draw.polygon(surface, (0, 0, 0, 128), points) # astronomical twilight - points = planets.get_terminator(lat, -18.0/180.0*pi, (w, h)) + points = planets.get_terminator(lat, -18.0/180.0*math.pi, (w, h)) pygame.draw.polygon(surface, (0, 0, 0, 160), points) self.nightmap = surface @@ -179,7 +177,6 @@ class MoonDial(object): def make_map(self): w, h = self.surface.get_size() - h -= _CLOCK_HEIGHT surface = pygame.Surface((w, h)) world = self.world surface.fill((0, 0, 192)) @@ -224,8 +221,11 @@ class MoonDial(object): city.draw(surface) def make_clock(self): - w, h = self.surface.get_width(), _CLOCK_HEIGHT - font = pygame.font.SysFont('arialblack', 16) + w = self.surface.get_width() + h = self.surface.get_height() * CLOCK_FRAC + font_size = int(round(h * 0.75)) + font = pygame.font.SysFont('arialblack', font_size) + # Compute the height of the numbers fh = font.size('0123456789')[1] surface = pygame.Surface((w, h)) surface.fill((0, 128, 255))