def __init__(self, context: GameContext, frame: Rect, width: int) -> None: super().__init__(context, frame) self.width = width self.ceiling = Solid( context, Rect.make(0, -frame.size.height / 2 + width / 2, frame.size.width, width)) self.wallLeft = Solid( context, Rect.make(-frame.size.width / 2 + width / 2, 0, width, frame.size.height - width * 2)) self.wallRight = Solid( context, Rect.make(frame.size.width / 2 - width / 2, 0, width, frame.size.height - width * 2)) self.floor = Solid( context, Rect.make(0, frame.size.height / 2 - width / 2, frame.size.width, width)) self.ceiling.renderObject = RenderObject.render_object_from_color( context.renderer, Color(0, 0, 0, 0xFF)) self.wallLeft.renderObject = RenderObject.render_object_from_color( context.renderer, Color(0, 0, 0, 0xFF)) self.wallRight.renderObject = RenderObject.render_object_from_color( context.renderer, Color(0, 0, 0, 0xFF)) self.floor.renderObject = RenderObject.render_object_from_color( context.renderer, Color(0, 0, 0, 0xFF)) self.add_child(self.ceiling) self.add_child(self.wallLeft) self.add_child(self.wallRight) self.add_child(self.floor)
def __init__(self, points=None, bgColor=Color("bg", ("blue", 0.45)), textColor=Color("bg", ("white", 0.95))): if not points: points = [] self.points = [] for point in points: self.points.append((point, False)) self.bgColor = bgColor self.textColor = textColor self.menu = False self.menuInstance = None
def get_rgb(self, index): page = self._get_page(index) content = page.find('div', class_='colormap-col colormap_detailinfo span6') rgb = content.find_all('p')[0].text[14:-9].strip().split(',') rgb = [int(col) for col in rgb] return Color(*rgb, index)
def loadColorsFromFile(self, path): """load color definitions from file""" config = ConfigObj(path) if 'colors' in config: colors = config['colors'] colorObjects = {} for key in colors.keys(): content = colors[key] if len(content ) == 2: # hex color/color name and alpha as float 0-1 colorString = content[0] alpha = float(content[1]) # create a new modRana color instance newColor = Color(key, colorStringAlphaTupple=(colorString, alpha)) colorObjects[key] = newColor return colorObjects else: return {}
if __name__ == "__main__": colors = None scrap = Scraper() if not os.path.exists("./data.json"): scrap.run_multi() colors = scrap.colors frozen = jsonpickle.encode(colors) with open('data.json', 'w') as text_file: print(frozen, file=text_file) else: with open('data.json', 'r') as text_file: colors = jsonpickle.decode(text_file.read()) while(True): choose = int(input("\n\n[1] Szukaj farby\n[2] Zakoncz dzialania\n>> ")) if choose == 1: rgb = input("Podaj rgb po spacji: ") rgb = [int(col) for col in rgb.split(' ')] point = Color(*rgb, 0) closest_colors = sorted(colors, key=lambda color: cie94(point.cie, color.cie)) closest_color = closest_colors[0:5] print(*closest_color, sep="\n") elif choose == 2: exit(0) else: print("Musisz wybrac 1 lub 2\n")
def __init__(self) -> None: if sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) < 0: raise RuntimeError("SDL could not initialize! SDL Error: " + str(sdl2.SDL_GetError())) if not sdl2.SDL_SetHint(sdl2.SDL_HINT_RENDER_SCALE_QUALITY, b"1"): print("Warning: Linear texture filtering not enabled.") img_flags = sdl2.sdlimage.IMG_INIT_PNG if not (sdl2.sdlimage.IMG_Init(img_flags) & img_flags): raise RuntimeError( "SDL_image could not initialize! SDL_image Error: " + str(sdl2.sdlimage.IMG_GetError())) if sdl2.sdlttf.TTF_Init() == -1: raise RuntimeError( "SDL_ttf could not initialize! SDL_ttf Error: " + str(sdl2.sdlttf.TTF_GetError())) settings = GameSettings('Test game', 800, 600) window = sdl2.SDL_CreateWindow(bytes(settings.name, 'utf-8'), sdl2.SDL_WINDOWPOS_UNDEFINED, sdl2.SDL_WINDOWPOS_UNDEFINED, settings.windowWidth, settings.windowHeight, sdl2.SDL_WINDOW_SHOWN) if not window: raise RuntimeError("Window could not be created. SDL Error: " + str(sdl2.SDL_GetError())) self.context = GameContext( sdl2.SDL_CreateRenderer( window, -1, sdl2.SDL_RENDERER_ACCELERATED | sdl2.SDL_RENDERER_PRESENTVSYNC), settings) sdl2.SDL_SetRenderDrawColor(self.context.renderer, 0xff, 0xff, 0xff, 0xff) self.world = World( self.context, Rect.make(0, 0, self.context.settings.windowWidth / 2, self.context.settings.windowHeight / 2)) self.ui = GameObject( self.context, Rect(Vector2D(), self.world.camera.originalSize.copy())) player = Player(self.context, Rect.make(0, 20, 10, 20)) player.idleAnimation = Animation.animation_with_single_render_object( RenderObject.render_object_from_file(self.context.renderer, b"img/idle.png")) player.moveAnimation = Animation.animation_with_speed_and_texture_path( 80, self.context.renderer, b"img/move.png", 40, 80, 6) player.jumpAnimation = Animation.animation_with_single_render_object( RenderObject.render_object_from_file(self.context.renderer, b"img/jump.png")) player.crouchAnimation = Animation.animation_with_single_render_object( RenderObject.render_object_from_file(self.context.renderer, b"img/crouch.png")) player.crouchMoveAnimation = Animation.animation_with_single_render_object( RenderObject.render_object_from_file(self.context.renderer, b"img/crouch.png")) player.speed = 1.3 player.jumpSpeed = 2.5 player.physics.gravityForce = 0.1 player.add_child(self.world.camera) self.world.add_child( Frame( self.context, Rect.make(0, 0, self.world.frame.size.width, self.world.frame.size.height), 10)) count = 200 power_count = 100 x = int(self.world.frame.size.width / 10 - 2) y = int(self.world.frame.size.height / 10 - 2) for pair in random.sample(set(pair_range(x, y)), count): random_x = pair[0] random_y = pair[1] rect = Rect.make( (self.world.frame.size.width / 2) - 15 - random_x * 10, (self.world.frame.size.height / 2) - 15 - random_y * 10, 10, 10) if power_count: game_object = Consumable(self.context, rect) game_object.renderObject = RenderObject.render_object_from_color( self.context.renderer, Color(0, 0xff, 0, 0x80)) power_count -= 1 else: game_object = Solid(self.context, rect) game_object.renderObject = RenderObject.render_object_from_file( self.context.renderer, b"img/brick.png") self.world.add_child(game_object) self.world.add_child(player) self.ui = GameObject(self.context, Rect(Vector2D(), self.world.camera.originalSize)) death_text = Text(self.context, Rect.make(0, 0, 100, 10)) death_text.set_text(b"You died! Game Over!") death_text.set_font(b"fonts/Scratch_.ttf", 28) death_text.set_color(sdl2.SDL_Color(0xff, 0, 0)) death_text.visible = False self.ui.add_child(death_text) player.deathText = death_text win_text = Text(self.context, Rect.make(0, 0, 100, 10)) win_text.set_text(b"Congratulations! You won!") win_text.set_font(b"fonts/Scratch_.ttf", 28) win_text.set_color(sdl2.SDL_Color(0, 0xff, 0)) win_text.visible = False self.ui.add_child(win_text) player.winText = win_text health_bar_holder = GameObject( self.context, Rect.make(-self.world.camera.originalSize.width / 2 + 16, -self.world.camera.originalSize.height / 2 + 2.5, 30, 3)) health_bar_holder.renderObject = RenderObject.render_object_from_color( self.context.renderer, Color.black()) self.ui.add_child(health_bar_holder) power_bar_holder = GameObject( self.context, Rect.make(self.world.camera.originalSize.width / 2 - 16, -self.world.camera.originalSize.height / 2 + 2.5, 30, 3)) power_bar_holder.renderObject = RenderObject.render_object_from_color( self.context.renderer, Color.black()) self.ui.add_child(power_bar_holder) health_bar = Bar(self.context, Rect.make(0, 0, 29, 2)) health_bar.renderObject = RenderObject.render_object_from_color( self.context.renderer, Color.red()) health_bar_holder.add_child(health_bar) player.healthBar = health_bar power_bar = Bar(self.context, Rect.make(0, 0, 29, 2)) power_bar.renderObject = RenderObject.render_object_from_color( self.context.renderer, Color.green()) power_bar.set_value(0) power_bar_holder.add_child(power_bar) player.powerBar = power_bar
def getCustomIcon(self, parameterList, w, h): """ there are six positional parameters: fill color,fill opacity, outline color, outline opacity, outline width (default 8) and corner radius (default 22) to use default value, just don't fill in the positional parameter ( len(parameter) == 0 ) USAGE: corner radius: default=22, 0 does right angle corners EXAMPLE: generic:green;1.0;blue;0.5;10;15 """ # check if the list has proper length if len(parameterList) != 6: return None semicolonSepList = parameterList # process the positional parameters if len(semicolonSepList[0]): fillColorString = semicolonSepList[0] else: fillColorString = None if len(semicolonSepList[1]): fillAlpha = float(semicolonSepList[1]) else: fillAlpha = 1.0 if len(semicolonSepList[2]): outlineColorString = semicolonSepList[2] else: outlineColorString = None if len(semicolonSepList[3]): outlineAlpha = float(semicolonSepList[3]) else: outlineAlpha = 1.0 if len(semicolonSepList[4]): outlineWidth = int(semicolonSepList[4]) else: outlineWidth = 4 if len(semicolonSepList[5]): cornerRadius = int(semicolonSepList[5]) else: cornerRadius = 22 # parse the colors (if defined) if fillColorString: fillColor = Color("fill", (fillColorString, fillAlpha)) fillColorRGBATuple = fillColor.getCairoColor() else: fillColorRGBATuple = self.buttonFillColor if outlineColorString: outlineColor = Color("outline", (outlineColorString, outlineAlpha)) outlineColorRGBATuple = outlineColor.getCairoColor() else: outlineColorRGBATuple = self.buttonOutlineColor # apply the alpha values try: (r, g, b, a) = fillColorRGBATuple fillColorRGBATuple = (r, g, b, fillAlpha) except Exception: self.log.exception("** wrong fill color code or name: %s", fillColorString) fillColorRGBATuple = self.buttonFillColor try: (r, g, b, a) = outlineColorRGBATuple outlineColorRGBATuple = (r, g, b, outlineAlpha) except Exception: self.log.exception("** wrong outline color code or name: %s", fillColorString) outlineColorRGBATuple = self.buttonOutlineColor # create the icon icon = self.roundedRectangle(w, h, fillColorRGBATuple, outlineColorRGBATuple, outlineWidth, cornerRadius) return icon