That's better
This commit is contained in:
parent
d5294e111d
commit
b818671816
1 changed files with 30 additions and 2 deletions
|
@ -1,6 +1,14 @@
|
|||
import math
|
||||
import cairo
|
||||
|
||||
PRESSURE_MAX = 1050 # millibar
|
||||
PRESSURE_MIN = 100
|
||||
PRESSURE_STEP = 50
|
||||
|
||||
PRESSURE_LOG_MAX = math.log(PRESSURE_MAX)
|
||||
PRESSURE_LOG_MIN = math.log(PRESSURE_MIN)
|
||||
PRESSURE_LOG_RANGE = PRESSURE_LOG_MAX - PRESSURE_LOG_MIN
|
||||
|
||||
TEMP_CENTER = 0 # degrees C
|
||||
TEMP_STEP = 5
|
||||
|
||||
|
@ -38,8 +46,27 @@ class SkewT():
|
|||
def graph_to_screen(self, x, y) -> tuple:
|
||||
return (self.width / 2) + x, self.height - y
|
||||
|
||||
def draw_pressure_lines(self, cr: cairo.Context):
|
||||
pass
|
||||
def pressure_y(self, pressure: float) -> float:
|
||||
log_p = math.log(clamp(pressure, PRESSURE_MIN, PRESSURE_MAX))
|
||||
factor = (PRESSURE_LOG_MAX - log_p) / PRESSURE_LOG_RANGE
|
||||
|
||||
return factor * self.height
|
||||
|
||||
def sample_to_graph(self, temp: float, pressure: float):
|
||||
x = (temp / TEMP_STEP) * self.temp_step_width
|
||||
y = self.pressure_y(pressure)
|
||||
|
||||
return x + y, y
|
||||
|
||||
def draw_pressure_lines(self, cr: cairo.Context, x: float, y: float):
|
||||
for pressure in range(PRESSURE_MIN, PRESSURE_MAX+1, PRESSURE_STEP):
|
||||
coord = self.graph_to_screen(-self.width / 2,
|
||||
self.pressure_y(pressure))
|
||||
|
||||
cr.set_source_rgba(0, 0, 0, 0.5)
|
||||
cr.move_to(x + coord[0], y + coord[1])
|
||||
cr.rel_line_to(self.width, 0)
|
||||
cr.stroke()
|
||||
|
||||
def draw_isotherms(self, cr: cairo.Context, x: float, y: float):
|
||||
cr.set_source_rgba(0.1, 0.5, 0.1, 0.8)
|
||||
|
@ -59,3 +86,4 @@ class SkewT():
|
|||
|
||||
def draw(self, cr: cairo.Context, x: float, y: float):
|
||||
self.draw_isotherms(cr, x, y)
|
||||
self.draw_pressure_lines(cr, x, y)
|
||||
|
|
Loading…
Add table
Reference in a new issue