本文整理汇总了Python中sense_hat.SenseHat.set_pixel方法的典型用法代码示例。如果您正苦于以下问题:Python SenseHat.set_pixel方法的具体用法?Python SenseHat.set_pixel怎么用?Python SenseHat.set_pixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sense_hat.SenseHat
的用法示例。
在下文中一共展示了SenseHat.set_pixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gyroGame
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
def gyroGame(maxDegs):
sense = SenseHat()
while 1:
orientation = sense.get_orientation_degrees()
if orientation['pitch'] < maxDegs:
realpitch=orientation['pitch']
else:
realpitch=-1*(360-orientation['pitch'])
if orientation['roll'] < maxDegs:
realroll=orientation['roll']
else:
realroll=-1*(360-orientation['roll'])
x_pos=7-int(round(((maxDegs+realpitch)/(2.0*maxDegs))*8.0,0))
y_pos=int(round(((maxDegs+realroll)/(2.0*maxDegs))*8.0,0))
if x_pos > 7:
x_pos = 7
if x_pos < 0:
x_pos = 0
if y_pos > 7:
y_pos = 7
if y_pos < 0:
y_pos = 0
sense.clear()
if (1 <= x_pos <=6) and (1 <= y_pos <=6):
sense.set_pixel(x_pos,y_pos,0,0,255)
else:
sense.set_pixel(x_pos,y_pos,255,0,0)
示例2: main
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
def main(v):
if v is None:
v=0.5
else:
v=float(v)
sense=SenseHat()
for i in range(8):
for j in range(8):
(h,s,v)=XY_to_HSV(i,j,v)
(r,g,b)=HSV_to_RGB(h,s,v)
#print (i,j,int(r),int(g),int(b),int(h),int(s),int(v))
sense.set_pixel(i,j,int(r),int(g),int(b))
示例3: main
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
def main():
sense = SenseHat()
color = (255, 0, 0)
prev_x = -1
prev_y = -1
while True:
acc = sense.get_accelerometer_raw()
x = round(limit(-10 * acc['x'] + 3))
y = round(limit(-10 * acc['y'] + 3))
if x != prev_x or y != prev_y:
sense.clear()
sense.set_pixel(x, y, *color)
prev_x = x
prev_y = y
time.sleep(0.08)
示例4: main
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
def main():
sense = SenseHat()
"""
sense.show_message("Hello World!!");
sense.set_rotation(180)
sense.show_message("Hello World!!");
"""
sense.flip_v()
list = sense.get_pixels()
#print list
sense.set_pixel(0,0,255,0,0)
sense.clear()
for i in range(0, 5):
sense.show_letter(str(i))
time.sleep(1)
sense.clear()
示例5: SenseHATRenderer
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
class SenseHATRenderer(AbstractRenderer):
def __init__(self):
super(AbstractRenderer,self).__init__()
os.environ['SDL_VIDEODRIVER'] = 'dummy'
pygame.init()
pygame.display.set_mode((1,1))
self.sense = SenseHat()
def render(self, cells):
print "Rendering cells"
for x in range(0, COLS):
for y in range(0, ROWS):
colour = cells[x][y].colour
r = colour[0]
g = colour[1]
b = colour[2]
self.sense.set_pixel(x, y, (r, g, b))
示例6: MyColorDialog
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
class MyColorDialog(QtGui.QColorDialog):
def __init__(self, *args, **kwargs):
super(MyColorDialog, self).__init__(*args, **kwargs)
self.currentColorChanged.connect(self.color_changed)
self.sense = SenseHat()
self.init_lcd()
def color_changed(self, color):
t_RGBA = color.getRgb() # (r, g, b, a)
t_RGB = t_RGBA[0:3]
for x in range(8):
for y in range(8):
self.sense.set_pixel(x, y, *t_RGB)
def init_lcd(self):
for x in range(8):
for y in range(8):
self.sense.set_pixel(x, y, 255, 255, 255)
示例7: __init__
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
class Screen:
def __init__(self):
self.sense = SenseHat()
self.general_level = 0
self.wait_time = 4
self.cur_time = 0
self.clear()
self.balance = 0
def clear(self):
for i in range(SIZE):
for j in range(SIZE):
self.sense.set_pixel(i, j, BLACK)
def clear_col(self, x):
for i in range(0, 7):
self.sense.set_pixel(x, i, BLACK)
def plot_bar(self, x, height, colors=None):
if colors is None:
colors = BAR_COLORS
self.clear_col(x)
for i in range(height):
self.sense.set_pixel(x, 7 - i, colors[7 - i])
def plot_balance(self):
for i in range(SIZE):
self.plot_bar(i, max(1, self.general_level), BAR_COLORS)
def show_amount(self):
self.show_message(str(self.balance), color=list(BAR_COLORS[min(7, 8 - self.general_level)]))
def show_message(self, message, speed=0.1, color=[255, 255, 255]):
self.sense.show_message(message, speed, color)
self.plot_balance()
""" Parses an input in the form:
balance percentage """
def parse_input(self, line):
self.cur_time = 0
# Split balance and percentage.
[self.balance, percent] = [float(x) for x in line.split()]
self.general_level = int(round(min(max(0, percent), 100) / 100.0 * SIZE))
self.draw_check()
def draw_check(self):
types = [BLACK, GREEN]
pixels = [types[CHECK[i / SIZE][i % SIZE]] for i in range(SIZE * SIZE)]
self.sense.set_pixels(pixels)
def no_text(self):
self.cur_time += SLEEP_TIME
if self.cur_time > self.wait_time:
self.cur_time = 0
self.show_amount()
示例8: __init__
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
class MClock:
def __init__(self, radius=200, segments=9, dim=0.8, sleep=5.0):
self.segments = segments
self.image = Image.new('RGB', (RADIUS * 2, RADIUS * 2))
self.img = ImageDraw.Draw(self.image)
self.display_credits = False
self.seconds = True
self.hat = SenseHat()
self.radius = RADIUS
self.dim = dim
self.sleep = sleep
self.recalc(self.radius*2, self.radius*2)
def set_segments(self, *args):
self.segments = max(self.segments, 2)
def toggle_text(self, *args):
self.showtext = not self.showtext
def toggle_seconds(self, *args):
self.seconds = not self.seconds
def show_credits(self, *args):
self.hat.show_message(self.credits)
def quit(self, *args):
self.running = False
credits = ("M Clock 2.0\n"
"by Johnny Gill\n"
"after tkinter by Guido van Rossum\n"
"after a design by Rob Juda")
creditid = None
showtext = False
def recalc(self, width, height):
radius = min(width, height) // 2
self.radius = radius
self.bigsize = radius * .975
self.litsize = radius * .67
def run(self):
self.running = True
while self.running:
t = time.time()
hh, mm, ss = time.localtime(t)[3:6]
self.draw(hh, mm, ss)
self.blit()
time.sleep(self.sleep)
def blit(self):
""" Update the image on the sense hat
Need to downsample from RADIUS to 8
Let's just pick a pixel at random and see how that works
"""
size = self.radius // 4
for x in range(8):
for y in range(8):
xpos = size * x
ypos = size * y
pix = self.pixel_picker(xpos, ypos, size, size)
self.hat.set_pixel(x, y, pix)
def pick_pixel(self, xpos, ypos, xx, yy):
rr = gg =bb = 0
for x in range(xx):
for y in range(yy):
r, g, b = self.image.getpixel((xpos + x, ypos + y))
rr += r
gg += g
bb += b
count = xx * yy
pix = (rr // count, gg // count, bb // count)
return pix
def weighted_pick_pixel(self, xpos, ypos, xx, yy):
rr = gg =bb = 0
#.........这里部分代码省略.........
示例9: randint
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
sense.set_pixels(ironDesign)
if block == lapis:
mc.postToChat("Lapis-Lazuli")
global lights
lights = True
if lights == True:
sense.clear()
x = randint(0, 7)
y = randint(0, 7)
r = randint(0, 255)
g = randint(0, 255)
b = randint(0, 255)
pixel = (r, g, b)
sense.set_pixel(x, y, pixel)
time.sleep(0.01)
if choice == 4:
print("To modify color please check code")
message = raw_input()
#Color Here
sense.show_message(message,text_colour=[0,255,0])
if choice == 5:
humidity = sense.get_humidity()
print("Humidity: %s %%rH" % humidity)
elif choice == 6:
pressure = sense.get_pressure()
print("Pressure: %s Millibars" % pressure)
示例10: SenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
from sense_hat import SenseHat
sense = SenseHat()
sense.clear()
edge = [0, 1, 2, 3, 4, 5, 6, 7, 15, 23, 31, 39, 47, 55, 63, 62, 61, 60, 59, 58, 57, 56, 48, 40, 32, 24, 16, 8]
length = len(edge)
ratio = length / 360.0
while True:
o = sense.get_orientation()
pitch = o["pitch"]
roll = o["roll"]
yaw = o["yaw"]
yaw_list_position = int(yaw * ratio)
yaw_pixel_number = edge[yaw_list_position]
y = yaw_pixel_number // 8
x = yaw_pixel_number % 8
sense.set_pixel(x, y, 255, 255, 255)
示例11: collision
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
speed = -1
else:
speed = +1
def collision(x,gap):
if x == 3:
if y < gap -1 or y > gap +1:
return True
return False
columns = Thread(target=draw_columns)
columns.start()
shake = Thread(target=get_shake)
shake.start()
while not game_over:
sense.set_pixel(3,y,BLUE)
sleep(0.1)
sense.set_pixel(3,y,BLACK)
y += speed
if y > 7:
y = 7
if y < 0:
y = 0
shake.join()
columns.join()
sense.show_message("You Lose", text_colour=(255,0,0))
示例12: fade
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
def fade( pixel ):
new_pixel=[]
for comp in pixel:
if comp>0:
new_pixel.append( comp-1)
else:
new_pixel.append( 0 )
return new_pixel
while True:
rx=random.randint(0,3)
ry=random.randint(0,3)
if random.randint(0,100) < 25:
col=[ random.randint(0,255),
random.randint(0,255),
random.randint(0,255)
]
if sense.get_pixel(rx,ry)==[0,0,0]:
sense.set_pixel(rx, ry, col)
sense.set_pixel(7-rx, ry, col)
sense.set_pixel(7-rx, 7-ry, col)
sense.set_pixel(rx, 7-ry, col)
pixels=sense.get_pixels()
new_pixels=[]
for p in pixels:
new_pixels.append( fade( p ) )
sense.set_pixels( new_pixels )
#sleep(0.1)
示例13: Point
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
class GusanoJ1:
sense = 0
gusano = -1
running = True
white = (0,0,0)
red = (255,0,0)
comida = Point(-1,-1)
def __init__(self):
self.sense = SenseHat()
self.sense.clear()
self.white = (255,255,255)
point1 = Point(0,0)
point2 = Point(0,1)
point3 = Point(0,2)
self.gusano = [point3,point2,point1]
def run(self):
x = 0
y = 2
print self.gusano
self.paintGusano()
stick=SenseStick()
xAnt = x
yAnt = y-1
while self.running:
for event in stick:
#Genera comida
if self.comidaDisponible() == False:
self.comida = self.generaComida()
self.paintComida()
if event.state == stick.STATE_PRESS:
#sense.set_pixel(x, y, 0, 0, 0) # Black 0,0,0 means OFF
update = False
if event.key == stick.KEY_DOWN and y < 7:
y = y + 1
update=True
elif event.key == stick.KEY_UP and y > 0:
y = y - 1
update=True
elif event.key == stick.KEY_RIGHT and x < 7:
x = x + 1
update=True
elif event.key == stick.KEY_LEFT and x > 0:
x = x - 1
update=True
pointTemp = Point(x,y)
print '----- Posicion'
print pointTemp.x
print pointTemp.y
print '-----EndPosicion'
if update == True and self.ifExistPoint(self.gusano,pointTemp) == False:
print 'Evento------'
self.sense.clear()
#Puede Comer?
if pointTemp.x == self.comida.x and pointTemp.y == self.comida.y:
self.gusano = self.addGusano(self.gusano,pointTemp)
self.limpiaComida()
self.sense.clear()
self.paintGusano()
else:
self.gusano = self.updateGusano(self.gusano,pointTemp)
print '____________________________________________'
#self.comiendo(pointTemp)
self.paintGusano()
time.sleep(0.15)
def paintComida(self):
colorComida = (0,254,0)
self.sense.set_pixel(self.comida.x,self.comida.y,colorComida)
def limpiaComida(self):
colorComida = (0,0,0)
self.sense.set_pixel(self.comida.x,self.comida.y,colorComida)
self.comida=Point(-1,-1)
def paintGusano(self):
print 'Imprimiendo gusano %d' %len(self.gusano)
#max = len(self.gusano)-1
for i in range(len(self.gusano)):
color=self.white
point = self.gusano[i]
print '**************'
print point.x
print point.y
print '**************'
if i == 0:
color=self.red
else:
color=self.white
self.sense.set_pixel(point.x,point.y,color)
def ifExistPoint(self,gusano,pointX):
for i in range(len(gusano)):
point = gusano[i]
#.........这里部分代码省略.........
示例14: SenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat 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]
sense = SenseHat()
sense.set_rotation(0)
sense.clear()
prev_x = 0
prev_y = 0
led_degree_ratio = len(led_loop) / 360.0
while True:
dir = sense.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:
sense.set_pixel(prev_x, prev_y, 0, 0, 0)
sense.set_pixel(x, y, 0, 0, 255)
prev_x = x
prev_y = y
示例15: SenseHat
# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixel [as 别名]
import pygame
import time
import math
pygame.init()
pygame.display.set_mode((1, 1))
sense = SenseHat()
white = (255, 255, 255)
green = (0, 255, 0)
yellow = (255, 255, 0)
red = (255, 0, 0)
sense.clear()
sense.set_pixel(5, 5, white)
sense.set_pixel(2, 5, green)
sense.set_pixel(2, 3, yellow)
sense.set_pixel(2, 1, red)
y = 5
while True:
for event in pygame.event.get():
if event.type == KEYDOWN:
sense.set_pixel(5, y, 0, 0, 0)
if event.key == K_DOWN and y < 5:
y += 2
elif event.key == K_UP and y > 1:
y -= 2
sense.set_pixel(5, y, 255, 255, 255)