當前位置: 首頁>>代碼示例>>Python>>正文


Python AstroPi.clear方法代碼示例

本文整理匯總了Python中astro_pi.AstroPi.clear方法的典型用法代碼示例。如果您正苦於以下問題:Python AstroPi.clear方法的具體用法?Python AstroPi.clear怎麽用?Python AstroPi.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在astro_pi.AstroPi的用法示例。


在下文中一共展示了AstroPi.clear方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: print

# 需要導入模塊: from astro_pi import AstroPi [as 別名]
# 或者: from astro_pi.AstroPi import clear [as 別名]
#!/usr/bin/python
import os
import time
import pygame  # See http://www.pygame.org/docs

print("Press Escape to quit")
time.sleep(1)

from pygame.locals import *
from astro_pi import AstroPi

pygame.init()
pygame.display.set_mode((640, 480))

ap = AstroPi()
ap.clear()  # Blank the LED matrix

# 0, 0 = Top left
# 7, 7 = Bottom right
UP_PIXELS = [[3, 0], [4, 0]]
DOWN_PIXELS = [[3, 7], [4, 7]]
LEFT_PIXELS = [[0, 3], [0, 4]]
RIGHT_PIXELS = [[7, 3], [7, 4]]
CENTRE_PIXELS = [[3, 3], [4, 3], [3, 4], [4, 4]]


def set_pixels(pixels, col):
    for p in pixels:
        ap.set_pixel(p[0], p[1], col[0], col[1], col[2])

開發者ID:New380,項目名稱:astro-pi-hat,代碼行數:31,代碼來源:pygame_joystick.py

示例2: AstroPi

# 需要導入模塊: from astro_pi import AstroPi [as 別名]
# 或者: from astro_pi.AstroPi import clear [as 別名]
#05/06/15
import pygame, random, datetime, math, os, time
from pygame.locals import *
from astro_pi import AstroPi
ap = AstroPi()


ap.clear()

pygame.init()
pygame.display.set_mode((640, 480))


#Handle the joystick input
def handle_event(event):
    if event.key == pygame.K_DOWN:
        return "DOWN"
        
    elif event.key == pygame.K_UP:
        return "UP"

    elif event.key == pygame.K_LEFT:
        return "LEFT"

    elif event.key == pygame.K_RIGHT:
        return "RIGHT"

    elif event.key == pygame.K_RETURN:
        return "RETURN"

開發者ID:swooningfish,項目名稱:reaction-games,代碼行數:31,代碼來源:Main.py

示例3: AstroPi

# 需要導入模塊: from astro_pi import AstroPi [as 別名]
# 或者: from astro_pi.AstroPi import clear [as 別名]
#!/usr/bin/python
from astro_pi import AstroPi
import time

ap = AstroPi()
temp = ap.get_temperature()
humidity = ap.get_humidity()
pressure = ap.get_pressure()


print("Temperature: %s C" % temp)               # Show temp on console
print("Humidity: %s %%rH" % humidity)        # Show humidity on console
print("Pressure: %s Millibars" % pressure)    # Show pressure on console

ap.set_rotation(180)        # Set LED matrix to scroll from right to left
              
ap.show_message("Temperature: %.2f C" % temp, scroll_speed=0.05, text_colour=[0, 255, 0])

time.sleep(1)           # Wait 1 second

ap.show_message("Humidity: %.2f %%rH" % humidity, scroll_speed=0.05, text_colour=[255, 0, 0]) 

time.sleep(1)      # Wait 1 second

ap.show_message("Pressure: %.2f Millibars" % humidity, scroll_speed=0.05, text_colour=[0, 0, 255])

ap.clear()      # Clear LED matrix
開發者ID:ontheplains,項目名稱:Raspberry-Pi-Code,代碼行數:29,代碼來源:astroPi.py

示例4: next_colour

# 需要導入模塊: from astro_pi import AstroPi [as 別名]
# 或者: from astro_pi.AstroPi import clear [as 別名]
msleep = lambda x: time.sleep(x / 1000.0)


def next_colour():
    global r
    global g
    global b

    if (r == 255 and g < 255 and b == 0):
        g += 1

    if (g == 255 and r > 0 and b == 0):
        r -= 1

    if (g == 255 and b < 255 and r == 0):
        b += 1

    if (b == 255 and g > 0 and r == 0):
        g -= 1

    if (b == 255 and r < 255 and g == 0):
        r += 1

    if (r == 255 and b > 0 and g == 0):
        b -= 1

while True:
    ap.clear([r, g, b])
    msleep(2)
    next_colour()
開發者ID:New380,項目名稱:astro-pi-hat,代碼行數:32,代碼來源:colour_cycle.py

示例5: AstroPiSnake

# 需要導入模塊: from astro_pi import AstroPi [as 別名]
# 或者: from astro_pi.AstroPi import clear [as 別名]
class AstroPiSnake():
    UP = 0
    DOWN = 1
    RIGHT = 2
    LEFT = 3

    BACKCOL = [0, 0, 0]
    SNAKECOL = [0, 255, 0]
    APPLECOL = [255, 0, 0]
    
    def __init__(self):
        pygame.init()
        pygame.display.set_mode((640, 480))
        
        self.ap = AstroPi()
        
    def startGame(self):
        self.ap.clear(self.BACKCOL)
        self.direction = self.UP
        self.length = 3
        self.tail = []
        self.tail.insert(0, [4, 4])
        self.createApple()
        self.score = 0
        
        playing = True
        while(playing):
            sleep(0.5)
            for event in pygame.event.get():
                if event.type == KEYDOWN:
                    self._handle_event(event)
            playing = self.move()

        self.ap.clear()

    def _handle_event(self, event):
        if event.key == pygame.K_DOWN:
            self.down()
        elif event.key == pygame.K_UP:
            self.up()
        elif event.key == pygame.K_LEFT:
            self.left()
        elif event.key == pygame.K_RIGHT:
            self.right()
        
    def createApple(self):
        badApple = True
        #try and fnd a location for the apple
        while(badApple):
            x = randint(0, 7)
            y = randint(0, 7)
            badApple = self.checkCollision(x, y)
        self.apple = [x, y]
        self.ap.set_pixel(x, y, self.APPLECOL)

    def checkCollision(self, x, y):
        #is this outside the screen
        if x > 7 or x < 0 or y > 7 or y < 0:
            return True
        else:
            #or in the snakes tail
            for segment in self.tail:
                if segment[0] == x and segment[1] == y:
                    return True
            else:
                return False

    def addSegment(self, x, y):
        #create the new segment of the snake
        self.ap.set_pixel(x, y, self.SNAKECOL)
        self.tail.insert(0, [x, y])
        
        #do I need to clear a segment
        if len(self.tail) > self.length:
            lastSegment = self.tail[-1]
            self.ap.set_pixel(lastSegment[0], lastSegment[1], self.BACKCOL)
            self.tail.pop()
        
    def move(self):
        #work out where the new segment of the snake will be
        newSegment = [self.tail[0][0], self.tail[0][1]]
        if self.direction == self.UP:
            newSegment[1] -= 1
        elif self.direction == self.DOWN:
            newSegment[1] += 1
        elif self.direction == self.LEFT:
            newSegment[0] -= 1
        elif self.direction == self.RIGHT:
            newSegment[0] += 1

        if self.checkCollision(newSegment[0], newSegment[1]):
            #game over
            snakehead = self.tail[0]
            for flashHead in range(0,5):
                self.ap.set_pixel(snakehead[0], snakehead[1], self.SNAKECOL)
                sleep(0.2)
                self.ap.set_pixel(snakehead[0], snakehead[1], self.BACKCOL)
                sleep(0.2)
            self.ap.show_message("Score = {}".format(self.score), text_colour = self.APPLECOL)
            
#.........這裏部分代碼省略.........
開發者ID:martinohanlon,項目名稱:AstroPiSnake,代碼行數:103,代碼來源:astropisnake.py


注:本文中的astro_pi.AstroPi.clear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。