yaplotlib 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- yaplotlib-0.1.3.dist-info/METADATA +15 -0
- yaplotlib-0.1.3.dist-info/RECORD +4 -0
- yaplotlib-0.1.3.dist-info/WHEEL +4 -0
- yaplotlib.py +171 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: yaplotlib
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: A tiny library to generate Yaplot file.
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: vitroid
|
|
7
|
+
Author-email: vitroid@gmail.com
|
|
8
|
+
Requires-Python: >=3.11,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
yaplotlib.py,sha256=QgJ-QxuiA_yCSoQ98y9IRf43uyXnuQ5X1KnGr3D7nfc,4157
|
|
2
|
+
yaplotlib-0.1.3.dist-info/METADATA,sha256=vTpmZXCh2E9dmqQUIO0uFYxd8WgIOppBCznACS8ij58,435
|
|
3
|
+
yaplotlib-0.1.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
4
|
+
yaplotlib-0.1.3.dist-info/RECORD,,
|
yaplotlib.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# even: stable; odd: develop
|
|
3
|
+
__version__ = "0.1.3"
|
|
4
|
+
|
|
5
|
+
import colorsys
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def plaintext(a):
|
|
9
|
+
s = ""
|
|
10
|
+
for x in a:
|
|
11
|
+
s += "{0:.4f} ".format(x)
|
|
12
|
+
return s
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def Line(v0,v1):
|
|
16
|
+
return "l " + plaintext(v0) + plaintext(v1) + "\n"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def Text(v,txt):
|
|
20
|
+
return "t " + plaintext(v) + " " + txt + "\n"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def Circle(v0):
|
|
24
|
+
return "c " + plaintext(v0) + "\n"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def Arrow(v0,v1):
|
|
28
|
+
return "s " + plaintext(v0) + plaintext(v1) + "\n"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def Polygon(vertices):
|
|
33
|
+
s = f"p {len(vertices)} "
|
|
34
|
+
for v in vertices:
|
|
35
|
+
s += plaintext(v)
|
|
36
|
+
return s + "\n"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def Color(x):
|
|
41
|
+
return f"@ {int(x)}\n"
|
|
42
|
+
|
|
43
|
+
# R,G,B in range 0..255
|
|
44
|
+
def SetPalette(x,R,G=None,B=None,maxval=255):
|
|
45
|
+
if G is None:
|
|
46
|
+
R,G,B = R
|
|
47
|
+
r = int(R*255/maxval)
|
|
48
|
+
g = int(G*255/maxval)
|
|
49
|
+
b = int(B*255/maxval)
|
|
50
|
+
return f"@ {int(x)} {r} {g} {b}\n"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def Size(x):
|
|
54
|
+
return f"r {float(x)}\n"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def Layer(x):
|
|
58
|
+
return f"y {int(x)}\n"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def ArrowType(x):
|
|
62
|
+
return f"a {int(x)}\n"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def NewPage():
|
|
66
|
+
return "\n"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def RandomPalettes(N, offset=10):
|
|
70
|
+
omega = 2 / (5**0.5 - 1)
|
|
71
|
+
s = ""
|
|
72
|
+
for i in range(N):
|
|
73
|
+
hue = (omega * i) % 1.0
|
|
74
|
+
sat = 0.5
|
|
75
|
+
bri = 1.0
|
|
76
|
+
r,g,b = colorsys.hsv_to_rgb(hue, sat, bri)
|
|
77
|
+
s += SetPalette(i+offset, r,g,b, maxval=1.0)
|
|
78
|
+
return s
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def RainbowPalettes(N, offset=10):
|
|
82
|
+
s = ""
|
|
83
|
+
for i in range(N):
|
|
84
|
+
hue = i / N
|
|
85
|
+
sat = 0.5
|
|
86
|
+
bri = 1.0
|
|
87
|
+
r,g,b = colorsys.hsv_to_rgb(hue, sat, bri)
|
|
88
|
+
s += SetPalette(i+offset, r,g,b, maxval=1.0)
|
|
89
|
+
return s
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def GradationPalettes(N, color, color1=None, offset=10, maxval=255):
|
|
93
|
+
"""
|
|
94
|
+
いずれ、dictやlistでも与えられるようにする。
|
|
95
|
+
"""
|
|
96
|
+
s = ""
|
|
97
|
+
for i in range(N):
|
|
98
|
+
ratio = i / (N-1)
|
|
99
|
+
r = color[0]*(1-ratio) + color1[0]*ratio
|
|
100
|
+
g = color[1]*(1-ratio) + color1[1]*ratio
|
|
101
|
+
b = color[2]*(1-ratio) + color1[2]*ratio
|
|
102
|
+
s += SetPalette(i+offset, r, g, b, maxval)
|
|
103
|
+
return s
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class Yaplot():
|
|
107
|
+
def __init__(self):
|
|
108
|
+
self.s = ""
|
|
109
|
+
self.layer = 1
|
|
110
|
+
self.color = 2
|
|
111
|
+
self.size = 1
|
|
112
|
+
self.arrowtype = 1
|
|
113
|
+
def Layer(self, layer):
|
|
114
|
+
if layer < 0:
|
|
115
|
+
return
|
|
116
|
+
if layer != self.layer:
|
|
117
|
+
self.s += Layer(layer)
|
|
118
|
+
self.layer = layer
|
|
119
|
+
def Color(self, color):
|
|
120
|
+
if color < 0:
|
|
121
|
+
return
|
|
122
|
+
if color != self.color:
|
|
123
|
+
self.s += Color(color)
|
|
124
|
+
self.color = color
|
|
125
|
+
def Size(self, size):
|
|
126
|
+
if size < 0:
|
|
127
|
+
return
|
|
128
|
+
if size != self.size:
|
|
129
|
+
self.s += Size(size)
|
|
130
|
+
self.size = size
|
|
131
|
+
def ArrowType(self, arrowtype):
|
|
132
|
+
if arrowtype < 0:
|
|
133
|
+
return
|
|
134
|
+
if arrowtype != self.arrowtype:
|
|
135
|
+
self.s += ArrowType(arrowtype)
|
|
136
|
+
self.arrowtype = arrowtype
|
|
137
|
+
def Line(self, a, b, layer=-1, color=-1):
|
|
138
|
+
if layer > 0:
|
|
139
|
+
self.s += self.Layer(layer)
|
|
140
|
+
if color >= 0:
|
|
141
|
+
self.s += self.Color(color)
|
|
142
|
+
self.s += Line(a, b)
|
|
143
|
+
def Arrow(self, a, b, layer=-1, color=-1, size=-1, arrowtype=-1):
|
|
144
|
+
self.s += self.Layer(layer)
|
|
145
|
+
self.s += self.Color(color)
|
|
146
|
+
self.s += Line(a, b)
|
|
147
|
+
def Polygon(self, p, layer=-1, color=-1):
|
|
148
|
+
self.s += self.Layer(layer)
|
|
149
|
+
self.s += self.Color(color)
|
|
150
|
+
self.s += Polygon(p)
|
|
151
|
+
def Circle(self, c, layer=-1, color=-1, size=-1):
|
|
152
|
+
self.s += self.Layer(layer)
|
|
153
|
+
self.s += self.Color(color)
|
|
154
|
+
self.s += self.Size(size)
|
|
155
|
+
self.s += Circle(c)
|
|
156
|
+
def SetPalette(self, x, R, G=None, B=None, maxval=255):
|
|
157
|
+
self.s += SetPalette(x, R, G, B, maxval)
|
|
158
|
+
def GradationPalettes(self, N, color, color1=None, offset=10, maxval=255):
|
|
159
|
+
self.s += GradationPalettes(N, color, color1, offset, maxval)
|
|
160
|
+
def RandomPalettes(self, N, offset=10):
|
|
161
|
+
self.s += RandomPalettes(N, offset)
|
|
162
|
+
def RainbowPalettes(self, N, offset=10):
|
|
163
|
+
self.s += RainbowPalettes(N, offset)
|
|
164
|
+
def NewPage(self):
|
|
165
|
+
self.s += NewPage()
|
|
166
|
+
self.layer = 1
|
|
167
|
+
self.color = 2
|
|
168
|
+
self.arrowtype = 1
|
|
169
|
+
self.size = 1
|
|
170
|
+
def dumps(self):
|
|
171
|
+
return self.s
|