当前位置: 首页>>代码示例>>Python>>正文


Python Grid.draw方法代码示例

本文整理汇总了Python中Grid.Grid.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Grid.draw方法的具体用法?Python Grid.draw怎么用?Python Grid.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grid.Grid的用法示例。


在下文中一共展示了Grid.draw方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Application

# 需要导入模块: from Grid import Grid [as 别名]
# 或者: from Grid.Grid import draw [as 别名]
class Application(Frame):
    
    def __init__(self, master):
        Frame.__init__(self, master)
        self.master = master
        self.running = True
        self.grid()
        self.create_widgets(master)
        self.grid = Grid(self.canvas, 40)
        self.val = 0
        self.draw_every_steps = 1
        self.draw_step = 0
        master.after(100, self.animation)

    def create_widgets(self, master):
        self.btn_start = Button(self, text = "Start")
        self.btn_start["text"] = "Start"
        self.btn_start["command"] = self.start
        self.btn_start.grid()
        
        self.btn_stop = Button(self)
        self.btn_stop["text"] = "Stop"
        self.btn_stop["command"] = self.stop
        self.btn_stop.grid()
        
        self.btn_stop = Button(self)
        self.btn_stop["text"] = "Restart"
        self.btn_stop["command"] = self.restart
        self.btn_stop.grid()
        
        self.canvas = Canvas(master, height = 400, width = 500, bg="white")
        self.canvas.pack()
        self.canvas.grid()
        
    def start(self):
        self.running = True
        
    def stop(self):
        self.running = False
        
    def restart(self):
        self.grid.restart()
        self.running = True
        
    def animation(self):
        if self.running == True:
            self.grid.step_all()
            self.draw_step += 1
            if(self.draw_step >= self.draw_every_steps):
                self.draw_step = 0
                self.grid.draw()
        self.master.after(1, self.animation)
            
开发者ID:radulacatus,项目名称:langtonsant,代码行数:54,代码来源:Application.py

示例2:

# 需要导入模块: from Grid import Grid [as 别名]
# 或者: from Grid.Grid import draw [as 别名]
                        screen = pygame.display.set_mode(screen_size, RESIZABLE)
                    else:
                        last_size = screen_size
                        screen_size = (screen_info.current_w, screen_info.current_h)
                        screen = pygame.display.set_mode(screen_size, FULLSCREEN)
                    fullscreen = not fullscreen
                    root.resize(width=screen_size[0], height=screen_size[1])
                    root.update_screen(screen)

            else:
                button.update(event)
                widget1.update(event)
                widget2.update(event)
                widget3.update(event)
                widget4.update(event)
                """
                button1.update(event)
                button2.update(event)
                button3.update(event)
                button4.update(event)
                button5.update(event)
                button6.update(event)
                button7.update(event)
                button8.update(event)
                button9.update(event)
                button10.update(event)
                """
        screen.fill((255, 255, 255))
        root.draw()
        pygame.display.update()
开发者ID:lumidify,项目名称:BobGUI,代码行数:32,代码来源:gridtest.py

示例3: __init__

# 需要导入模块: from Grid import Grid [as 别名]
# 或者: from Grid.Grid import draw [as 别名]
class Screen:

    def __init__(self, window, scene, menu):
        self.u = (2./3, -1./3.5)
        self.v = (-2./3, -1./3.5)
        self.w = (0, -15)

        self._window = window
        self._scene = scene
        self._hud = HUD(self)
        self._grid = Grid(self)
        self._players = pygame.sprite.Group()
        player1 = PlayerSprite(scene.getPlayer(0), menu)
        self._playerG1 = pygame.sprite.Group()
        self._playerG1.add(player1)
        player2 = PlayerSprite(scene.getPlayer(1), menu)
        self._playerG2 = pygame.sprite.Group()
        self._playerG2.add(player2)
        self._players.add(player1)
        self._players.add(player2)
        self._shadows = pygame.sprite.Group()
        self._shadows.add(ShadowSprite(scene.getPlayer(0)))
        self._shadows.add(ShadowSprite(scene.getPlayer(1)))
        self._weaponGroup = pygame.sprite.Group()
        self._weaponList = [WeaponSprite(scene.getPlayer(0).weapon()),
                WeaponSprite(scene.getPlayer(1).weapon())]

    def calcPos(self, vector):
        return (
            vector[0]*self.u[0] + vector[1]*self.v[0] + vector[2]*self.w[0] +
                self._window.get_width()/2,
            vector[0]*self.u[1] + vector[1]*self.v[1] + vector[2]*self.w[1] +
                self._window.get_height()/2
        )

    def calcPosZ(self, vector):
        return vector[0] + vector[1]

    def calcVec(self, vector):
        return (
            vector[0]*self.u[0] + vector[1]*self.v[0],
            vector[0]*self.u[1] + vector[1]*self.v[1]
        )

    def draw(self):
        self._players.update(self._scene, self)
        self._shadows.update(self._scene, self)
        self._window.fill(pygame.Color(255,255,255))    

        for w in self._weaponList:
            if w.weapon().active():
                self._weaponGroup.add(w)
            else:
                self._weaponGroup.remove(w)

        self._weaponGroup.update()

        self._grid.draw()
        self._shadows.draw(self._window)

        if self.calcPosZ(self._scene.getPlayer(0).position()) > self.calcPosZ(self._scene.getPlayer(1).position()):
            self._playerG1.draw(self._window);
            self._playerG2.draw(self._window);
        else:
            self._playerG2.draw(self._window);
            self._playerG1.draw(self._window);

        self._weaponGroup.draw(self._window)

        self._grid.afterDraw()

        self._hud.draw()

        pygame.display.flip()
开发者ID:ClubEngine,项目名称:GameJam4,代码行数:76,代码来源:Screen.py

示例4: Grid

# 需要导入模块: from Grid import Grid [as 别名]
# 或者: from Grid.Grid import draw [as 别名]
import pygame
import sys
from pygame.locals import *
from Grid import Grid


window = pygame.display.set_mode((1024,768))
pygame.display.set_caption('Tile Game')
screen = pygame.display.get_surface()
pygame.key.set_repeat(1,50)


grid = Grid(100, 100, 500, 500, 0.90)

while True:
    screen.fill((1,1,1,0))
    grid.draw(pygame, screen)
    pygame.display.flip()

    for e in pygame.event.get():
        if e.type == QUIT:
            sys.exit(0)

        if e.type == MOUSEBUTTONDOWN:
            if e.button == 1:
                grid.click(e.pos)
开发者ID:maddenpj,项目名称:aTile,代码行数:28,代码来源:game.py

示例5: App

# 需要导入模块: from Grid import Grid [as 别名]
# 或者: from Grid.Grid import draw [as 别名]
class App(object):
    """docstring for App"""
    def __init__(self):
        super(App, self).__init__()
        
        self.setup_pygame()

        self.events = Events()

        self.lane = Lane(self.events)
        self.lane.add_support_point(100,100)
        self.lane.add_support_point(200,100)
        self.lane.add_support_point(200,200)
        self.lane.add_support_point(100,200)

        self.cars = []
        for k in range(4):
            self.cars.append(Car(x=150+k*5,y=100,theta=np.random.randint(0,360),speed=np.random.randint(45,180)))
        # self.cars.append(Car(x=250,y=100,theta=-45,speed=2*90))
        self.action = None
        self.human = HumanController()
        self.heuristic = Heuristic(self.lane)
        Node.heuristic = self.heuristic
        self.onestep = OneStepLookaheadController(self.cars,self.lane,self.heuristic)
        self.nstep = NStepLookaheadController(self.cars,self.lane, self.heuristic, 2)
        self.bestfirst = BestFirstController(self.cars,self.lane, self.heuristic)
        self.controller = self.bestfirst


        # self.window = Window(self.screen, self.events, 300, 200, "caption")

        self.grid = Grid(50,50,*self.size)
        self.last_distance_grid_update = time() - 10
        self.update_distance_grid()

        self.done = False

        self.register_events()
        self.spin()

    def setup_pygame(self):
        pygame.init()
         
        # Set the width and height of the screen [width, height]
        self.size = (700, 500)
        self.screen = pygame.display.set_mode(self.size)

        self.font = pygame.font.SysFont("arial",10)
         
        pygame.display.set_caption("My Game")

    def draw_string(self,string,x,y,color=Draw.BLACK):
        Draw.draw_string(self.screen,self.font,string,x,y,color)


    def draw(self):
        self.grid.draw(self.screen)

        self.lane.draw(self.screen)

        # Draw car
        for car in self.cars:
            if self.controller is not None:
                if hasattr(self.controller,"action"):
                    car.draw(self.screen, self.controller.action)
                self.controller.draw(self.screen, car)

            else:
                car.draw(self.screen)


    def input(self):
        # get mouse info
        cursor = pygame.mouse.get_pos()
        (left_button, middle_button, right_button) = pygame.mouse.get_pressed() 
        

        keys = pygame.key.get_pressed()
        if self.lane.selected is not None:
            if keys[pygame.K_DELETE]:
                self.lane.remove_support_point(self.lane.selected)
                self.lane.selected = None
                self.update_distance_grid()

 
        if keys[pygame.K_SPACE]:
            for car in self.cars:
                # save original speed
                if not hasattr(car,"speed_on"):
                    car.speed_on = car.speed
                # toggle speed
                car.speed = car.speed_on - car.speed
        
        if keys[pygame.K_RETURN]:
            self.controller = self.human if self.controller != self.human else self.onestep

    def update_distance_grid(self):
        # return
        if time() - self.last_distance_grid_update > 1 / 5:
            self.last_distance_grid_update = time()        
#.........这里部分代码省略.........
开发者ID:xaedes,项目名称:MCTSCarControl,代码行数:103,代码来源:script.py


注:本文中的Grid.Grid.draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。