本文整理汇总了Python中numbers.clip函数的典型用法代码示例。如果您正苦于以下问题:Python clip函数的具体用法?Python clip怎么用?Python clip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_confident
def is_confident(life):
_friendly_confidence = 0
_threat_confidence = 0
for target_id in judgement.get_trusted(life, visible=False):
_knows = brain.knows_alife_by_id(life, target_id)
if _knows['dead'] or _knows['asleep']:
continue
_recent_mod = numbers.clip(_knows['last_seen_time'], 0, 300)/300.0
if _knows['last_seen_time']:
_friendly_confidence += _recent_mod
else:
_friendly_confidence += judgement.get_ranged_combat_rating_of_target(life, target_id)*_recent_mod
for target_id in judgement.get_threats(life, ignore_escaped=True):
_knows = brain.knows_alife_by_id(life, target_id)
if _knows['dead'] or _knows['asleep']:
continue
_recent_mod = numbers.clip(_knows['last_seen_time'], 0, 300)/300.0
if _knows['last_seen_time']:
_threat_confidence += 2*_recent_mod
else:
_threat_confidence += judgement.get_ranged_combat_rating_of_target(life, target_id)*_recent_mod
return _friendly_confidence > _threat_confidence
示例2: update_targets_around_noise
def update_targets_around_noise(life, noise):
_most_likely_target = {'target': None, 'last_seen_time': 0}
if 'target' in noise and not life['id'] == noise['target']:
_visiblity = numbers.clip(sight.get_stealth_coverage(LIFE[noise['target']]), 0.0, 1.0)
_visiblity = numbers.clip(_visiblity+(numbers.distance(life['pos'], LIFE[noise['target']]['pos']))/(sight.get_vision(life)/2), 0, 1.0)
if _visiblity >= sight.get_visiblity_of_position(life, LIFE[noise['target']]['pos']):
brain.meet_alife(life, LIFE[noise['target']])
life['know'][noise['target']]['escaped'] = 1
life['know'][noise['target']]['last_seen_at'] = noise['pos'][:]
life['know'][noise['target']]['last_seen_time'] = 0
for target in life['know'].values():
if not target['escaped'] or not target['last_seen_at'] or target['dead']:
continue
if numbers.distance(target['last_seen_at'], noise['pos']) > noise['volume']:
continue
if judgement.is_target_threat(life, target['life']['id']):
if not _most_likely_target['target'] or target['last_seen_time'] < _most_likely_target['last_seen_time']:
_most_likely_target['last_seen_time'] = target['last_seen_time']
_most_likely_target['target'] = target
if _most_likely_target['target']:
_most_likely_target['target']['escaped'] = 1
_most_likely_target['target']['last_seen_at'] = noise['pos'][:]
_most_likely_target['target']['last_seen_time'] = 1
logging.debug('%s heard a noise, attributing it to %s.' % (' '.join(life['name']), ' '.join(_most_likely_target['target']['life']['name'])))
示例3: get_overwatch_hardship
def get_overwatch_hardship(no_mod=True):
_stats = WORLD_INFO['overwatch']
_situation = get_player_situation()
if not _situation:
return 0
if no_mod:
_mod = 1
else:
if len(_situation['online_alife']) == len(_situation['trusted_online_alife']):
_mod = _stats['last_updated']/float(WORLD_INFO['ticks'])
else:
_mod = numbers.clip((_stats['last_updated']*1.5)/float(WORLD_INFO['ticks']), 0, 1.0)
#TODO: Decay
#_stats['loss_experienced'] *= _dec
#_stats['danger_experienced'] *= _dec
#_stats['injury'] *= _dec
#_stats['human_encounters'] *= _dec
_hardship = _stats['loss_experienced']
_hardship += _stats['danger_experienced']
_hardship += _stats['injury']
_hardship += _stats['human_encounters']*4
_hardship *= _mod
return numbers.clip(float(_hardship), 0.0, 10.0)
示例4: check_chunks
def check_chunks(self, force=False):
if not force and WORLD_INFO["ticks"] - self.last_checked < self.check_every:
return False
self.last_checked = WORLD_INFO["ticks"]
for life in [l for l in LIFE.values() if l["online"]]:
_x_min = numbers.clip(life["pos"][0] - MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0] - 1 - MAP_WINDOW_SIZE[0])
_y_min = numbers.clip(life["pos"][1] - MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1] - 1 - MAP_WINDOW_SIZE[1])
_x_max = numbers.clip(life["pos"][0] + MAP_WINDOW_SIZE[0], 0, MAP_SIZE[0] - 1)
_y_max = numbers.clip(life["pos"][1] + MAP_WINDOW_SIZE[1], 0, MAP_SIZE[1] - 1)
_refresh = False
for y in range(_y_min, _y_max, WORLD_INFO["chunk_size"]):
for x in range(_x_min, _x_max, WORLD_INFO["chunk_size"]):
maps.load_cluster_at_position_if_needed((x, y))
SETTINGS["loading"] = True
if "player" in life:
_refresh = True
if _refresh:
gfx.refresh_view("map")
SETTINGS["loading"] = False
示例5: draw_chunk_map
def draw_chunk_map(life=None, show_faction_ownership=False):
_x_min = numbers.clip(CAMERA_POS[0]/WORLD_INFO['chunk_size'], 0, MAP_SIZE[0]/WORLD_INFO['chunk_size'])
_y_min = numbers.clip(CAMERA_POS[1]/WORLD_INFO['chunk_size'], 0, MAP_SIZE[1]/WORLD_INFO['chunk_size'])
_x_max = numbers.clip(_x_min+WINDOW_SIZE[0], 0, MAP_SIZE[0]/WORLD_INFO['chunk_size'])
_y_max = numbers.clip(_y_min+WINDOW_SIZE[1], 0, MAP_SIZE[1]/WORLD_INFO['chunk_size'])
_life_chunk_key = None
if life:
_life_chunk_key = lfe.get_current_chunk_id(life)
for x in range(_x_min, _x_max):
_d_x = x-(CAMERA_POS[0]/WORLD_INFO['chunk_size'])
if 0>_d_x >= WINDOW_SIZE[0]:
continue
for y in range(_y_min, _y_max):
_d_y = y-(CAMERA_POS[1]/WORLD_INFO['chunk_size'])
_draw = True
_fore_color = tcod.darker_gray
_back_color = tcod.darkest_gray
if 0>_d_y >= WINDOW_SIZE[1]:
continue
_chunk_key = '%s,%s' % (x*WORLD_INFO['chunk_size'], y*WORLD_INFO['chunk_size'])
if life:
if not _chunk_key in life['known_chunks']:
_draw = False
if _draw:
_type = WORLD_INFO['chunk_map'][_chunk_key]['type']
_char = 'x'
if _type in ['building', 'town']:
_fore_color = tcod.light_gray
_char = 'B'
elif _type in ['outpost', 'factory']:
_fore_color = tcod.desaturated_green
_back_color = tcod.desaturated_han
_char = 'M'
elif _type == 'field':
_fore_color = tcod.yellow
elif _type == 'forest':
_fore_color = tcod.dark_green
elif _type in ['road', 'driveway']:
_fore_color = tcod.white
_back_color = tcod.black
_char = '.'
if _chunk_key == _life_chunk_key and time.time()%1>=.5:
_fore_color = tcod.white
_char = 'X'
gfx.blit_char_to_view(_d_x, _d_y, _char, (_fore_color, _back_color), 'chunk_map')
else:
gfx.blit_char_to_view(_d_x, _d_y, 'x', (tcod.darker_gray, tcod.darkest_gray), 'chunk_map')
示例6: death
def death():
FADE_TO_WHITE[0] += 0.5
_time_since_death = FADE_TO_WHITE[0]
_time_alive = numbers.clip(
(LIFE[SETTINGS["controlling"]]["time_of_death"] - LIFE[SETTINGS["controlling"]]["created"])
/ float(WORLD_INFO["length_of_day"]),
0.1,
9999,
)
_string = "You die."
_sub_string = LIFE[SETTINGS["controlling"]]["cause_of_death"]
_col = int(round(255 * numbers.clip((_time_since_death / 100.0) - random.uniform(0, 0.15), 0, 1)))
if _time_alive == 1:
_sub_sub_string = "Lived 1 day"
else:
_sub_sub_string = "Lived %s days" % (_time_alive)
gfx.fade_to_black(1)
gfx.blit_string(
(MAP_WINDOW_SIZE[0] / 2) - len(_string) / 2,
MAP_WINDOW_SIZE[1] / 2,
_string,
"map",
fore_color=tcod.Color(_col, 0, 0),
back_color=tcod.Color(0, 0, 0),
)
gfx.blit_string(
(MAP_WINDOW_SIZE[0] / 2) - len(_sub_string) / 2,
(MAP_WINDOW_SIZE[1] / 2) + 2,
_sub_string,
"map",
fore_color=tcod.Color(int(round(_col * 0.75)), int(round(_col * 0.75)), int(round(_col * 0.75))),
back_color=tcod.Color(0, 0, 0),
)
gfx.blit_string(
(MAP_WINDOW_SIZE[0] / 2) - len(_sub_sub_string) / 2,
(MAP_WINDOW_SIZE[1] / 2) + 4,
_sub_sub_string,
"map",
fore_color=tcod.Color(int(round(_col * 0.75)), int(round(_col * 0.75)), int(round(_col * 0.75))),
back_color=tcod.Color(0, 0, 0),
)
if _time_since_death >= 350:
worldgen.save_world()
worldgen.reset_world()
gfx.clear_scene()
SETTINGS["running"] = 1
return False
return True
示例7: draw_message_box
def draw_message_box():
_view = get_view_by_name('message_box')
if not _is_view_dirty(_view):
return False
_set_view_clean(_view)
#blit_string(1, 0, 'Messages', 'message_box', fore_color=tcod.white)
_y_mod = 1
_lower = numbers.clip(0,len(MESSAGE_LOG)-MESSAGE_LOG_MAX_LINES,100000)
_i = -1
for msg in MESSAGE_LOG[_lower:len(MESSAGE_LOG)]:
if msg['count']:
_text = '%s (x%s)' % (msg['msg'], msg['count']+1)
else:
_text = msg['msg']
if msg['style'] == 'damage':
_fore_color = tcod.red
elif msg['style'] == 'speech':
_fore_color = tcod.gray
elif msg['style'] == 'action':
_fore_color = tcod.lighter_crimson
elif msg['style'] == 'important':
_fore_color = tcod.Color(150,150,255)
elif msg['style'] == 'radio':
_fore_color = tcod.Color(225,245,169)
elif msg['style'] == 'good':
_fore_color = tcod.light_green
elif msg['style'] == 'player_combat_good':
_fore_color = tcod.green
elif msg['style'] == 'player_combat_bad':
_fore_color = tcod.crimson
else:
_fore_color = tcod.white
_c = 9*((_i>0)+1)
_back_color = tcod.Color(_c, _c, _c)
_i = -_i
while _text:
_print_text = _text[:_view['draw_size'][0]-2]
_padding = ' '*numbers.clip(_view['draw_size'][0], 0, _view['draw_size'][0]-len(_print_text)-2)
blit_string(1, _y_mod, _print_text+_padding, 'message_box', fore_color=_fore_color, back_color=_back_color)
_y_mod += 1
_text = _text[_view['draw_size'][0]-2:]
if _y_mod > MESSAGE_LOG_MAX_LINES:
break
if not _text.startswith(' ') and _text:
_text = ' '+_text
if _y_mod > MESSAGE_LOG_MAX_LINES:
break
示例8: draw_intro
def draw_intro():
_stime = time.time()
_title_time = time.time()
_warning_time = None
_warning_message = VERSION
_sub_mod = 0
_sub_time = 0
_shadow = 50
_burn = 8.0
_char_alpha = {c: random.uniform(.15, .7) for c in SUB_LINE}
#Why did I base this on time.time()?
while time.time()-_stime<=5:
_text = INTRO
if time.time()-_stime<=1:
_text = list(_text)
random.shuffle(_text)
_text = ''.join(_text)
else:
if not _sub_time:
_sub_time = time.time()
if 4.0>time.time()-_stime:
_burn *= 1.005
elif time.time()-_stime>=4.0 and _burn>255:
_burn = 255
_text = INTRO
_mod = int(round(255*numbers.clip(time.time()-_title_time, 0, 1)))
console_set_default_foreground(0, Color(_mod, _mod, _mod))
console_print(0, (WINDOW_SIZE[0]/2)-len(_text)/2, (WINDOW_SIZE[1]/2)-2, _text)
if time.time()-_stime>=1:
if not _warning_time:
_warning_time = time.time()
_mod = int(round(255*numbers.clip(time.time()-_warning_time, 0, 1)))
console_set_default_foreground(0, Color(_mod/2, _mod/2, _mod/2))
console_print(0, 0, WINDOW_SIZE[1]-1, _warning_message)
if time.time()-_stime>=1.2:
_i = 0
for c in SUB_LINE:
_c_mod = _char_alpha[c]
_mod = numbers.clip(time.time()-_warning_time, 0, 1)
console_set_default_foreground(0, Color(int(round((200*_mod)*_c_mod)), 0, 0))
console_print(0, _i+(WINDOW_SIZE[0]/2)-len(SUB_LINE)/2, (WINDOW_SIZE[1]/2), c)
_char_alpha[c] = numbers.clip(_char_alpha[c]*1.015, 0, 1)
_i += 1
console_flush()
SETTINGS['running'] = 1
示例9: calculate_fire
def calculate_fire(fire):
_neighbor_intensity = 0
_neighbor_lit = False
for x in range(-1, 2):
_x = fire['pos'][0]+x
if _x<0 or _x>=MAP_SIZE[0]:
continue
for y in range(-1, 2):
if not x and not y:
continue
_y = fire['pos'][1]+y
if _y<0 or _y>=MAP_SIZE[1]:
continue
_effects = [EFFECTS[eid] for eid in EFFECT_MAP[_x][_y] if EFFECTS[eid]['type'] == 'fire']
for effect in _effects:
_neighbor_intensity += effect['intensity']
if 'light' in effect:
_neighbor_lit = True
if not _effects:
_tile = WORLD_INFO['map'][_x][_y][fire['pos'][2]]
_raw_tile = tiles.get_raw_tile(_tile)
_heat = tiles.get_flag(WORLD_INFO['map'][_x][_y][fire['pos'][2]], 'heat')
_current_burn = int(round(fire['intensity']))
_max_burn = int(round(_current_burn*.23))
if tiles.flag(_tile, 'heat', numbers.clip(_heat+(fire['intensity']*.01), 0, 8))>=_raw_tile['burnable']:
if _raw_tile['burnable'] and _max_burn:
create_fire((_x, _y, fire['pos'][2]), intensity=random.randint(1, numbers.clip(1+_max_burn, 2, 8)))
_intensity = ((64-_neighbor_intensity)/64.0)*random.uniform(0, SETTINGS['fire burn rate'])
fire['intensity'] -= _intensity
for life in [LIFE[life_id] for life_id in LIFE_MAP[fire['pos'][0]][fire['pos'][1]]]:
lfe.burn(life, fire['intensity'])
for item in items.get_items_at(fire['pos']):
items.burn(item, fire['intensity'])
update_effect(fire)
if fire['intensity'] <= 0.25:
unregister_effect(fire)
if 'light' in fire:
fire['light']['brightness'] -= numbers.clip(_intensity*.015, 0, 5)
elif not _neighbor_lit:
fire['light'] = create_light(fire['pos'], (255, 69, 0), 17*(fire['intensity']/8.0), 0.25)
示例10: move_camera
def move_camera(pos, scroll=False):
_orig_pos = CAMERA_POS[:]
CAMERA_POS[0] = numbers.clip(pos[0]-(WINDOW_SIZE[0]/2),0,MAP_SIZE[0]-WINDOW_SIZE[0])
CAMERA_POS[1] = numbers.clip(pos[1]-(WINDOW_SIZE[1]/2),0,MAP_SIZE[1]-WINDOW_SIZE[1])
CAMERA_POS[2] = pos[2]
if not _orig_pos == CAMERA_POS:
gfx.refresh_view('map')
elif SETTINGS['controlling'] and not alife.brain.get_flag(LIFE[SETTINGS['controlling']], 'redraw') == pos:
gfx.refresh_view('map')
示例11: position_is_in_frame
def position_is_in_frame(pos):
_view = get_active_view()
if not _view:
return False
if pos[0] >= CAMERA_POS[0] and pos[0] < numbers.clip(CAMERA_POS[0]+_view['view_size'][0]-1, 0, MAP_SIZE[0]) and \
pos[1] >= CAMERA_POS[1] and pos[1] < numbers.clip(CAMERA_POS[1]+_view['view_size'][1]-1, 0, MAP_SIZE[1]):
return True
return False
示例12: death
def death():
_player = LIFE[SETTINGS['controlling']]
maps.reset_lights()
FADE_TO_WHITE[0] += .5
_time_since_death = FADE_TO_WHITE[0]
_time_alive = round(numbers.clip((_player['time_of_death']-_player['created'])/float(WORLD_INFO['length_of_day']), 0.1, 9999), 2)
_string = 'You die.'
_sub_string = _player['cause_of_death']
_col = int(round(255*numbers.clip((_time_since_death/100.0)-random.uniform(0, 0.15), 0, 1)))
if _time_alive == 1:
_sub_sub_string = 'Lived 1 day'
else:
if _time_alive < 1:
_sub_sub_string = 'Lived less than a day'
else:
_sub_sub_string = 'Lived %0.1f days' % (_time_alive)
gfx.fade_to_black(1)
gfx.blit_string((MAP_WINDOW_SIZE[0]/2)-len(_string)/2,
MAP_WINDOW_SIZE[1]/2,
_string,
'map',
fore_color=tcod.Color(_col, 0, 0),
back_color=tcod.Color(0, 0, 0))
gfx.blit_string((MAP_WINDOW_SIZE[0]/2)-len(_sub_string)/2,
(MAP_WINDOW_SIZE[1]/2)+2,
_sub_string,
'map',
fore_color=tcod.Color(int(round(_col*.75)), int(round(_col*.75)), int(round(_col*.75))),
back_color=tcod.Color(0, 0, 0))
gfx.blit_string((MAP_WINDOW_SIZE[0]/2)-len(_sub_sub_string)/2,
(MAP_WINDOW_SIZE[1]/2)+4,
_sub_sub_string,
'map',
fore_color=tcod.Color(int(round(_col*.75)), int(round(_col*.75)), int(round(_col*.75))),
back_color=tcod.Color(0, 0, 0))
if _time_since_death>=350:
worldgen.save_world()
worldgen.reset_world()
gfx.clear_scene()
SETTINGS['running'] = 1
return False
return True
示例13: is_confident
def is_confident(life):
if 'player' in life:
return False
_friendly_confidence = judgement.get_ranged_combat_rating_of_target(life, life['id'])
_threat_confidence = 0
for target_id in judgement.get_trusted(life, visible=False):
_knows = brain.knows_alife_by_id(life, target_id)
if _knows['dead'] or _knows['asleep']:
continue
if _knows['last_seen_time']>30:
if brain.get_alife_flag(life, target_id, 'threat_score'):
_recent_mod = 1-(numbers.clip(_knows['last_seen_time'], 0, 300)/300.0)
_score = brain.get_alife_flag(life, target_id, 'threat_score')
_friendly_confidence += _score*_recent_mod
else:
_friendly_confidence += 1
else:
_score = judgement.get_ranged_combat_rating_of_target(life, target_id)
brain.flag_alife(life, target_id, 'threat_score', value=_score)
_friendly_confidence += _score
for target_id in judgement.get_threats(life, ignore_escaped=False):
_knows = brain.knows_alife_by_id(life, target_id)
if _knows['dead'] or _knows['asleep']:
continue
if _knows['last_seen_time']:
if brain.get_alife_flag(life, target_id, 'threat_score'):
if _knows['last_seen_time']>50:
_recent_mod = 1-(numbers.clip(_knows['last_seen_time'], 0, 600)/600.0)
else:
_recent_mod = 1
_score = brain.get_alife_flag(life, target_id, 'threat_score')
_threat_confidence += _score*_recent_mod
else:
_threat_confidence += 1
else:
_score = judgement.get_ranged_combat_rating_of_target(life, target_id, inventory_check=False)
brain.flag_alife(life, target_id, 'threat_score', value=_score)
_threat_confidence += _score
return _friendly_confidence-_threat_confidence>=-2
示例14: get_vision
def get_vision(life):
if not 'CAN_SEE' in life['life_flags']:
return 0
if 'player' in life:
_fov_mod = 1
else:
_fov_mod = numbers.clip(1-(life['think_rate']/float(life['think_rate_max'])), 0.5, 1)
_world_light = tcod.white-weather.get_lighting()
_light_percentage = numbers.clip(((_world_light.r+_world_light.g+_world_light.b)*.30)/200.0, 0, 1)
return int(round((life['vision_max']*_light_percentage)*_fov_mod))
示例15: move_camera
def move_camera(pos, scroll=False):
_orig_pos = CAMERA_POS[:]
CAMERA_POS[0] = numbers.clip(pos[0] - (MAP_WINDOW_SIZE[0] / 2), 0, MAP_SIZE[0] - MAP_WINDOW_SIZE[0])
CAMERA_POS[1] = numbers.clip(pos[1] - (MAP_WINDOW_SIZE[1] / 2), 0, MAP_SIZE[1] - MAP_WINDOW_SIZE[1])
CAMERA_POS[2] = pos[2]
if not _orig_pos == CAMERA_POS:
gfx.refresh_view("map")
elif SETTINGS["controlling"] and not alife.brain.get_flag(LIFE[SETTINGS["controlling"]], "redraw") == pos:
gfx.refresh_view("map")
if SETTINGS["controlling"]:
alife.brain.flag(LIFE[SETTINGS["controlling"]], "redraw", value=pos[:])