mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-13 08:11:54 +02:00
Refactor buildings and craters.
This commit is contained in:
parent
0f632087e4
commit
1b035300df
5 changed files with 293 additions and 266 deletions
46
map_machine/feature/crater.py
Normal file
46
map_machine/feature/crater.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
"""
|
||||
Crater on the map.
|
||||
"""
|
||||
import numpy as np
|
||||
from colour import Color
|
||||
from svgwrite import Drawing
|
||||
|
||||
from map_machine.geometry.flinger import Flinger
|
||||
from map_machine.osm.osm_reader import Tagged
|
||||
|
||||
|
||||
class Crater(Tagged):
|
||||
"""Volcano or impact crater on the map."""
|
||||
|
||||
def __init__(
|
||||
self, tags: dict[str, str], coordinates: np.ndarray, point: np.ndarray
|
||||
) -> None:
|
||||
super().__init__(tags)
|
||||
self.coordinates: np.ndarray = coordinates
|
||||
self.point: np.ndarray = point
|
||||
|
||||
def draw(self, svg: Drawing, flinger: Flinger) -> None:
|
||||
"""Draw crater ridge."""
|
||||
scale: float = flinger.get_scale(self.coordinates)
|
||||
assert "diameter" in self.tags
|
||||
radius: float = float(self.tags["diameter"]) / 2.0
|
||||
radial_gradient = svg.radialGradient(
|
||||
center=self.point + np.array((0.0, radius * scale / 7.0)),
|
||||
r=radius * scale,
|
||||
gradientUnits="userSpaceOnUse",
|
||||
)
|
||||
color: Color = Color("#000000")
|
||||
gradient = svg.defs.add(radial_gradient)
|
||||
(
|
||||
gradient
|
||||
.add_stop_color(0.0, color.hex, opacity=0.2)
|
||||
.add_stop_color(0.7, color.hex, opacity=0.2)
|
||||
.add_stop_color(1.0, color.hex, opacity=1.0)
|
||||
) # fmt: skip
|
||||
circle = svg.circle(
|
||||
self.point,
|
||||
radius * scale,
|
||||
fill=gradient.get_funciri(),
|
||||
opacity=0.2,
|
||||
)
|
||||
svg.add(circle)
|
Loading…
Add table
Add a link
Reference in a new issue