本文整理汇总了Python中astro_pi.AstroPi.set_pixel方法的典型用法代码示例。如果您正苦于以下问题:Python AstroPi.set_pixel方法的具体用法?Python AstroPi.set_pixel怎么用?Python AstroPi.set_pixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astro_pi.AstroPi
的用法示例。
在下文中一共展示了AstroPi.set_pixel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AstroPi
# 需要导入模块: from astro_pi import AstroPi [as 别名]
# 或者: from astro_pi.AstroPi import set_pixel [as 别名]
from astro_pi import AstroPi
ap = AstroPi()
ap.set_pixel(2,2,[0,0,255])
ap.set_pixel(4,2,[0,0,255])
ap.set_pixel(3,4,[100,0,0])
ap.set_pixel(1,5,[255,0,0])
ap.set_pixel(2,6,[255,0,0])
ap.set_pixel(3,6,[255,0,0])
ap.set_pixel(4,6,[255,0,0])
ap.set_pixel(5,5,[255,0,0])
示例2: AstroPi
# 需要导入模块: from astro_pi import AstroPi [as 别名]
# 或者: from astro_pi.AstroPi import set_pixel [as 别名]
#testing the led matrix
from astro_pi import AstroPi
ap = AstroPi()
ap.clear()
#ap.show_message("Hello Space")
ap.set_pixel(0, 0, 255, 0, 0)
ap.set_pixel(7, 7, 255, 255, 255)
#ap.set_pixel(7, 7, 0, 0, 0)
ap.clear()
#ap.clear([0,0,255])
示例3: move_ball
# 需要导入模块: from astro_pi import AstroPi [as 别名]
# 或者: from astro_pi.AstroPi import set_pixel [as 别名]
#When it has broken from the loop it moves the ball
move_ball()
#Adds a move
move += 1
#Return these variables because I didn't get my head around globalling at the
#Start, but it no difference to performance
return move, ballMoveTime
#Clears the board incase there was something on it before
ap.clear()
#Sort and show bat straight away
batMiddle = 3
ap.set_pixel(0,batMiddle, [100,100,100])
#Choose starting location of ball
randomRow = random.randint(2,4)
ballLocation = [3,randomRow]
#Sets the time interval the ball moves
ballMoveTime = 0.4
#Initialises the teleports
teleportLocations = [[],[]]
#Starts the angle going towards the side without bat as it's the nice thing
#to do
angle = 180
示例4: AstroPiSnake
# 需要导入模块: from astro_pi import AstroPi [as 别名]
# 或者: from astro_pi.AstroPi import set_pixel [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)
#.........这里部分代码省略.........
示例5: make_point
# 需要导入模块: from astro_pi import AstroPi [as 别名]
# 或者: from astro_pi.AstroPi import set_pixel [as 别名]
if(x > 7) : x = 7
if(y < 0) : y = 0
if(y > 7) : y = 7
p = ap.get_pixel(x,y)
#debugging info as setting 0, 255, 255 did not work
#print p
'
#check if the point has been collected
if(p[0] == pr and p[1] == pg and p[2] == pb):
#its a point!
points = points + 1
speed = speed + 1 # increase speed
make_point() # make another point
ap.set_pixel(x,y,r,g,b)
time.sleep( float(1)/speed)
#check for events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
#change the co-efficient depending on the key pressed , or exit the game
if event.type==KEYDOWN:
if event.key==K_ESCAPE:
running = False
if event.key==K_LEFT:
leftco = -1
upco = 0
elif event.key==K_RIGHT:
leftco = 1
upco = 0
示例6: AstroPi
# 需要导入模块: from astro_pi import AstroPi [as 别名]
# 或者: from astro_pi.AstroPi import set_pixel [as 别名]
# The calibration program will produce the file RTIMULib.ini
# Copy it into the same folder as your Python code
led_loop = [4, 5, 6, 7, 15, 23, 31, 39, 47, 55, 63, 62, 61, 60, 59, 58, 57, 56, 48, 40, 32, 24, 16, 8, 0, 1, 2, 3]
ap = AstroPi()
ap.set_rotation(0)
ap.clear()
prev_x = 0
prev_y = 0
led_degree_ratio = len(led_loop) / 360.0
while True:
dir = ap.get_compass()
dir_inverted = 360 - dir # So LED appears to follow North
led_index = int(led_degree_ratio * dir_inverted)
offset = led_loop[led_index]
y = offset // 8 # row
x = offset % 8 # column
if x != prev_x or y != prev_y:
ap.set_pixel(prev_x, prev_y, 0, 0, 0)
ap.set_pixel(x, y, 0, 0, 255)
prev_x = x
prev_y = y
示例7:
# 需要导入模块: from astro_pi import AstroPi [as 别名]
# 或者: from astro_pi.AstroPi import set_pixel [as 别名]
snakeColour = [0,100,0]
snakeBodyLength = 1
snakeBodyCoords = [[0,0]]
applesEaten = 0
#State of death flashing initialised
state = True
#Create a colour for reference, unecessary
black = [0,0,0]
#Starts the snake going right
previous = "RIGHT"
#Set the first snakes colour and locaiton
ap.set_pixel(0,0,snakeColour)
#Create an apple to start
create_apple()
#Tell the loop the snake is alive
alive = True
startTime = datetime.datetime.now()
while alive:
#Move body and store return of it in check variable
check = move_body()
#Tells program if you are dead or alive