Skip to content

Commit

Permalink
Added a variant to not draw.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwatsonforster committed Sep 29, 2023
1 parent 7b4dee5 commit 1770bcd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
45 changes: 45 additions & 0 deletions airpower/draw.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import airpower.variants as apvariants

import numpy as np

import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['figure.figsize'] = [7.5, 10]
plt.rcParams.update({'font.size': 10})

_donotdraw = True

def setcanvas(x, y):
global _donotdraw
if apvariants.withvariant("do not draw"):
_donotdraw = True
if _donotdraw:
return
matplotlib.rcParams['figure.figsize'] = [x, y]
plt.figure()
plt.axis('equal')
Expand All @@ -23,18 +32,24 @@ def physicaltohex(x,y):

def _drawhexinphysical(x, y, size=1, color="lightgrey"):
# size is inscribed diameter
if _donotdraw:
return
azimuths = np.array((0, 60, 120, 180, 240, 300, 0))
xvertices = x + 0.5 * size * cosd(azimuths) / cosd(30)
yvertices = y + 0.5 * size * sind(azimuths) / cosd(30)
plt.plot(xvertices, yvertices, color=color, zorder=0)

def _drawdotinphysical(x, y, size=1, facing=0, dx=0, dy=0, color="black"):
if _donotdraw:
return
x = x + dx * sind(facing) + dy * cosd(facing)
y = y - dx * cosd(facing) + dy * sind(facing)
plt.plot(x, y, marker=".", color=color, zorder=1)

def _drawsquareinphysical(x, y, facing, size=1, dx=0, dy=0, color="black"):
# size is diagonal
if _donotdraw:
return
x = x + dx * sind(facing) + dy * cosd(facing)
y = y - dx * cosd(facing) + dy * sind(facing)
azimuths = np.array((0, 90, 180, 270, 0))
Expand All @@ -45,10 +60,14 @@ def _drawsquareinphysical(x, y, facing, size=1, dx=0, dy=0, color="black"):
plt.plot(xvertices, yvertices, color=color, zorder=1)

def _drawlineinphysical(x0, y0, x1, y1, color="black", linestyle="solid", zorder=1):
if _donotdraw:
return
plt.plot((x0, x1), (y0, y1), linestyle=linestyle, color=color, zorder=zorder)

def _drawarrowinphysical(x, y, facing, size=1.0, dx=0, dy=0, color="black"):
# size is length
if _donotdraw:
return
x = x + dx * sind(facing) + dy * cosd(facing)
y = y - dx * cosd(facing) + dy * sind(facing)
x0 = x - 0.5 * size * cosd(facing)
Expand All @@ -59,6 +78,8 @@ def _drawarrowinphysical(x, y, facing, size=1.0, dx=0, dy=0, color="black"):

def _drawdartinphysical(x, y, facing, size=1.0, dx=0, dy=0, color="black"):
# size is length
if _donotdraw:
return
x = x + dx * sind(facing) + dy * cosd(facing)
y = y - dx * cosd(facing) + dy * sind(facing)
x0 = x - 0.5 * size * cosd(facing)
Expand All @@ -68,6 +89,8 @@ def _drawdartinphysical(x, y, facing, size=1.0, dx=0, dy=0, color="black"):
plt.arrow(x0, y0, x1 - x0, y1 - y0, width=0.02, head_length=size, head_width=0.5*size, color=color, length_includes_head=True, zorder=1)

def _drawtextinphysical(x, y, facing, s, size=10, dx=0, dy=0, color="black"):
if _donotdraw:
return
x = x + dx * sind(facing) + dy * cosd(facing)
y = y - dx * cosd(facing) + dy * sind(facing)
plt.text(x, y, s, size=size, rotation=facing - 90,
Expand All @@ -77,38 +100,60 @@ def _drawtextinphysical(x, y, facing, s, size=10, dx=0, dy=0, color="black"):
rotation_mode="anchor")

def _drawcompassinphysical(x, y, facing):
if _donotdraw:
return
_drawdotinphysical(x, y, size=0.3)
_drawarrowinphysical(x, y, facing, size=0.8, dy=+0.4)
_drawtextinphysical(x, y, facing, "N", dy=0.95)

def drawhex(x, y, **kwargs):
if _donotdraw:
return
_drawhexinphysical(*hextophysical(x, y), **kwargs)

def drawdot(x, y, **kwargs):
if _donotdraw:
return
_drawdotinphysical(*hextophysical(x, y), **kwargs)

def drawsquare(x, y, facing, **kwargs):
if _donotdraw:
return
_drawsquareinphysical(*hextophysical(x, y), facing, **kwargs)

def drawline(x0, y0, x1, y1, **kwargs):
if _donotdraw:
return
_drawlineinphysical(*hextophysical(x0, y0), *hextophysical(x1, y1), **kwargs)

def drawarrow(x, y, facing, **kwargs):
if _donotdraw:
return
_drawarrowinphysical(*hextophysical(x, y), facing, **kwargs)

def drawdart(x, y, facing, **kwargs):
if _donotdraw:
return
_drawdartinphysical(*hextophysical(x, y), facing, **kwargs)

def drawtext(x, y, facing, s, **kwargs):
if _donotdraw:
return
_drawtextinphysical(*hextophysical(x, y), facing, s, **kwargs)

def drawcompass(x, y, facing, **kwargs):
if _donotdraw:
return
_drawcompassinphysical(*hextophysical(x, y), facing, **kwargs)

def drawflightpath(lastx, lasty, x, y):
if _donotdraw:
return
drawline(lastx, lasty, x, y, color="darkgray", linestyle="dashed", zorder=0.5)

def drawaircraft(x, y, facing, name, altitude, when):
if _donotdraw:
return
if when == "end":
color = "black"
else:
Expand Down
5 changes: 3 additions & 2 deletions airpower/prolog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
def startprolog(sheets, compassrose, north="up", variants=[]):
aplog.log("--- start prolog ---")
aplog.logbreak()
apvariants.setvariants(variants)
aplog.logbreak()
apmap.setmap(sheets, compassrose)
aplog.logbreak()
apazimuth.setnorth(north)
aplog.logbreak()
apvariants.setvariants(variants)
aplog.logbreak()

apmap.drawmap()
apturn.restart()

Expand Down
1 change: 1 addition & 0 deletions airpower/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"disallow ENE/ESE/WSW/WNW",
"prefer NE/SE/SW/NW",
"implicit turn and bank declarations"
"do not draw"
]

_variants = []
Expand Down

0 comments on commit 1770bcd

Please sign in to comment.