Initial implementation of paths, hexagon pattern
This commit is contained in:
parent
518de9cef8
commit
e18688495f
1 changed files with 104 additions and 0 deletions
|
@ -1,6 +1,110 @@
|
||||||
import math
|
import math
|
||||||
import cairo
|
import cairo
|
||||||
|
|
||||||
|
from typing import Iterable
|
||||||
|
|
||||||
|
class Path():
|
||||||
|
__slots__ = 'commands',
|
||||||
|
|
||||||
|
def __init__(self, commands: Iterable):
|
||||||
|
self.commands = commands
|
||||||
|
|
||||||
|
def horiz_to(self, cr: cairo.Context, x2: float):
|
||||||
|
_, y = cr.get_current_point()
|
||||||
|
|
||||||
|
return cr.line_to(x2, y)
|
||||||
|
|
||||||
|
def rel_horiz_to(self, cr: cairo.Context, x2: float):
|
||||||
|
x, y = cr.get_current_point()
|
||||||
|
|
||||||
|
return cr.line_to(x + x2, y)
|
||||||
|
|
||||||
|
def vert_to(self, cr: cairo.Context, y2: float):
|
||||||
|
x, _ = cr.get_current_point()
|
||||||
|
|
||||||
|
return cr.line_to(x, y2)
|
||||||
|
|
||||||
|
def rel_vert_to(self, cr: cairo.Context, y2: float):
|
||||||
|
x, y = cr.get_current_point()
|
||||||
|
|
||||||
|
return cr.line_to(x, y + y2)
|
||||||
|
|
||||||
|
def draw(self, cr: cairo.Context):
|
||||||
|
for item in self.commands:
|
||||||
|
command, args = item
|
||||||
|
fn = fns[command]
|
||||||
|
|
||||||
|
if command == 'M':
|
||||||
|
for arg in args:
|
||||||
|
cr.move_to(*arg)
|
||||||
|
elif command == 'm':
|
||||||
|
for arg in args:
|
||||||
|
cr.rel_move_to(*arg)
|
||||||
|
elif command == 'L':
|
||||||
|
for arg in args:
|
||||||
|
cr.line_to(*arg)
|
||||||
|
elif command == 'l':
|
||||||
|
for arg in args:
|
||||||
|
cr.rel_line_to(*arg)
|
||||||
|
elif command == 'H':
|
||||||
|
for arg in args:
|
||||||
|
self.horiz_to(cr, arg)
|
||||||
|
elif command == 'h':
|
||||||
|
for arg in args:
|
||||||
|
self.rel_horiz_to(cr, arg)
|
||||||
|
elif command == 'V':
|
||||||
|
for arg in args:
|
||||||
|
self.vert_to(cr, arg)
|
||||||
|
elif command == 'v':
|
||||||
|
for arg in args:
|
||||||
|
self.rel_vert_to(cr, arg)
|
||||||
|
elif command == 'Z':
|
||||||
|
cr.close_path()
|
||||||
|
|
||||||
|
class HexagonPattern():
|
||||||
|
COMMANDS = (
|
||||||
|
('M', ((23.246093, 0), (0, 13.382812))),
|
||||||
|
('V', (44.689453,)),
|
||||||
|
('L', ((0.0839844, 44.640625),
|
||||||
|
(24.033203, 58.505859),
|
||||||
|
(24.001953, 86.332031),
|
||||||
|
(22.841796, 87))),
|
||||||
|
('h', (4.478516,)),
|
||||||
|
('L', ((26.068359, 86.275391),
|
||||||
|
(26.099609, 58.449219),
|
||||||
|
(50.083984, 44.640625),
|
||||||
|
(74.033203, 58.505859),
|
||||||
|
(74.001953, 86.332031),
|
||||||
|
(72.841796, 87))),
|
||||||
|
('h', (4.478516,)),
|
||||||
|
('L', (( 76.068359, 86.275391),
|
||||||
|
( 76.099609, 58.449219),
|
||||||
|
(100, 44.689453))),
|
||||||
|
('V', (13.365234,)),
|
||||||
|
('L', ((76.919921, 0))),
|
||||||
|
('H', (73.246093,)),
|
||||||
|
('L', ((50.015625, 13.373047),
|
||||||
|
(26.919921, 0))),
|
||||||
|
('Z', ()),
|
||||||
|
('M', ((25.083984, 1.25),
|
||||||
|
(49.033203, 15.115234),
|
||||||
|
(49.001953, 42.941406),
|
||||||
|
(25.017578, 56.75),
|
||||||
|
(1.0019531, 42.845703))),
|
||||||
|
('l', ((0.033203, -27.75))),
|
||||||
|
('z'),
|
||||||
|
('m', ((50,0),
|
||||||
|
(24.017576, 13.904297),
|
||||||
|
(-0.0352, 27.75))),
|
||||||
|
('L', ((75.017578, 56.75),
|
||||||
|
(51.068359, 42.884766),
|
||||||
|
(51.099609, 15.058594))),
|
||||||
|
('Z', ())
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(self.COMMANDS)
|
||||||
|
|
||||||
class Gauge():
|
class Gauge():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue