Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.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 如何获得李萨如曲线表中所有曲线的X和Y位置?_Python_Animation_Pygame_Geometry_Position - Fatal编程技术网

Python 如何获得李萨如曲线表中所有曲线的X和Y位置?

Python 如何获得李萨如曲线表中所有曲线的X和Y位置?,python,animation,pygame,geometry,position,Python,Animation,Pygame,Geometry,Position,在观看了一些编码训练之后,我试图用python制作一个李萨如曲线表。我成功地画出了圆、环绕的点和线。 然而,我似乎无法绘制实际的曲线。我创建了一个名为positions的列表,它从行和列中获取x_uu和y_uu值,但动画只绘制右下角的圆。我想不出我的错误。 我在GitHub上的完整代码: 您必须将在每个帧中计算的位置(_x,_y)的排列添加到容器位置,而不是每帧一个位置 将坐标转换为整数值,并仅向容器添加唯一坐标。注意,像素的坐标是整数。画一个点两次,并不能使它“更白” 使用比列表更大的比率来存

在观看了一些编码训练之后,我试图用python制作一个李萨如曲线表。我成功地画出了圆、环绕的点和线。 然而,我似乎无法绘制实际的曲线。我创建了一个名为positions的列表,它从行和列中获取x_uu和y_uu值,但动画只绘制右下角的圆。我想不出我的错误。 我在GitHub上的完整代码:


您必须将在每个帧中计算的位置
(_x,_y)
的排列添加到容器
位置
,而不是每帧一个位置

将坐标转换为整数值,并仅向容器添加唯一坐标。注意,像素的坐标是整数。画一个点两次,并不能使它“更白”

使用比列表更大的比率来存储唯一的帖子

position=set()
当_正在运行时:
# [...]
lx_ux=[]
对于范围内的列(列):
# [...]
#添加x
lx_u2;.append(int(圆形(cx+x)))
ly_uux=[]
对于范围内的行(行):
# [...]
#添加y
追加(整数(四舍五入(cy+y)))
#将值添加到
位置。更新([(x_uux,y_ux)表示x_x,y_ux表示y_uy])
对于已就位的pos:
pygame.draw.circle(窗口,(255,255,255),位置1)


但是,通过将曲线写入曲面而不是将其存储在一个集合中,可以获得最佳性能改进

创建对象的栅格:

surf=pygame.Surface((瓷砖大小,瓷砖大小))
grid=[[surf.copy()表示范围内的i(列)]表示范围内的j(行)]
在每个帧中的每个曲面上绘制一个点:

lx中的列cx、x、y的
:
对于ly中的行、cy、x_uuy和y:
网格[列][行]。将“\u”设置为((x+平铺大小//2,y+平铺大小//2),(255,255,255))
在每个帧中绘制曲面栅格:

对于枚举(网格)中的列、网格和行:
对于行,枚举中的单元格(网格行):
cx=(列+1)*平铺尺寸
cy=(行+1)*瓷砖尺寸
窗口。blit(单元冲浪,(cx,cy))
最简单的例子:

另见

导入数学
导入pygame
pygame.init()
window=pygame.display.set_模式((500500))
clock=pygame.time.clock()
角度=0
tile\u size=window.get\u width()//10
columns=window.get\u width()//平铺大小-1
rows=window.get\u height()//平铺大小-1
半径=(瓷砖大小-10)//2
surf=pygame.Surface((瓷砖大小,瓷砖大小))
表面填充((32,0,32))
grid=[[surf.copy()表示范围内的i(列)]表示范围内的j(行)]
运行=真
运行时:
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
运行=错误
lx=[(c-1,c*平铺尺寸+平铺尺寸//2,圆(半径*数学cos(角度*c)),圆(半径*数学sin(角度*c)))范围内的c(1,列+1)]
ly=[(r-1,r*tile\u size+tile\u size//2,范围(1,行+1)内r的圆形(半径*数学cos(角度*r)),圆形(半径*数学sin(角度*r)))
角度+=0.01
对于lx中的列cx、x、y_u:
对于ly中的行、cy、x_uuy和y:
网格[列][行]。将“\u”设置为((x+平铺大小//2,y+平铺大小//2),(255,255,255))
窗口填充((0,0,0))
对于列,枚举(网格)中的网格\行:
对于行,枚举中的单元格(网格行):
cx=(列+1)*平铺尺寸
cy=(行+1)*瓷砖尺寸
窗口。blit(单元冲浪,(cx,cy))
cy=瓷砖尺寸//2
对于lx中的列cx、x、y:
pygame.draw.circle(窗口,(127,127,127),(cx,cy),半径,1)
pygame.draw.circle(窗口,(127127127),(x+cx,y+cy),5)
pygame.draw.line(window,(127127127),(cx+x,cy+y),(cx+x,window.get_height()),1)
cx=瓷砖大小//2
对于ly中的行、cy、x、y:
pygame.draw.circle(窗口,(127,127,127),(cx,cy),半径,1)
pygame.draw.circle(窗口,(127127127),(x+cx,y+cy),5)
pygame.draw.line(window,(127127127),(cx+x,cy+y),(window.get_width(),cy+y),1)
对于位置in[(x[1]+x[2],y[1]+y[3]),对于x in lx,对于y in ly]:
pygame.draw.circle(窗口,(255,0,0),位置3)
pygame.display.flip()
pygame.quit()
退出()
    width, height = 800, 800
name_of_window = ""
pygame.init()
window = pygame.display.set_mode((width, height))
pygame.display.set_caption(name_of_window)
clock = pygame.time.Clock()
angle = 1
circle_diameter = int(width / 10)
columns = int(width / circle_diameter) - 1
rows = int(height / circle_diameter) - 1
circle_diameter_draw = circle_diameter - 10
r = circle_diameter_draw / 2
position = []

is_running = True

while is_running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False

    window.fill((0, 0, 0))

    for column in range(columns):
        # the circle x location
        cx = circle_diameter + column * circle_diameter + int(circle_diameter_draw / 2)
        # the circle y location
        cy = circle_diameter_draw / 2 + circle_diameter_draw / 10
        # the dot x location
        x = r * math.cos(angle * (column + 1))
        # the dot y location
        y = r * math.sin(angle * (column + 1))
        # draws circle
        pygame.draw.circle(window, (255, 255, 255), [cx, int(cy)], int(r), 1)
        # draws dot
        pygame.draw.circle(window, (255, 255, 255), [int(x + cx), int(y + cy)], 5)
        # draws line from dot pos
        pygame.draw.line(window, (255, 255, 255), (cx + x, cy + y), (cx + x, height), 1)
        angle += 0.001
        # adds the x
        x_ = cx + x

    for row in range(rows):
        # the circle y location
        cy = circle_diameter + row * circle_diameter + int(circle_diameter_draw / 2)
        # the circle x location
        cx = circle_diameter_draw / 2 + circle_diameter_draw / 10
        # the dot x location
        x = r * math.cos(angle * (row + 1))
        # the dot y location
        y = r * math.sin(angle * (row + 1))
        # draws circle
        pygame.draw.circle(window, (255, 255, 255), [int(cx), int(cy)], int(r), 1)
        # draws dot
        pygame.draw.circle(window, (255, 255, 255), [int(x + cx), int(y + cy)], 5)
        # draws line from dot pos
        pygame.draw.line(window, (255, 255, 255), (cx + x, cy + y), (width, cy + y), 1)
        angle += 0.001
        y_ = cy + y

    # adds the values to the
    position.append([x_, y_])

    for i in range(len(position)):
        pygame.draw.circle(window, (255, 255, 255), (int(position[i][0]), int(position[i][1])), 1)