This repository was archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogo.py
78 lines (61 loc) · 1.78 KB
/
logo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import numpy as np
from funcs import logoFunc
import matplotlib
from matplotlib import pyplot as plt
import PIL.Image
import colorcet
def background(xscale=3):
return np.mean(makeLogo(xscale*10)[-1])
defaultRes=2048
def makeLogo(x=0, y=0, xscale=3, xres=defaultRes, yres=defaultRes):
xs=np.linspace(-xscale+x, x+xscale, xres)
ys=np.linspace(y-1, y+30, yres)
xys=np.array(np.meshgrid(xs, ys))
zs=logoFunc(xys)
zs=np.flip(zs, axis=0)
return (xs, ys, xys, zs)
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import LightSource
logoBack=background()
defaultCmap=colorcet.m_rainbow_r
def getColors(z, cmap=None):
if cmap is None:
cmap=defaultCmap
mz=np.array(z)
mz[mz>logoBack]=logoBack
mz-=np.min(mz)
mz/=np.max(mz)
cols=cmap(mz)
#cols=np.zeros((z.shape[0], z.shape[1], 4))
#cols[:,:,3]=np.exp(-mz)
return cols
def plotLogo3D(res=defaultRes):
(x, y, xy, z)=makeLogo(xres=res, yres=res)
fig = plt.figure()
ax = Axes3D(fig)
ax.view_init(elev=90, azim=90)
ax.plot_surface(*xy, z, facecolors=getColors(z))
#ax.contour(x, y, z)
return fig
def plotLogo(res=defaultRes):
(x, y, xy, z)=makeLogo(xres=res, yres=res)
del(xy)
del(x)
del(y)
imgData=getColors(z)
del(z)
im=PIL.Image.fromarray(np.array(imgData*255, dtype=np.int8), "RGBA")
return im
from plumbum import cli
class LogoPlotterCLI(cli.Application):
res=cli.SwitchAttr(["r", "resolution"], int, default=defaultRes, help="A resolution of the image. Use the highest possible.")
threeD=cli.Flag(["3d"], help="Plot 3d")
def main(self):
if not self.threeD:
im=plotLogo(res=self.res)
im.save("logo.png", format="png")
else:
fig=plotLogo3D(res=self.res)
plt.show()
if __name__=="__main__":
LogoPlotterCLI.run()