本文整理汇总了Python中pyb.rng函数的典型用法代码示例。如果您正苦于以下问题:Python rng函数的具体用法?Python rng怎么用?Python rng使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rng函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enterObstacleAvoidanceState
def enterObstacleAvoidanceState(self):
self.log('Entering ObstacleAvoidanceState')
self.ikEngine.travelX = 0
self.turnTimeoutTime = pyb.millis() + FRONT_OBSTACLE_TURN_TIMEOUT
if (self.leftRangeDistance < SIDE_SENSOR_CLEAR_OBSTACLE) & (
self.rightRangeDistance < SIDE_SENSOR_CLEAR_OBSTACLE):
# stuff on both sides, pick a direction at random to turn
if pyb.rng() & 1 == 0:
self.log('Obstacles on both sides, turning right')
self.ikEngine.travelRotZ = -FRONT_OBSTACLE_TURN_SPEED
else:
self.log('Obstacles on both sides, turning left')
self.ikEngine.travelRotZ = FRONT_OBSTACLE_TURN_SPEED
elif self.leftRangeDistance < SIDE_SENSOR_CLEAR_OBSTACLE:
self.log('Obstacle on left side, turning right')
self.ikEngine.travelRotZ = -FRONT_OBSTACLE_TURN_SPEED
elif self.rightRangeDistance < SIDE_SENSOR_CLEAR_OBSTACLE:
self.log('Obstacle on right side, turning left')
self.ikEngine.travelRotZ = FRONT_OBSTACLE_TURN_SPEED
else: # nothing on either side, so pick a side at random
if pyb.rng() & 1 == 0:
self.log('Only front obstacle, turning right')
self.ikEngine.travelRotZ = -FRONT_OBSTACLE_TURN_SPEED
else:
self.log('Only front obstacle, turning left')
self.ikEngine.travelRotZ = FRONT_OBSTACLE_TURN_SPEED
示例2: addbomb
def addbomb( self ) :
x = int(randval(self.ds[0]))
y = int(randval(self.ds[1]))
rad = randval(20) + 5
r = pyb.rng() & 0xFF
g = pyb.rng() & 0xFF
b = pyb.rng() & 0xFF
spd = randval(30.0) + 1.0
clr = self.display.color(r,g,b)
self.bombs.insert(0, bomb((x, y), rad, clr, spd))
示例3: randomise
def randomise(self):
array = ptr8(self._array)
idx = int(self._size_elements)
while idx:
val = int(pyb.rng()) & 0xff
array[idx] = val
idx -= 1
示例4: perk
def perk(self, delay, color, start=None):
#print("perk(%d, %r, %r)" % (delay, color, start))
stoichiometric = self.stoichiometric
i = None
while True:
if i is None:
if start is None:
i = self.top_i
else:
i = start
self.add_color_to(i, color)
yield from self.show_for(delay)
if self.at_mid(i):
new_color = yield from self.react_at(i)
if new_color is None:
return
else:
color = new_color
prev_i = i
i = self.down(i, rng()&1)
self.sub_color_from(prev_i, color)
self.leds_need_sync = True
if i is None:
return color
if self.perk_quit:
break
self.perk_quit -= 1
示例5: seed
def seed():
for x in range(0, width-1):
for y in range(0, height-1):
if pyb.rng() % 2 == 1:
grid[x][y] = 1
else:
grid[x][y] = 0
示例6: tick
def tick():
global wheelColour, ledcount, sequence, ledpin
pin = pyb.Pin(ledpin)
neo = pyb.Neopix(pin)
leds = [0x000000] * ledcount
if (sequence == "rainbow"):
wheelColour = (wheelColour + 8) & 255
for ledNumber in range(0, ledcount):
pos = ((ledNumber*8)+wheelColour)
pos = pos & 255
leds[ledNumber] = Wheel(pos).get_neo()
elif (sequence == "matrix"):
for ledNumber in range(0, ledcount):
led_green = (pyb.rng() & 255)
led_colour = Colour(0, led_green, 0)
if led_green < 230:
led_colour.set_g(int(led_green / 8))
if led_green > 253:
led_colour.set_hex('#ffffff')
leds[ledNumber] = led_colour.get_neo()
elif (sequence == "colour"):
colour = database.database_get("led-colour", "#ffffff")
tmp_colour = Colour()
tmp_colour.set_hex(colour)
leds = [tmp_colour.get_neo()] * ledcount
neo.display(leds)
示例7: list_shuffle
def list_shuffle(list):
for i, item in enumerate(list):
list[i] = (pyb.rng(), item)
list.sort()
for i, item in enumerate(list):
list[i] = item[1]
return list
示例8: testpixel
def testpixel( display ) :
print('testing pixels')
displaysize = display.size()
r = 255
x = -10
g = 0
b = 0
for y in range(-10, displaysize[1] + 10) :
display.pixel((x, y), pyb.TFT.color(r, g, b))
x += 1
g += 2
b += 1
for i in range(100):
x = pyb.rng() % displaysize[0]
y = pyb.rng() % displaysize[1]
display.pixel((x,y), randcolor())
pyb.delay(2000)
示例9: gen_uuid
def gen_uuid():
"""
:return uuid of a message 32 random hexadecimal chars
"""
res = ''
for i in range(0, 32):
res += hex(pyb.rng() % 16)[2:].upper()
return res
示例10: nick_screen
def nick_screen(container_handle):
if not container_handle:
container_handle = ugfx.Container(0, 0, 320, 240)
container_handle.area(0, 0, 320, 240, ugfx.html_color(pyb.rng()%0xffffff))
ugfx.display_image(0, 0, "apps/sponsors/splash3.gif")
container_handle.show()
return container_handle
示例11: spawn_enemy
def spawn_enemy():
if level == 1:
spawn_quadcopter()
else:
if pyb.rng() % 5 == 0:
spawn_hab()
else:
spawn_quadcopter()
示例12: spawn_hab
def spawn_hab():
if len(quadcopters) > level:
print("Too many copters! Call the CAA")
#global tmc_count
#tmc_count += 1
return
quadcopter = HAB(pyb.rng()%300, 180, speed=1)
quadcopters.append(quadcopter)
示例13: get_new_game_state
def get_new_game_state(w, h):
angle = pyb.rng() % MAX_ANGLE + 360 - MAX_ANGLE
return {'player': {'x': 0, 'y': 0},
'ai': {'x': w - 2,
'y': h - 15},
'ball': {'x': 5,
'y': 5,
'velocity': get_velocity(angle)},
'score': 0}
示例14: spawn_quadcopter
def spawn_quadcopter():
if len(quadcopters) > level:
print("Too many copters! Call the CAA")
global tmc_count
tmc_count += 1
return
right = pyb.rng() % 2
if right:
x = 0
direction = '+'
else:
x = 320
direction = '-'
speed = (pyb.rng() % (level))
if speed == 0:
speed = 1
quadcopter = Quadcopter(x, pyb.rng() % 160, direction=direction, speed=speed)
quadcopters.append(quadcopter)
示例15: generate_board
def generate_board():
"""
Returns random board.
"""
board = set()
for x in range(8):
for y in range(8):
if pyb.rng() % 2 == 0:
board.add((x, y))
return board