PK!44nummu/__init__.py__version__ = '0.1.8' from nummu.core import Nummu PK!q޼' nummu/core.pyimport warnings import numpy as np from array2gif import write_gif from numpngw import write_apng class Nummu: def __init__(self, height, weight): self.seq = [] self.is_quit = False self.modules = [] self.resources = {} self.height = height self.weight = weight def load(self, name, type, **meta): self.resources[name] = dict(type=type, **meta) def add(self, mod): self.modules.append(mod) def quit(self): self.is_quit = True def _run_init(self): for mod in self.modules: if hasattr(mod, 'init'): warnings.warn('init is deprecated, use __init__ instead.', DeprecationWarning) mod.init() def _run_update(self, delta): for mod in self.modules: if hasattr(mod, 'update'): mod.update(delta) def _run_draw(self): palette = np.zeros((self.height, self.weight, 3), dtype=np.uint8) for mod in self.modules: if hasattr(mod, 'draw'): mod.draw(palette) self.seq.append(palette) def export(self, filename, delay, length=30000): self._run_init() progress = 0 while not self.is_quit: try: self._run_update(delay) self._run_draw() progress += delay if progress >= length: raise StopIteration except StopIteration: self.quit() if filename.endswith('.png'): write_apng(filename, self.seq, delay=delay, use_palette=True) elif filename.endswith('.gif'): # array2gif requires a transposed matrix compared to numpngw. seq = [] for s in self.seq: seq.append(np.transpose(s, axes=[1, 0, 2])) write_gif(seq, filename, fps=int(1000/delay)) else: raise NotImplementedError('Unsupported file format') PK!@44 nummu/draw.pyimport numpy as np from PIL import Image, ImageDraw, ImageFont def _get_rect(x, y, width, height, angle): rect = np.array([(0, 0), (width, 0), (width, height), (0, height), (0, 0)]) theta = (np.pi / 180.0) * angle R = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]]) return np.dot(rect, R) + np.array([x, y]) def rect(pallete, x, y, w, h, angle=0, color=0): _rect = _get_rect(x, y, w, h, angle) img = Image.fromarray(pallete) draw = ImageDraw.Draw(img) draw.polygon([tuple(p) for p in _rect], fill=color) pallete[:, :, :] = np.asarray(img) def line(pallete, x1, y1, x2, y2, color=0): img = Image.fromarray(pallete) draw = ImageDraw.Draw(img) draw.line((x1, y1, x2, y2), fill=color) pallete[:, :, :] = np.asarray(img) def image(pallete, x, y, img): bg = Image.fromarray(pallete) if isinstance(img, str): _img = Image.open(img) bg.paste(_img, (x, y), _img) else: raise ValueError('unknown img type.') pallete[:, :, :] = np.asarray(bg) PK!3:&&nummu/errors.pyclass NummuError(Exception): pass PK!BR''nummu-0.1.8.dist-info/LICENSEMIT License Copyright (c) 2018 Soasme Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HNɡSTnummu-0.1.8.dist-info/WHEEL HM K-*ϳR03rOK-J,/R(O-)T03"]b݀ҢԜ$+TtJcݼTļJ.PK!HB^,5:nummu-0.1.8.dist-info/METADATAWMS7CfbOM=q tڄBÀګJZs\M.Wǣ{ߒ17 )-d>fݰ,/ V rW9ȸ9_ }QaxaFDkOWIJFձIiuF)dLBn-$/'pxnʵ3Av\,Ơ;1WKK mp)T^d2a~+ݹYXzX";H 2]MdQņnL !u>_ dw'CA"4+"D>A 8R3AHân Y*M^x PN(g…kؽ6mڟiBeRY-1Vk.`j3RՀբ)֝|oOYTudv Sp9چMD6Lj]:iGшFA;Ѵߛ9q C wFNp0ǣYo(w; Giΰ {S -zX8] ۰,I3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