Python pygame.Color() Examples
The following are 30
code examples of pygame.Color().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.

Example #1
Source File: PlotPyGame.py From Grid2Op with Mozilla Public License 2.0 | 7 votes |
def _draw_topos_one_sub(self, fig, sub_id, buses_z, elements, bus_vect): colors = [pygame.Color(255, 127, 14), pygame.Color(31, 119, 180)] # I plot the buses for bus_id, z_bus in enumerate(buses_z): pygame.draw.circle(self.screen, colors[bus_id], [int(z_bus.real), int(z_bus.imag)], int(self.bus_radius), 0) # i connect every element to the proper bus with the proper color for el_nm, dict_el in elements.items(): this_el_bus = bus_vect[dict_el["sub_pos"]] -1 if this_el_bus >= 0: pygame.draw.line(self.screen, colors[this_el_bus], [int(dict_el["z"].real), int(dict_el["z"].imag)], [int(buses_z[this_el_bus].real), int(buses_z[this_el_bus].imag)], 2) return []
Example #2
Source File: viewfinder.py From viewfinder with Apache License 2.0 | 6 votes |
def DrawLabel(label, x, y, color, font, transparency, bold=False, border=False, left_justify=False): color = pygame.Color(*[int(i + transparency * (j - i)) for i, j in zip(color, backdrop_color)]) offset = DimensionsToPixels([x, y]) ts = bold_font.render(label, True, color) if bold else font.render(label, True, color) if y > iphone_dims[1] - ts.get_height(): offset[1] -= (ts.get_height() + 2) else: offset[1] += 2 if left_justify: offset[0] = min(iphone_dims[0], offset[0]) else: offset[0] = max(0, offset[0] - ts.get_width()) GetSurface().blit(ts, offset) if border: pygame.draw.rect(GetSurface(), color, [offset[0]-2, offset[1]-2, ts.get_width() + 4, ts.get_height() + 4], 1)
Example #3
Source File: PlotPyGame.py From Grid2Op with Mozilla Public License 2.0 | 6 votes |
def _draw_topos_one_sub(self, fig, sub_id, buses_z, elements, bus_vect): colors = [pygame.Color(255, 127, 14), pygame.Color(31, 119, 180)] # I plot the buses for bus_id, z_bus in enumerate(buses_z): pygame.draw.circle(self.screen, colors[bus_id], [int(z_bus.real), int(z_bus.imag)], int(self.bus_radius), 0) # i connect every element to the proper bus with the proper color for el_nm, dict_el in elements.items(): this_el_bus = bus_vect[dict_el["sub_pos"]] -1 if this_el_bus >= 0: pygame.draw.line(self.screen, colors[this_el_bus], [int(dict_el["z"].real), int(dict_el["z"].imag)], [int(buses_z[this_el_bus].real), int(buses_z[this_el_bus].imag)], 2) return []
Example #4
Source File: Common.py From PyMenu with GNU General Public License v3.0 | 6 votes |
def blitMultilineText(surface, text, pos, font, color=pygame.Color('black')): words = [word.split(' ') for word in text.splitlines()] # 2D array where each row is a list of words. space = font.size(' ')[0] # The width of a space. max_width, max_height = surface.get_size() x, y = pos for line in words: for word in line: word_surface = font.render(word, 0, color) word_width, word_height = word_surface.get_size() if x + word_width >= max_width: x = pos[0] # Reset the x. y += word_height # Start on new row. surface.blit(word_surface, (x, y)) x += word_width + space x = pos[0] # Reset the x. y += word_height # Start on new row.
Example #5
Source File: keyboard.py From Retropie-CRT-Edition with GNU General Public License v3.0 | 6 votes |
def render_text(self, p_sText, p_bShadow = True): C_SHADOW = pygame.Color( 19, 14, 56) C_TEXT = pygame.Color(202,199,219) p_sText = str(p_sText) img = self.m_oFontText.render(p_sText, False, C_TEXT) rect = img.get_rect() sf = pygame.Surface((rect.width, rect.height), pygame.SRCALPHA) if p_bShadow: shadow = self.m_oFontText.render(p_sText, False, C_SHADOW) shadow_rect = img.get_rect() shadow_rect.x += 1 shadow_rect.y += 1 sf.blit(shadow, shadow_rect) sf.blit(img, rect) return sf
Example #6
Source File: ptext.py From ct-Raspi-Radiowecker with GNU General Public License v3.0 | 6 votes |
def _fitsize(text, size, **kwargs): options = _FitsizeOptions(**kwargs) key = text, size, options.key() if key in _fit_cache: return _fit_cache[key] width, height = size def fits(fontsize): opts = options.copy() spans = _wrap(text, fontsize=fontsize, width=width, **opts.towrapoptions()) wmax, hmax = 0, 0 for tpiece, tagspec, x, jpara, jline, linewidth in spans: tagspec.updateoptions(opts) font = getfont(fontsize=fontsize, **opts.togetfontoptions()) y = font.get_sized_height() * (opts.pspace * jpara + opts.lineheight * jline) w, h = font.size(tpiece) wmax = max(wmax, x + w) hmax = max(hmax, y + h) return wmax <= width and hmax <= height fontsize = _binarysearch(fits) _fit_cache[key] = fontsize return fontsize # Returns the color as a color RGB or RGBA tuple (i.e. 3 or 4 integers in the range 0-255) # If color is None, fall back to the default. If default is also None, return None. # Both color and default can be a list, tuple, a color name, an HTML color format string, a hex # number string, or an integer pixel value. See pygame.Color constructor for specification.
Example #7
Source File: ct-alarm-radio.py From ct-Raspi-Radiowecker with GNU General Public License v3.0 | 6 votes |
def cache_idlescreen(self): self.idlescreen_cache = {} time_string = datetime.now().strftime( self.config.setting["timeformat"]) timefont_size = self.ui.calculate_font_size(30) fontcolor = pygame.color.Color(50, 50, 50, 255) self.idlescreen_cache["time_text"] = gui.Text( time_string, timefont_size, color=fontcolor, font=self.ui.basefont_file, shadowoffset=(0.5, 0.5)) self.idlescreen_cache["time_text"].Position = self.ui.calculate_position( (0, 0), self.idlescreen_cache["time_text"].Surface, "center", "center") empty_image = pygame.Surface( self.ui.display_size) def reset_idle(): self.is_idle = False self.idlescreen_cache["button"] = gui.Button( empty_image, self.ui.display_size, reset_idle) self.idlescreen_cache["button"].Position = (0, 0)
Example #8
Source File: render.py From gym-carla with MIT License | 6 votes |
def _render_hist_actors(self, surface, actor_polygons, actor_type, world_to_pixel, num): lp=len(actor_polygons) color = COLOR_SKY_BLUE_0 for i in range(max(0,lp-num),lp): for ID, poly in actor_polygons[i].items(): corners = [] for p in poly: corners.append(carla.Location(x=p[0],y=p[1])) corners.append(carla.Location(x=poly[0][0],y=poly[0][1])) corners = [world_to_pixel(p) for p in corners] color_value = max(0.8 - 0.8/lp*(i+1), 0) if ID == self.hero_id: # red color = pygame.Color(255, math.floor(color_value*255), math.floor(color_value*255)) else: if actor_type == 'vehicle': # green color = pygame.Color(math.floor(color_value*255), 255, math.floor(color_value*255)) elif actor_type == 'walker': # yellow color = pygame.Color(255, 255, math.floor(color_value*255)) pygame.draw.polygon(surface, color, corners)
Example #9
Source File: playSnake.py From You-are-Pythonista with GNU General Public License v3.0 | 6 votes |
def main(): global FPSCLOCK, DISPLAY, BASICFONT, BLACK, WHITE, RED, GREY # 初始化Pygame库 pygame.init() # 初始化一个游戏界面窗口 DISPLAY = pygame.display.set_mode((640, 480)) # 设置游戏窗口的标题 pygame.display.set_caption('人人都是Pythonista - Snake') # 定义一个变量来控制游戏速度 FPSCLOCK = pygame.time.Clock() # 初始化游戏界面内使用的字体 BASICFONT = pygame.font.SysFont("SIMYOU.TTF", 80) # 定义颜色变量 BLACK = pygame.Color(0, 0, 0) WHITE = pygame.Color(255, 255, 255) RED = pygame.Color(255, 0, 0) GREY = pygame.Color(150, 150, 150) playGame() # 开始游戏
Example #10
Source File: skin_manager.py From launcher with GNU General Public License v3.0 | 6 votes |
def SetColors(self): Colors = {} Colors["High"] = pygame.Color(51, 166, 255) Colors["Text"] = pygame.Color(83, 83, 83) Colors["ReadOnlyText"] = pygame.Color(130,130,130) Colors["Front"] = pygame.Color(131, 199, 219) Colors["URL"] = pygame.Color(51, 166, 255) Colors["Line"] = pygame.Color(169, 169, 169) Colors["TitleBg"] = pygame.Color(228, 228, 228) Colors["Active"] = pygame.Color(175, 90, 0) Colors["Disabled"] = pygame.Color(204, 204, 204) Colors["White"] = pygame.Color(255, 255, 255) Colors["Black"] = pygame.Color(0, 0, 0) if self.configExists(): if "Colors" in self._Config.sections(): colour_opts = self._Config.options("Colors") for i in Colors: if i in colour_opts: try: Colors[i] = self.ConvertToRGB( self._Config.get("Colors", i)) except Exception, e: print("error in ConvertToRGB %s" % str(e)) continue
Example #11
Source File: battle.py From universalSmashSystem with GNU General Public License v3.0 | 6 votes |
def __init__(self,_fighter): spriteManager.Sprite.__init__(self) self.fighter = _fighter self.percent = int(_fighter.damage) self.bg_sprite = _fighter.franchise_icon self.bg_sprite.recolor(self.bg_sprite.image,pygame.Color('#cccccc'),pygame.Color(settingsManager.getSetting('playerColor'+str(_fighter.player_num)))) self.bg_sprite.alpha(128) self.image = self.bg_sprite.image self.rect = self.bg_sprite.image.get_rect() #Until I can figure out the percentage sprites self.percent_sprites = spriteManager.SheetSprite(settingsManager.createPath('sprites/guisheet.png'), 64) self.kerning_values = [49,33,44,47,48,43,43,44,49,43,48] #This is the width of each sprite, for kerning purposes self.percent_sprite = spriteManager.Sprite() self.percent_sprite.image = pygame.Surface((196,64), pygame.SRCALPHA, 32).convert_alpha() self.redness = 0 self.updateDamage() self.percent_sprite.rect = self.percent_sprite.image.get_rect() self.percent_sprite.rect.center = self.rect.center
Example #12
Source File: css.py From universalSmashSystem with GNU General Public License v3.0 | 6 votes |
def recolorIcon(self,_reset=False): if _reset: self.icon.recolor(self.icon.image, self.icon_color, pygame.Color('#cccccc')) self.icon_color = pygame.Color('#cccccc') else: display_color = self.wheel.fighterAt(0).palette_display new_color = display_color[self.current_color % len(display_color)] #If the icon matches the background, make it default to the icon color if new_color == pygame.Color(self.fill_color): new_color = pygame.Color('#cccccc') self.icon.recolor(self.icon.image, self.icon_color, new_color) self.icon_color = new_color
Example #13
Source File: ball_shape.py From PyPhysicsSandbox with MIT License | 6 votes |
def _draw(self, screen): if self._cosmetic: p = (self._x, self._y) else: p = to_pygame(self.body.position) pygame.draw.circle(screen, self.color, p, int(self._radius), 0) if self.draw_radius_line: if self._cosmetic: p2 = (self._x+self._radius, self._y) else: circle_edge = self.body.position + pymunk.Vec2d(self.shape.radius, 0).rotated(self.body.angle) p2 = to_pygame(circle_edge) pygame.draw.lines(screen, pygame.Color('black'), False, [p, p2], 1)
Example #14
Source File: pygame_functions.py From Pygame_Functions with GNU General Public License v2.0 | 6 votes |
def __init__(self, text, xpos, ypos, width, case, maxLength, fontSize): pygame.sprite.Sprite.__init__(self) self.text = "" self.width = width self.initialText = text self.case = case self.maxLength = maxLength self.boxSize = int(fontSize * 1.7) self.image = pygame.Surface((width, self.boxSize)) self.image.fill((255, 255, 255)) pygame.draw.rect(self.image, (0, 0, 0), [0, 0, width - 1, self.boxSize - 1], 2) self.rect = self.image.get_rect() self.fontFace = pygame.font.match_font("Arial") self.fontColour = pygame.Color("black") self.initialColour = (180, 180, 180) self.font = pygame.font.Font(self.fontFace, fontSize) self.rect.topleft = [xpos, ypos] newSurface = self.font.render(self.initialText, True, self.initialColour) self.image.blit(newSurface, [10, 5])
Example #15
Source File: pygame_functions.py From Pygame_Functions with GNU General Public License v2.0 | 6 votes |
def __init__(self, text, xpos, ypos, width, case, maxLength, fontSize): pygame.sprite.Sprite.__init__(self) self.text = "" self.width = width self.initialText = text self.case = case self.maxLength = maxLength self.boxSize = int(fontSize * 1.7) self.image = pygame.Surface((width, self.boxSize)) self.image.fill((255, 255, 255)) pygame.draw.rect(self.image, (0, 0, 0), [0, 0, width - 1, self.boxSize - 1], 2) self.rect = self.image.get_rect() self.fontFace = pygame.font.match_font("Arial") self.fontColour = pygame.Color("black") self.initialColour = (180, 180, 180) self.font = pygame.font.Font(self.fontFace, fontSize) self.rect.topleft = [xpos, ypos] newSurface = self.font.render(self.initialText, True, self.initialColour) self.image.blit(newSurface, [10, 5])
Example #16
Source File: aux_functions.py From DRLwithTL with MIT License | 6 votes |
def blit_text(surface, text, pos, font, color=pygame.Color('black')): words = [word.split(' ') for word in text.splitlines()] # 2D array where each row is a list of words. space = font.size(' ')[0] # The width of a space. max_width, max_height = surface.get_size() x, y = pos for line in words: for word in line: word_surface = font.render(word, 0, color) word_width, word_height = word_surface.get_size() if x + word_width >= max_width: x = pos[0] # Reset the x. y += word_height # Start on new row. surface.blit(word_surface, (x, y)) x += word_width + space x = pos[0] # Reset the x. y += word_height # Start on new row.
Example #17
Source File: creeps.py From code-for-blog with The Unlicense | 6 votes |
def draw_walls(self): wallcolor = Color(140, 140, 140) for wall in self.walls: nrow, ncol = wall pos_x = self.field_rect.left + ncol * self.GRID_SIZE + self.GRID_SIZE / 2 pos_y = self.field_rect.top + nrow * self.GRID_SIZE + self.GRID_SIZE / 2 radius = 3 pygame.draw.polygon(self.screen, wallcolor, [ (pos_x - radius, pos_y), (pos_x, pos_y + radius), (pos_x + radius, pos_y), (pos_x, pos_y - radius)]) if (nrow + 1, ncol) in self.walls: pygame.draw.line(self.screen, wallcolor, (pos_x, pos_y), (pos_x, pos_y + self.GRID_SIZE), 3) if (nrow, ncol + 1) in self.walls: pygame.draw.line(self.screen, wallcolor, (pos_x, pos_y), (pos_x + self.GRID_SIZE, pos_y), 3)
Example #18
Source File: task.py From code-jam-5 with MIT License | 6 votes |
def _complete(self, successful: bool) -> None: """Called when task was completed.""" if successful: Sound.task_completed.play() else: Sound.task_failed.play() # Set that task was closed game_vars.open_task = None # Add/reduce heat depending on results game_vars.current_heat += ( self.heat_add_success if successful else self.heat_add_failure ) # Screen notification to informa on task result game_vars.notification = Notification( self.biome.text_task_success if successful else self.biome.text_task_fail, Color.green if successful else Color.red, ) self.is_done = True
Example #19
Source File: period.py From code-jam-5 with MIT License | 6 votes |
def draw_age(self) -> None: """Draw how long the earth lived.""" if self.start_time is not None: # If paused - dont count the age if game_vars.is_paused: if not self.pause_time: self.pause_time = time.time() self.pause_time_sum = time.time() - self.pause_time else: self.pause_time = None font = pg.font.Font(None, 50) text = realtime_to_ingame_formatted(self.elapsed, self.start_date) age_indicator = font.render(text, True, pg.Color("black")) self.screen.blit( age_indicator, (int(WIDTH // 2) - int(age_indicator.get_width() // 2), 0), )
Example #20
Source File: utils.py From Games with MIT License | 5 votes |
def drawGameMatrix(screen, game_matrix, cfg): for i in range(len(game_matrix)): for j in range(len(game_matrix[i])): number = game_matrix[i][j] x = cfg.MARGIN_SIZE * (j + 1) + cfg.BLOCK_SIZE * j y = cfg.MARGIN_SIZE * (i + 1) + cfg.BLOCK_SIZE * i pygame.draw.rect(screen, pygame.Color(getColorByNumber(number)[0]), (x, y, cfg.BLOCK_SIZE, cfg.BLOCK_SIZE)) if number != 'null': font_color = pygame.Color(getColorByNumber(number)[1]) font_size = cfg.BLOCK_SIZE - 10 * len(str(number)) font = pygame.font.Font(cfg.FONTPATH, font_size) text = font.render(str(number), True, font_color) text_rect = text.get_rect() text_rect.centerx, text_rect.centery = x + cfg.BLOCK_SIZE / 2, y + cfg.BLOCK_SIZE / 2 screen.blit(text, text_rect)
Example #21
Source File: Game23.py From Games with MIT License | 5 votes |
def main(cfg): # 游戏初始化 pygame.init() screen = pygame.display.set_mode(cfg.SCREENSIZE) pygame.display.set_caption('2048 —— 微信公众号:Charles的皮卡丘') # 播放背景音乐 pygame.mixer.music.load(cfg.BGMPATH) pygame.mixer.music.play(-1) # 实例化2048游戏 game_2048 = Game2048(matrix_size=cfg.GAME_MATRIX_SIZE, max_score_filepath=cfg.MAX_SCORE_FILEPATH) # 游戏主循环 clock = pygame.time.Clock() is_running = True while is_running: screen.fill(pygame.Color(cfg.BG_COLOR)) # --按键检测 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key in [pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT]: game_2048.setDirection({pygame.K_UP: 'up', pygame.K_DOWN: 'down', pygame.K_LEFT: 'left', pygame.K_RIGHT: 'right'}[event.key]) # --更新游戏状态 game_2048.update() if game_2048.isgameover: game_2048.saveMaxScore() is_running = False # --将必要的游戏元素画到屏幕上 drawGameMatrix(screen, game_2048.game_matrix, cfg) start_x, start_y = drawScore(screen, game_2048.score, game_2048.max_score, cfg) drawGameIntro(screen, start_x, start_y, cfg) # --屏幕更新 pygame.display.update() clock.tick(cfg.FPS) return endInterface(screen, cfg)
Example #22
Source File: draw.py From rpisurv with GNU General Public License v2.0 | 5 votes |
def blank_screen(absposx,absposy,width,height,surface): logger.debug("blanking the screen") surface.fill(pygame.Color("black")) #If the surface was an image you should draw over the images placeholder(absposx,absposy,width,height,"images/blank.png",surface)
Example #23
Source File: viewfinder.py From viewfinder with Apache License 2.0 | 5 votes |
def DrawLabel(label, x, y, color, font, transparency, bold=False, border=False, left_justify=False): color = pygame.Color(*[int(i + transparency * (j - i)) for i, j in zip(color, backdrop_color)]) offset = DimensionsToPixels([x, y]) ts = bold_font.render(label, True, color) if bold else font.render(label, True, color) if y > iphone_dims[1] - ts.get_height(): offset[1] -= (ts.get_height() + 2) else: offset[1] += 2 if left_justify: offset[0] = min(iphone_dims[0], offset[0]) else: offset[0] = max(0, offset[0] - ts.get_width()) GetSurface().blit(ts, offset) if border: pygame.draw.rect(GetSurface(), color, [offset[0]-2, offset[1]-2, ts.get_width() + 4, ts.get_height() + 4], 1)
Example #24
Source File: viewfinder.py From viewfinder with Apache License 2.0 | 5 votes |
def DrawLine(line, color, transparency): color = pygame.Color(*[int(i + transparency * (j - i)) for i, j in zip(color, backdrop_color)]) tx_line = [DimensionsToPixels(pt) for pt in line] pygame.draw.aaline(GetSurface(), color, tx_line[0], tx_line[1], 1)
Example #25
Source File: timeline.py From viewfinder with Apache License 2.0 | 5 votes |
def DrawLabels(labels, x_off, transparency): color = pygame.Color(*[int(x + transparency * (y - x)) for x, y in zip(text_color, backdrop_color)]) for label, pos in zip(labels, xrange(len(labels))): DrawLabel(x_off, (float(pos) * iphone_dims[1]) / (len(labels) - 1), label, color)
Example #26
Source File: viewfinder.py From viewfinder with Apache License 2.0 | 5 votes |
def DrawLine(line, color, transparency): color = pygame.Color(*[int(i + transparency * (j - i)) for i, j in zip(color, backdrop_color)]) tx_line = [DimensionsToPixels(pt) for pt in line] pygame.draw.aaline(GetSurface(), color, tx_line[0], tx_line[1], 1)
Example #27
Source File: battle_city_utils.py From AirGesture with MIT License | 5 votes |
def drawSidebar(self): global screen, players, enemies x = 416 y = 0 screen.fill([100, 100, 100], pygame.Rect([416, 0], [64, 416])) xpos = x + 16 ypos = y + 16 # draw enemy lives for n in range(len(self.level.enemies_left) + len(enemies)): screen.blit(self.enemy_life_image, [xpos, ypos]) if n % 2 == 1: xpos = x + 16 ypos += 17 else: xpos += 17 # players' lives if pygame.font.get_init(): text_color = pygame.Color('black') for n in range(len(players)): if n == 0: screen.blit(self.font.render(str(n + 1) + "P", False, text_color), [x + 16, y + 200]) screen.blit(self.font.render(str(players[n].lives), False, text_color), [x + 31, y + 215]) screen.blit(self.player_life_image, [x + 17, y + 215]) else: screen.blit(self.font.render(str(n + 1) + "P", False, text_color), [x + 16, y + 240]) screen.blit(self.font.render(str(players[n].lives), False, text_color), [x + 31, y + 255]) screen.blit(self.player_life_image, [x + 17, y + 255]) screen.blit(self.flag_image, [x + 17, y + 280]) screen.blit(self.font.render(str(self.stage), False, text_color), [x + 17, y + 312])
Example #28
Source File: battle_city_utils.py From AirGesture with MIT License | 5 votes |
def drawIntroScreen(self, put_on_surface=True): """ Draw intro (menu) screen @param boolean put_on_surface If True, flip display after drawing @return None """ global screen screen.fill([0, 0, 0]) if pygame.font.get_init(): hiscore = self.loadHiscore() screen.blit(self.font.render("HI- " + str(hiscore), True, pygame.Color('white')), [170, 35]) screen.blit(self.font.render("1 PLAYER", True, pygame.Color('white')), [165, 250]) screen.blit(self.font.render("2 PLAYERS", True, pygame.Color('white')), [165, 275]) screen.blit(self.font.render("(c) 1980 1985 NAMCO LTD.", True, pygame.Color('white')), [50, 350]) screen.blit(self.font.render("ALL RIGHTS RESERVED", True, pygame.Color('white')), [85, 380]) if self.nr_of_players == 1: screen.blit(self.player_image, [125, 245]) elif self.nr_of_players == 2: screen.blit(self.player_image, [125, 270]) self.writeInBricks("battle", [65, 80]) self.writeInBricks("city", [129, 160]) if put_on_surface: pygame.display.flip()
Example #29
Source File: PlotPyGame.py From Grid2Op with Mozilla Public License 2.0 | 5 votes |
def _get_default_cmap(self, normalized_val): # step 0: compute thickness and color max_val = 1. ratio_ok = 0.7 start_red = 0.5 amount_green = 235 - int(235. * (normalized_val / (max_val * ratio_ok))**4) amount_red = int(255 * (normalized_val/ (max_val * ratio_ok))**4) # if normalized_val < ratio_ok * max_val: # amount_green = 100 - int(100. * normalized_val / (max_val * ratio_ok)) # if normalized_val > ratio_ok: # tmp = (1.0 * (normalized_val - ratio_ok) / (max_val - ratio_ok))**2 # amount_red += int(235. * tmp) # print("normalized_val {}, amount_red {}".format(normalized_val, amount_red)) # fix to prevent pygame bug if amount_red < 0: amount_red = int(0) elif amount_red > 255: amount_red = int(255) if amount_green < 0: amount_green = int(0) elif amount_green > 255: amount_green = int(255) amount_red = int(amount_red) amount_green = int(amount_green) color = pygame.Color(amount_red, amount_green, 20) return color
Example #30
Source File: PlotPyGame.py From Grid2Op with Mozilla Public License 2.0 | 5 votes |
def _get_default_cmap(self, normalized_val): # step 0: compute thickness and color max_val = 1. ratio_ok = 0.7 start_red = 0.5 amount_green = 235 - int(235. * (normalized_val / (max_val * ratio_ok))**4) amount_red = int(255 * (normalized_val/ (max_val * ratio_ok))**4) # if normalized_val < ratio_ok * max_val: # amount_green = 100 - int(100. * normalized_val / (max_val * ratio_ok)) # if normalized_val > ratio_ok: # tmp = (1.0 * (normalized_val - ratio_ok) / (max_val - ratio_ok))**2 # amount_red += int(235. * tmp) # print("normalized_val {}, amount_red {}".format(normalized_val, amount_red)) # fix to prevent pygame bug if amount_red < 0: amount_red = int(0) elif amount_red > 255: amount_red = int(255) if amount_green < 0: amount_green = int(0) elif amount_green > 255: amount_green = int(255) amount_red = int(amount_red) amount_green = int(amount_green) color = pygame.Color(amount_red, amount_green, 20) return color