本文整理汇总了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])
示例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"
示例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
示例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()
示例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)
#.........这里部分代码省略.........