这是生成分形的代码
import matplotlib.pyplot as plt
def makes(self, fractal):
if (fractal == "SierpinskiTriangle"):
SierpinskiTriangle(self.dimensions)
for i in range(len(SierpinskiTriangle.verticies)):
plotPoint(i, self.vertexColor, self.vertexRadius)
for i in range(SierpinskiTriangle.numPoints):
listVertices = SierpinskiTriangle.verticies
randVert = randint(0, len(listVertices)-1)
newVertexPoint = listVertices[randVert]
m1 = Point.midpt(m1, newVertexPoint)
self.plot(m1)
elif (fractal == "SierpinskiCarpet"):
SierpinskiCarpet(self.dimensions)
for i in range(len(SierpinskiCarpet.verticies)):
plotPoint(i, self.vertexColor, self.vertexRadius)
for i in range(SierpinskiCarpet.numPoints):
listVertices = SierpinskiCarpet
randVert = randint(0, len(listVertices)-1)
newVertexPoint = listVertices[randVert]
m1 = Point.midpt(m1, newVertexPoint)
self.plot(m1)
else:
Pentagon(self.dimensions)
for i in range(len(Pentagon.verticies)):
plotPoint(i, self.vertexColor, self.vertexRadius)
for i in range(Pentagon.numPoints):
listVertices = SierpinskiCarpet
randVert = randint(0, len(listVertices)-1)
newVertexPoint = listVertices[randVert]
m1 = Point.midpt(m1, newVertexPoint)
self.plot(m1)
最后,我不知道如何将分形可视化
我认为这与matplot.lib有关,但我不确定如何处理
虽然
matplotplib
主要适用于绘制图形,但如果您愿意,也可以使用它绘制点和多边形;另见:How to draw a triangle using matplotlib.pyplot based on 3 dots (x,y) in 2D?例如,要从多边形合成Sierpinski triangle,并将这些多边形绘制到图形上,请执行以下操作:
以上代码为我生成以下图像输出:
相关问题 更多 >
编程相关推荐