当前位置: 首页>>代码示例>>Python>>正文


Python pyb.rng函数代码示例

本文整理汇总了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
开发者ID:raymondcheng008,项目名称:roz,代码行数:26,代码来源:roz.py

示例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))
开发者ID:rolandvs,项目名称:GuyCarverMicroPythonCode,代码行数:10,代码来源:bombs.py

示例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
开发者ID:wamonite,项目名称:emfbadge_2016_life,代码行数:7,代码来源:main.py

示例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
开发者ID:pramasoul,项目名称:micropython-ws2812,代码行数:27,代码来源:percolator.py

示例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
开发者ID:sampdelaney,项目名称:tilda3-gol,代码行数:7,代码来源:main.py

示例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)
开发者ID:thinkl33t,项目名称:TiLDA-Wearables,代码行数:29,代码来源:external.py

示例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
开发者ID:robert-hh,项目名称:SSD1963-TFT-Library-for-PyBoard,代码行数:7,代码来源:slides.py

示例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)
开发者ID:rolandvs,项目名称:GuyCarverMicroPythonCode,代码行数:17,代码来源:tft.py

示例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
开发者ID:librallu,项目名称:cohorte-herald,代码行数:8,代码来源:serial_herald_message.py

示例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
开发者ID:tofuman,项目名称:RedStar-Badge-OS,代码行数:8,代码来源:main.py

示例11: spawn_enemy

def spawn_enemy():
    if level == 1:
        spawn_quadcopter()
    else:
        if pyb.rng() % 5 == 0:
            spawn_hab()
        else:
            spawn_quadcopter()
开发者ID:MatthewWilkes,项目名称:tildamk3-dronehunt,代码行数:8,代码来源:main.py

示例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)
开发者ID:MatthewWilkes,项目名称:tildamk3-dronehunt,代码行数:8,代码来源:main.py

示例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}
开发者ID:nvbn,项目名称:pyboard-play,代码行数:9,代码来源:pong.py

示例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)
开发者ID:MatthewWilkes,项目名称:tildamk3-dronehunt,代码行数:18,代码来源:main.py

示例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
开发者ID:JanBednarik,项目名称:micropython-matrix8x8,代码行数:10,代码来源:game_of_life.py


注:本文中的pyb.rng函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。