Skip to content
/ TMA_py Public

The python version of Tweetable Mathematical Art

Notifications You must be signed in to change notification settings

0x00A0/TMA_py

Repository files navigation

TMA_py


The python version of Tweetable Mathematical Art

Usage:

  1. import gen.py
  2. inherit class TMA
  3. implements RD(i, j, DIM), GR(i, j, DIM), BL(i, j, DIM), to specify the RGB value of the generated image at position (i, j), the size of the image is DIM*DIM
  4. instantiate then call Gen(), the generated image would be saved to filename

Tweetable Mathematical Art 的Python实现

用法:

  1. 导入gen.py
  2. 继承TMA
  3. 实现RD(i, j, DIM), GR(i, j, DIM), BL(i, j, DIM)三个抽象方法, 用于指定生成图在(i, j)位置的RGB值, 生成图的尺寸是DIM*DIM
  4. 实例化并调用Gen()方法, 生成的图像会被保存到filename指定的位置

Example/示例:

from gen import *
class Demo(TMA):
	def __init__(self, filename: str, DIM=1024):
		super().__init__(filename, DIM)

	def RD(self, i: int, j: int, DIM: int):
		return 255 * math.cos(math.atan2(j - 512, i - 512) / 2) ** 2

	def GR(self, i: int, j: int, DIM: int):
		return 255 * math.cos(math.atan2(j - 512, i - 512) / 2 - 2 * math.acos(-1) / 3) ** 2

	def BL(self, i: int, j: int, DIM: int):
		return 255 * math.cos(math.atan2(j - 512, i - 512) / 2 + 2 * math.acos(-1) / 3) ** 2


if __name__ == '__main__':
	demo = Demo(r'demo.png')
	demo.Gen()

The generated image of codes above would be / 以上代码将会生成如下的图像:

Demo image

About

The python version of Tweetable Mathematical Art

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages