Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.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 获取pygame窗口但没有输出_Python_Algorithm_Pygame_Robotics - Fatal编程技术网

Python 获取pygame窗口但没有输出

Python 获取pygame窗口但没有输出,python,algorithm,pygame,robotics,Python,Algorithm,Pygame,Robotics,我试图用python编写一个RRT路径规划算法。虽然代码执行时没有错误,但结果是一个没有输出的普通pygame窗口 import sys, random, math, pygame from math import sqrt,cos,sin,atan2 from pygame.locals import * pygame.init() class RRT(object): X_dimension = 0 Y_dimension = 0 Window_size = 0 EPS

我试图用python编写一个RRT路径规划算法。虽然代码执行时没有错误,但结果是一个没有输出的普通pygame窗口

import sys, random, math, pygame
from math import sqrt,cos,sin,atan2
from pygame.locals import *
pygame.init()

class RRT(object):

X_dimension = 0
Y_dimension = 0
Window_size = 0
EPS         = 0
Max_nodes   = 0 
nodes       = list()
K_ESCAPE    = True
KEYUP       = True
QUIT        = True

def __init__(self,x,y):
    self.x = [10,20,40,50,60,0]
    self.y = [15,30,0,54,75,68]  

#parameters
    self.X_dimension = 1280                                  #length of the window
    self.Y_dimension = 1280                                  #breadth of the window
    self.Window_size = [self.X_dimension, self.Y_dimension]  #Window size
    self.EPS         =  7000                                 #EPSILON or Incremental Distance 
    self.Max_nodes   = 100                                   #maximum number of nodes
    self.QUIT        = QUIT
    self.KEYUP       = KEYUP
    self.K_ESCAPE    = K_ESCAPE


#function for calculating euclidean distance
def Calculate_Distance(self):
    x= self.x
    y=self.y

    return sqrt((x[5]-y[5])*(x[5]-y[5])+(x[4]-y[4])*(x[4]-y[4]))

#Function for calculating all the possible points
def Initiate_Sampling(self):

    self.EPS = 7000 
    y = self.y
    x = self.x

    if self.Calculate_Distance() < 70:
        return y, x
    else:
        theta = atan2(y[1]-x[1], y[0]-x[0])
        return x[0] + self.EPS*cos(theta), x[1] + self.EPS*sin(theta)

#Function for displaying the output
def Start_The_Game(self):

    pygame.init()

    screen = pygame.display.set_mode(self.Window_size)
    caption = pygame.display.set_caption("performing RRT")
    white = 255, 240, 200
    black = 20, 20, 40
    screen.fill(black) 

    return('GAME BEGINS')   


#Main Function
def Node_Generation(self, nodes=True):
    self.nodes      = nodes
    self.QUIT       = QUIT
    self.KEYUP      = KEYUP
    self.K_ESCAPE   = K_ESCAPE

    nodes = [(5.0,5.25),(7.0,7.25),(8,8.25)]

    #nodes.append(X_dimension/2.0, Y_dimension/2.0)        
    nodes.append((0.0,0.0))

for i in range(Max_nodes):
    rand = random.random()*640.0, random.random()*480.0
    nn = self.nodes[0]

for p in nodes:
    if self.Calculate_Distance(p,rand) < self.Calculate_Distance(nn,rand):
        nn = p
        newnode = step_from_to(nn,rand)
        nodes.append(newnode)
        pygame.draw.line(screen,white,nn,newnode)
        pygame.display.update()
        #print (i, "  ", nodes)

for event in pygame.event.get():
    if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE):
        pygame.quit()
        sys.exit("GAME OVER")



path = RRT(0,0)#write the starting nodes
path.Calculate_Distance()
path.Initiate_Sampling()
path.Start_The_Game()
path.Node_Generation()    
导入系统、随机、数学、pygame
从数学导入sqrt、cos、sin、atan2
从pygame.locals导入*
pygame.init()
类别RRT(对象):
X_维数=0
Y_维度=0
窗口大小=0
每股收益=0
最大节点数=0
节点=列表()
K_ESCAPE=True
KEYUP=True
退出=真
定义初始化(self,x,y):
self.x=[10,20,40,50,60,0]
self.y=[15,30,0,54,75,68]
#参数
self.X#u尺寸=1280#窗口长度
self.Y#u尺寸=1280#窗宽
self.Window_size=[self.X_维度,self.Y_维度]#窗口大小
self.EPS=7000ε或增量距离
self.Max_节点=100#最大节点数
self.QUIT=退出
self.KEYUP=KEYUP
self.K_ESCAPE=K_ESCAPE
#计算欧氏距离的函数
def计算_距离(自身):
x=自我。x
y=self.y
返回sqrt((x[5]-y[5])*(x[5]-y[5])+(x[4]-y[4])*(x[4]-y[4]))
#用于计算所有可能点的函数
def启动_采样(自):
self.EPS=7000
y=self.y
x=自我。x
如果自行计算_距离()<70:
返回y,x
其他:
θ=atan2(y[1]-x[1],y[0]-x[0])
返回x[0]+self.EPS*cos(θ),x[1]+self.EPS*sin(θ)
#用于显示输出的函数
def启动游戏(自我):
pygame.init()
screen=pygame.display.set_模式(自身窗口大小)
caption=pygame.display.set_caption(“正在执行RRT”)
白色=255、240、200
黑色=20,20,40
屏幕填充(黑色)
return('游戏开始')
#主要功能
def Node_生成(self,nodes=True):
self.nodes=节点
self.QUIT=退出
self.KEYUP=KEYUP
self.K_ESCAPE=K_ESCAPE
节点=[(5.0,5.25),(7.0,7.25),(8,8.25)]
#nodes.append(X\u维度/2.0,Y\u维度/2.0)
nodes.append((0.0,0.0))
对于范围内的i(最大节点数):
rand=random.random()*640.0,random.random()*480.0
nn=自身节点[0]
对于节点中的p:
如果self.Calculate_Distance(p,rand)

上面的结果是一个普通的pygame窗口,但没有输出。

您应该首先修复代码的缩进。还有,为什么节点有时是bool,有时是列表?为什么Calculate_Distance有时用两个参数调用,有时不用参数调用?我将修复缩进。该节点也是一个列表对象。除了缩进之外,还有任何逻辑或语法错误吗?删除了无关的文本。您应该首先修复代码的缩进。还有,为什么节点有时是bool,有时是列表?为什么Calculate_Distance有时用两个参数调用,有时不用参数调用?我将修复缩进。该节点也是一个列表对象。除了缩进之外,是否有任何逻辑或语法错误?删除无关文本。