Python美丽图案生成方法

发布时间 2023-11-09 18:23:35作者: 艾孜尔江

使用samila库可以生成美丽的图案, 例如:

# pip install samila==1.1 or pip3 install samila==1.1

import matplotlib.pyplot as plt
from samila import GenerativeImage

# g = GenerativeImage()
# g.generate()
# g.plot()
# plt.show()

import random
import math


def f1(x, y):
    result = random.uniform(-1, 1) * x**2 - math.sin(y**2) + abs(y-x)
    return result


def f2(x, y):
    result = random.uniform(-1, 1) * y**3 - math.cos(x**2) + 2*x
    return result


g = GenerativeImage(f1, f2)
g.generate()
g.plot()
plt.show()


g = GenerativeImage(f1, f2)
g.generate()
g.plot(color="yellow", bgcolor="black", projection=Projection.POLAR)
g.seed
1018273
plt.show()

生成结果: