The python version of Tweetable Mathematical Art
Usage:
- import
gen.py
- inherit class
TMA
- 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 isDIM*DIM
- instantiate then call
Gen()
, the generated image would be saved tofilename
Tweetable Mathematical Art 的Python实现
用法:
- 导入
gen.py
- 继承
TMA
类 - 实现
RD(i, j, DIM)
,GR(i, j, DIM)
,BL(i, j, DIM)
三个抽象方法, 用于指定生成图在(i, j)
位置的RGB值, 生成图的尺寸是DIM*DIM
- 实例化并调用
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 / 以上代码将会生成如下的图像: