Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用标签绘制此IFS cantor集?_Python_Fractals_Zelle Graphics - Fatal编程技术网

Python 如何使用标签绘制此IFS cantor集?

Python 如何使用标签绘制此IFS cantor集?,python,fractals,zelle-graphics,Python,Fractals,Zelle Graphics,我正在使用Python中的Zelle图形包绘制cantor三元图的迭代,如IFS(迭代函数系统)图。 我想画的迭代函数系统是: {R;x/9+1/6,2/3+x/9,x/9+1/3,x/9+5/6} 下面的代码是我在互联网上找到的代码的仿制品。代码正确吗?如何使每个线段具有不同的颜色,以及如何标记每个阶段中的点 from graphics import * def cantor_set(win,x,y,h,Len): if Len < 2: return line

我正在使用Python中的Zelle图形包绘制cantor三元图的迭代,如IFS(迭代函数系统)图。 我想画的迭代函数系统是:

{R;x/9+1/6,2/3+x/9,x/9+1/3,x/9+5/6}
下面的代码是我在互联网上找到的代码的仿制品。代码正确吗?如何使每个线段具有不同的颜色,以及如何标记每个阶段中的点

from graphics import *

def cantor_set(win,x,y,h,Len): 

    if Len < 2: return

    line = Line(Point(x, y), Point(x+Len, y))
    line.setWidth(20)
    line.draw(win)

    cantor_set(win,2*x+3,y+h,h,Len//18)
    cantor_set(win,2*x+12,y+h,h,Len//18)
    cantor_set(win,2*x+6,y+h,h,Len//18)
    cantor_set(win,2*x+15,y+h,h,Len//18)

def cantor_set_starter():
    Len = 790
    win = GraphWin("Cantor Set", 800, 200)
    c = cantor_set(win,5,20,50,790)
win.postscript(file = "can1.eps")
#win.getMouse()
#win.close()
cantor_set_starter()
从图形导入*
def CONTOR_集合(win、x、y、h、Len):
如果Len<2:返回
直线=直线(点(x,y),点(x+Len,y))
线条设置宽度(20)
平局(赢)
康托集(赢,2*x+3,y+h,h,Len//18)
康托集(赢,2*x+12,y+h,h,Len//18)
康托集(赢,2*x+6,y+h,h,Len//18)
康托集(赢,2*x+15,y+h,h,Len//18)
def CONTOR_set_starter():
Len=790
win=GraphWin(“康托集”,800200)
c=康托鲁集(赢,5,20,50790)
win.postscript(file=“can1.eps”)
#win.getMouse()
#赢
cantor_set_starter()

编程中有两种主要类型的错误:语法错误和算法错误。您的程序同时受到这两方面的影响。我们可以相当轻松地修复您的语法错误:

from graphics import *

def cantor_set(win, x, y, h, length):

    if length < 2:
        return

    line = Line(Point(x, y), Point(x + length, y))
    line.setWidth(20)
    line.draw(win)

    cantor_set(win, 2 * x + 3, y + h, h, length // 18)
    cantor_set(win, 2 * x + 12, y + h, h, length // 18)
    cantor_set(win, 2 * x + 6, y + h, h, length // 18)
    cantor_set(win, 2 * x + 15, y + h, h, length // 18)

def cantor_set_starter(length):
    cantor_set(win, 5, 20, 50, length)

win = GraphWin("Cantor Set", 800, 200)

cantor_set_starter(790)

win.getMouse()
win.close()
从图形导入*
def cantor_集合(win、x、y、h、长度):
如果长度小于2:
返回
直线=直线(点(x,y),点(x+长度,y))
线条设置宽度(20)
平局(赢)
cantor_集(win,2*x+3,y+h,h,长度//18)
cantor_集(win,2*x+12,y+h,h,长度//18)
cantor_集(win,2*x+6,y+h,h,长度//18)
cantor_集(win,2*x+15,y+h,h,长度//18)
def cantor_套装_启动器(长度):
坎托鲁组(赢,5,20,50,长)
win=GraphWin(“康托集”,800200)
康托尔套装起动器(790)
win.getMouse()
赢
但由于存在算法错误,它不会绘制类似于康托三元图的图形。为了帮助您解决这些问题,我们需要了解更多关于迭代函数系统方程和其他细节的信息。如果目标只是绘制一个康托集,我们可以修改您的程序,主要通过丢弃代码和调整剩余的数学:

from graphics import *

def cantor_set(win, x, y, height, length):

    if length < 2:
        return

    line = Line(Point(x, y), Point(x + length, y))
    line.setWidth(height / 2)
    line.draw(win)

    length /= 3

    cantor_set(win, x, y + height, height, length)
    cantor_set(win, x + 2 * length, y + height, height, length)

win = GraphWin("Cantor Set", 800, 300)

cantor_set(win, 5, 20, 50, 790)

win.getMouse()
win.close()
从图形导入*
def cantor_集合(win、x、y、高度、长度):
如果长度小于2:
返回
直线=直线(点(x,y),点(x+长度,y))
线条设置宽度(高度/2)
平局(赢)
长度/=3
cantor_集合(win、x、y+高度、高度、长度)
cantor_集(win,x+2*长度,y+高度,高度,长度)
win=GraphWin(“康托集”,800300)
坎托鲁组(赢,5,20,50,790)
win.getMouse()
赢