ascii-figures 1.0.4__tar.gz
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.
- ascii_figures-1.0.4/PKG-INFO +7 -0
- ascii_figures-1.0.4/ascii_figures.egg-info/PKG-INFO +7 -0
- ascii_figures-1.0.4/ascii_figures.egg-info/SOURCES.txt +6 -0
- ascii_figures-1.0.4/ascii_figures.egg-info/dependency_links.txt +1 -0
- ascii_figures-1.0.4/ascii_figures.egg-info/top_level.txt +1 -0
- ascii_figures-1.0.4/pattern/pattern.py +89 -0
- ascii_figures-1.0.4/pyproject.toml +13 -0
- ascii_figures-1.0.4/setup.cfg +4 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pattern
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
def s():
|
|
2
|
+
return "█"
|
|
3
|
+
def rectangle(height, width, hollow=False):
|
|
4
|
+
return "\n".join(s()*width for i in range(height)) if not hollow else "\n".join(s()*width if i in (0, height-1) else s()+" "*(width-2)+s() for i in range(height))
|
|
5
|
+
def triangle(height, type="rtp"):
|
|
6
|
+
if type=="rtp":
|
|
7
|
+
return "\n".join(s()*i for i in range(1, height+1))
|
|
8
|
+
elif type=="irtp":
|
|
9
|
+
return "\n".join(s()*i for i in range(height, 0, -1))
|
|
10
|
+
elif type=="cpp":
|
|
11
|
+
return "\n".join(" "*(height-i)+s()*(2*i-1) for i in range(1, height+1))
|
|
12
|
+
elif type=="htp":
|
|
13
|
+
return "\n".join(s()*(2*height-1) if i==height-1 else " "*(height-i-1)+s()+(" "*(2*i-1)+s() if i else "") for i in range(height))
|
|
14
|
+
elif type=="paskal":
|
|
15
|
+
return "\n".join(" "*(height-i-1)+" ".join(str(__import__("math").comb(i, j)) for j in range(i+1)) for i in range(height))
|
|
16
|
+
def parallelogram(height, width):
|
|
17
|
+
return "\n".join(" "*(height-i-1)+s()*width for i in range(height))
|
|
18
|
+
def trapezoid(height):
|
|
19
|
+
return "\n".join(" "*(height-i-1)+s()*(2*i+5) for i in range(height))
|
|
20
|
+
def hourglass(height):
|
|
21
|
+
return "\n".join(" "*(height-i)+s()*(2*i-1) for i in range(height, 0, -1))+"\n"+"\n".join(" "*(height-i)+s()*(2*i-1) for i in range(2, height+1))
|
|
22
|
+
def bow_tie(height):
|
|
23
|
+
return "\n".join(s()*i+" "*(2*(height-i))+s()*i for i in range(1, height+1))+"\n"+"\n".join(s()*i+" "*(2*(height-i))+s()*i for i in range(height-1, 0, -1))
|
|
24
|
+
def cross(height):
|
|
25
|
+
return "\n".join(s()*height if i==height//2 else " "*(height//2)+s() for i in range(height))
|
|
26
|
+
def checkerboard(height, width, first=True):
|
|
27
|
+
return "\n".join("".join([s(), " "][(i+j)%2-int(first)] for j in range(width)) for i in range(height))
|
|
28
|
+
def sierpinski_carpet(iter):
|
|
29
|
+
return "\n".join("".join(" " if any((x//3**k)%3==1 and (y//3**k)%3==1 for k in range(iter)) else s() for x in range(3**iter)) for y in range(3**iter))
|
|
30
|
+
def circle(radius):
|
|
31
|
+
return "\n".join("".join(s() if x**2+y**2<=radius**2 else " " for x in range(-radius, radius+1)) for y in range(-radius, radius+1))
|
|
32
|
+
def ellipse(height, width):
|
|
33
|
+
return "\n".join("".join(s() if ((x-(width-1)/2)/(width/2))**2+((y-(height-1)/2)/(height/2))**2<=1 else " " for x in range(width)) for y in range(height))
|
|
34
|
+
def contour(figure, fillsymbol=s()):
|
|
35
|
+
return "\n".join(row if i in (0, len(figure.split("\n"))-1) else "".join(c if c == fillsymbol and j in (row.find(fillsymbol), row.rfind(fillsymbol)) else " " for j, c in enumerate(row)) if fillsymbol in row else " "*len(row) for i, row in enumerate(figure.split("\n")) for row in [figure.split("\n")[i]])
|
|
36
|
+
def mandelbrot(height, width, iterations=30, chars=" .:-=+*#%@"):
|
|
37
|
+
result = []
|
|
38
|
+
for y in range(height):
|
|
39
|
+
row = ""
|
|
40
|
+
for x in range(width):
|
|
41
|
+
c = complex(x / width * 3.5 - 2.5, y / height * 2 - 1)
|
|
42
|
+
z = 0j
|
|
43
|
+
for i in range(iterations):
|
|
44
|
+
z = z*z + c
|
|
45
|
+
if abs(z) > 2:
|
|
46
|
+
break
|
|
47
|
+
if abs(z) > 2:
|
|
48
|
+
row += chars[min(len(chars)-1, i * len(chars) // iterations)]
|
|
49
|
+
else:
|
|
50
|
+
row += chars[-1]
|
|
51
|
+
result.append(row)
|
|
52
|
+
return "\n".join(result)
|
|
53
|
+
def spiral(height, width, turns=3, point=3000):
|
|
54
|
+
from math import sin, cos, pi
|
|
55
|
+
return (lambda p={(round((width-1)/2 + (0.48*i/(point-1))*(width-1)*cos(turns*2*pi*i/(point-1))), round((height-1)/2 + (0.48*i/(point-1))*(height-1)*sin(turns*2*pi*i/(point-1))*2)) for i in range(point)}: "\n".join("".join(s() if (x, y) in p else " " for x in range(width)) for y in range(height)))()
|
|
56
|
+
def heart(width=41, height=21):
|
|
57
|
+
return "\n".join("".join(s() if (((-1.5+3*i/(width-1))**2+(1.5-3*j/(height-1))**2-1)**3-(-1.5+3*i/(width-1))**2*(1.5-3*j/(height-1))**3)<=0 else " " for i in range(width)) for j in range(height))
|
|
58
|
+
def cantor(width):
|
|
59
|
+
from math import log
|
|
60
|
+
return"\n".join("".join(" " if any((x//(3**(int(log(width,3))-k-1)))%3==1 for k in range(i)) else s() for x in range(width)) for i in range(int(log(width,3))+1))
|
|
61
|
+
def formula(f, rx, ry):
|
|
62
|
+
return "\n".join("".join(s() if f(x, y) else " " for x in rx) for y in ry)
|
|
63
|
+
def dragon(n=10):
|
|
64
|
+
res=[]
|
|
65
|
+
s = "FX"
|
|
66
|
+
for _ in range(n):
|
|
67
|
+
s = "".join("X+YF+" if c == "X" else "-FX-Y" if c == "Y" else c for c in s)
|
|
68
|
+
x = y = 0
|
|
69
|
+
d = 0
|
|
70
|
+
points = [(x,y)]
|
|
71
|
+
for c in s:
|
|
72
|
+
if c == "F":
|
|
73
|
+
x += (1,0,-1,0)[d]
|
|
74
|
+
y += (0,1,0,-1)[d]
|
|
75
|
+
points.append((x,y))
|
|
76
|
+
elif c == "+":
|
|
77
|
+
d = (d+1)%4
|
|
78
|
+
elif c == "-":
|
|
79
|
+
d = (d-1)%4
|
|
80
|
+
minx = min(x for x,y in points)
|
|
81
|
+
maxx = max(x for x,y in points)
|
|
82
|
+
miny = min(y for x,y in points)
|
|
83
|
+
maxy = max(y for x,y in points)
|
|
84
|
+
g = [[" " for _ in range(maxx-minx+1)] for _ in range(maxy-miny+1)]
|
|
85
|
+
for x,y in points:
|
|
86
|
+
g[maxy-y][x-minx] = "*"
|
|
87
|
+
res.append("\n".join("".join(r) for r in g))
|
|
88
|
+
return "\n".join(res)
|
|
89
|
+
print(contour(heart()))
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ascii-figures"
|
|
7
|
+
version = "1.0.4"
|
|
8
|
+
description = "Generate ASCII figures and mathematical fractals"
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
|
+
authors = [
|
|
11
|
+
{name = "Muhəmməd Zeynallı"}
|
|
12
|
+
]
|
|
13
|
+
license = "MIT"
|