def reset(self): self.rect_1 = create_rect(self.x - 2, self.y - 2, self.w + 4, self.h + 4, sf.Color(100, 100, 100)) bar_len = self.h * self.value self.rect_2 = create_rect(self.x, self.y + self.h - bar_len, self.w, bar_len, sf.Color(5, 102, 17))
def __init__(self): self.loading_text = sf.Text('Initializing...') self.loading_text.character_size = 64 self.loading_text.font = sf.Font.from_file('loading.ttf') self.texture = sf.Texture.from_file("data/world16384.png") self.world = sf.Sprite(self.texture) self.video_mode = sf.VideoMode.get_fullscreen_modes()[0] vm_size = self.video_mode.width, self.video_mode.height self.world.origin = (c / 2 for c in self.texture.size) self.world.position = (c / 2 for c in vm_size) self.world.ratio = (min( v / t for t, v in zip(self.texture.size, vm_size)), ) * 2 self.original_ratio = self.world.ratio.x self.fc_logo = sf.Sprite(sf.Texture.from_file("fcbayern.png")) self.fc_logo.origin = 200, 400 self.fc_logo.position = vm_size[0] / 2, vm_size[1] / 2 - 30 self.dhl = sf.Sprite(sf.Texture.from_file("globalfamily.png")) self.dhl.origin = self.dhl.texture.size self.dhl.position = (x - 60 for x in vm_size) self.loading_text.position = vm_size[0] / 2, vm_size[1] / 2 + 30 self.loading_text.color = sf.Color(255, 255, 255, 255) self.fade = sf.RectangleShape(vm_size) self.fade.fill_color = sf.Color(0, 0, 0, 200) self.fade.position = (0, 0) self.window = sf.RenderWindow(self.video_mode, "FanMap") self.window.framerate_limit = 60 self.q = Queue() self.objects = [] self.zoomt = -1 self.zoomdirec = 0 self.target_origin = self.world.origin super().__init__()
def create_grid(self, step): self.grid_step = step self.grid_box = sf.RectangleShape((1000, 700)) self.grid_box.position = self.GRID_POS self.grid_box.outline_color = sf.Color(150, 150, 150) self.grid_box.outline_thickness = 2 self.horizontal_lines_nb = int(self.grid_box.size.y // step) self.horizontal_lines = sf.VertexArray(sf.PrimitiveType.LINES, 2 * self.horizontal_lines_nb) for y, i in zip(range(self.horizontal_lines_nb), range(0, 2 * self.horizontal_lines_nb, 2)): self.horizontal_lines[i].position = self.GRID_POS + (0, step * y) self.horizontal_lines[i + 1].position = self.GRID_POS + (self.grid_box.size.x, step * y) self.horizontal_lines[i].color = sf.Color(180, 180, 180) self.horizontal_lines[i + 1].color = sf.Color(180, 180, 180) self.vertical_lines_nb = int(self.grid_box.size.x // step) self.vertical_lines = sf.VertexArray(sf.PrimitiveType.LINES, 2 * self.vertical_lines_nb) for x, i in zip(range(self.vertical_lines_nb), range(0, 2 * self.vertical_lines_nb, 2)): self.vertical_lines[i].position = self.GRID_POS + (step * x, 0) self.vertical_lines[i + 1].position = self.GRID_POS + (step * x, self.grid_box.size.y) self.vertical_lines[i].color = sf.Color(180, 180, 180) self.vertical_lines[i + 1].color = sf.Color(180, 180, 180) self.grid = [] for j in range(self.horizontal_lines_nb + 1): self.grid.append([]) for i in range(self.vertical_lines_nb + 1): self.grid[j].append(0)
def __init__(self, target): self.target = target self.background_image = sf.Sprite( sf.Texture.from_file(target.dialog_background)) self.dialog_icon = sf.Sprite(sf.Texture.from_file(target.dialog_icon)) self.label = target.label self.next_label = self.label ### ATTENTION ^ BUG IF STRING IS EMPTY` self.name = sf.Text(target.name, sf.Font.from_file("data/font.ttf"), 40) self.name.position = 300, 475 #self.name.string = target.name self.name.color = sf.Color(241, 213, 169) #self.dialog_file = target.dialog_file with open(target.dialog_file) as data_file: self.data = json.load(data_file) #print(self.data[self.label]) #self.font = sf.Font.from_file() self.text = sf.Text(self.data[self.label]['text'], sf.Font.from_file("data/font.ttf"), 40) #self.text.string = self.data[self.label]['text'] self.text.position = 500, 610 self.text.color = sf.Color(45, 35, 18) self.answers = [] self.cursor = sf.RectangleShape() self.cursor.fill_color = sf.Color(30, 40, 50, 60) self.cursor.size = 300, 30 self.cursor.position = 50, 565 self.loadAnswers() self.texture = sf.Texture.create(window.size.x, window.size.y) self.texture.update(window) self.sprite = sf.Sprite(self.texture) self.camera = sf.View() self.camera.reset([0, 0, 1280, 800]) window.view = self.camera
def __init__(self, tiledmap, xml: ElementTree.Element): super().__init__() self.xml = xml self.map = tiledmap self.id = int(self.xml.get('id')) self.name = self.xml.get('name') color = self.xml.get('color') if color: if len(color) == 9: self.color = sf.Color(int(color[3:5], 16), int(color[5:7], 16), int(color[7:9], 16), int(color[1:3], 16)) else: self.color = sf.Color(int(color[1:3], 16), int(color[3:5], 16), int(color[5:7], 16), 255) else: self.color = sf.Color(100, 100, 100, 160) self.rectangles = [] self.points = [] self.ellipses = [] self.polygons = [] self.lines = [] self._render_texture = sf.RenderTexture( tiledmap.width * tiledmap.tile_width, tiledmap.height * tiledmap.tile_height) self.sprite = sf.Sprite(self._render_texture.texture)
def update(self, player, time): x_pos = player.sprite.position.x y_pos = player.sprite.position.y if self.transparent: if inPolygon(x_pos, y_pos, self.x_transparent, self.y_transparent): if self.is_transparent == False: self.is_transparent = True self.sprite.texture = self.transparent_texture self.sprite.color = sf.Color(255, 255, 255, 125) else: if self.is_transparent == True: self.is_transparent = False self.sprite.texture = self.texture self.sprite.color = sf.Color(255, 255, 255, 255) if self.solid: if inPolygon(x_pos, y_pos, self.x_solid, self.y_solid): player.sprite.move([ player.x_speed * time * player.movespeed * (-1), player.y_speed * time * player.movespeed * (-1) ]) x_pos = player.magic_hand.position.x y_pos = player.magic_hand.position.y if self.usable: if inPolygon(x_pos, y_pos, self.x_usable, self.y_usable): if not self.is_usable: self.is_usable = True self.sprite.texture = self.usable_texture player.usable_counter = self else: if self.is_usable: self.is_usable = False self.sprite.texture = self.texture
def resolve_color(self, time, maxbound): if self.pi.ltt <= 0: self.fill_color = sf.Color(255, 100, 100) else: color = (1 - max(time - self.pi.ltt, 0) / maxbound) g = int(round(color**3 * 255)) self.fill_color = sf.Color(60, g, 50)
def _color(self, i): colors = (sf.Color(0x00, 0x00, 0xAA), sf.Color(0x88, 0xDD, 0xFF), sf.Color(0xFF, 0x88, 0x00), sf.Color.BLACK) if i == self._iterations: return colors[-1] else: choice = (i // 2) % len(colors) return colors[choice]
def draw(self, target, states, selected=False): if selected != self.selected: self.selected = selected c = sf.Color.WHITE if selected else sf.Color( 255, 255, 0) if self.border.quirky else sf.Color(0, 0, 0, 16) for i in [0, 1]: self[i].color = c target.draw(self, states)
def _redraw_healthbar(self): self.bar_green_len = int(10*max(self.health, 0)/100) self.bar_green = create_rect( 0, 0, self.bar_green_len, 2, sf.Color(0, 140, 0)) self.bar_red = create_rect( self.bar_green_len, 0, 10-self.bar_green_len, 2, sf.Color(130, 0, 0)) if self.health == 0: self.sprite.color = sf.Color(100, 100, 100, 150)
def nuklearSfmlDrawRectOutline(self,cmd,window): p=pynk.ffi.cast("struct nk_command_rect*",cmd) rect=sf.RectangleShape() rect.size=sf.Vector2(p.w, p.h) rect.position=sf.Vector2(p.x, p.y) rect.outline_thickness=p.line_thickness rect.fill_color=sf.Color(0,0,0,0) rect.outline_color=sf.Color(p.color.r, p.color.g, p.color.b, p.color.a) window.draw(rect)
def nuklearSfmlDrawLine(self,cmd,window): p=pynk.ffi.cast("struct nk_command_line*",cmd) rect=sf.RectangleShape() rect.size=sf.Vector2(p.line_thickness, abs(p.begin.y-p.end.y)) rect.position=sf.Vector2(p.begin.x, p.begin.y) rect.outline_thickness=p.line_thickness rect.fill_color=sf.Color(p.color.r, p.color.g, p.color.b, p.color.a) rect.outline_color=sf.Color(p.color.r, p.color.g, p.color.b, p.color.a) window.draw(rect)
def __init__(self, poly, centroid, isClosed): self.poly = poly sf.Drawable.__init__(self) self.blackBorder = SFLineStrip(poly + [poly[0]], col=sf.Color.BLACK) if isClosed: self.triFan = SFTriFan([centroid] + poly + [poly[0]], col=sf.Color(0, 0, 0, 128)) else: self.triFan = SFTriFan([centroid] + poly, col=sf.Color(0, 0, 0, 32))
def __init__(self, position, fill_color): super().__init__() self.growing = True self.sprite = sf.CircleShape(33) self.sprite.fill_color = sf.Color(fill_color.r, fill_color.g, fill_color.b, 50) self.sprite.position = position - sf.Vector2(0, 5) self.sprite2 = sf.CircleShape(50) self.sprite2.fill_color = sf.Color(fill_color.r, fill_color.g, fill_color.b, 190) self.sprite2.position = position - sf.Vector2(0, 5)
def __init__(self, id, x, y, w, default=50): super().__init__() self.id = id self.x = x self.y = y self.w = w self.slider_x = x + int(w * (default / 100.0)) self.last_slider_x = self.slider_x self.rect_1 = create_rect(self.x, self.y + 4, self.w, 4, sf.Color(25, 25, 25)) self.rect_2 = create_rect(self.x, self.y, 3, 12, sf.Color(200, 200, 200)) self.rect_2.origin = (1, 0) self.clicked = False
def _render(self): self.hwnd.clear(sf.Color(18, 176, 255)) if self.state in self.render_callbacks: self.render_callbacks[self.state](()) self.ui.draw(self.hwnd)
def post_process_one_core(self, histogram, maxv): img = sf.Image.create(400, 400) #img.create(2048, 2048) freq = 0 color = 0 alpha = 0 freqArchive = np.zeros((400, 400)) for i in range(400): for y in range(400): #freq = histogram[y][i][0] #color = histogram[y][i][1] for a in range(5): for b in range(5): freq = histogram[5 * y + b][5 * i + a][0] color = histogram[5 * y + b][5 * i + a][1] if (freq != 0 and maxv > 1): alpha += color * pow( (math.log(freq, 10) / math.log(maxv, 10)), 1 / 2.2) #print(alpha) freqArchive[y][i] += histogram[5 * y + b][5 * i + a][ 0] #histogram[y][i][0] pass on alpha /= 25 col = sf.Color(alpha * 255, alpha * 255, alpha * 255, 255) img[(y, i)] = col self.gaussian_density_blur(freqArchive, img) img.to_file("ifs.png")
def circle(window, colors, pos, radius, outline_thickness=0): o = sf.CircleShape() o.radius = radius o.outline_thickness = outline_thickness try: o.outline_color = sf.Color(colors[1][0], colors[1][1], colors[1][2]) except: o.outline_color = sf.Color(0, 0, 0) o.fill_color = sf.Color(colors[0][0], colors[0][1], colors[0][2]) o.origin = (0, 0) o.position = pos window.draw(o) return o
def populate(self, json_body, quality = 100): self.a = json_body["orbit"]["semimajor"] self.e = json_body["orbit"]["eccentricity"] self.incl = json_body["orbit"]["inclination"] self.peri = json_body["orbit"]["arg_of_peri"] self.col = json_body["color"] ## compute semiminor axis from definitions of f (focal point) and e (eccentricity): f^2 = a^2 - self^2, e = f/a => self = a*sqrt(-e^2 + 1) self.b = self.a * math.sqrt(-self.e**2 + 1) ## create the body's orbit using sfml's convex shape object self.ellipse.point_count = quality ## draw as many points as 'quality' goes for i in range(quality): theta = math.pi * 2.0 * i / quality self.ellipse.set_point(i, (self.a * math.cos(theta) * math.cos(self.incl * 2. * math.pi / 360.), self.b * math.sin(theta))) self.ellipse.fill_color = sf.Color.TRANSPARENT self.ellipse.outline_color = sf.Color(self.col[0], self.col[1], self.col[2], self.col[3]) ## scale the thickness as semimajor increases (might need tweaking for very big/small orbits) self.ellipse.outline_thickness = 0.015 * self.a ## place the shape's origin at (-focus, 0) so that its origin is the same as the sun's focus = self.a * self.e self.ellipse.origin = (-focus, 0) ## we can then rotate it according to its 'Argument of perihelion' self.ellipse.rotate(self.peri)
def nuklearSfmlDrawRectFilled(self,cmd,window): p=pynk.ffi.cast("struct nk_command_rect_filled*",cmd) rectangle=sf.RectangleShape() rectangle.fill_color=sf.Color(p.color.r, p.color.g, p.color.b, p.color.a) rectangle.size=sf.Vector2(p.w, p.h) rectangle.position=sf.Vector2(p.x, p.y) window.draw(rectangle)
def init(self): ## load some textures # bakground texture stars_t = self.res.load_tex("stars.jpg") # sun texture sun_t = self.res.load_tex("sun.png") ## set up the background self.background = sf.Sprite(stars_t) scale = self.scn.get_window_size().x / stars_t.size.x self.background.scale((scale, scale)) self.background.move((0, 0)) # make it a little fainter self.background.color = sf.Color(255, 255, 255, 150) ## parse the solar system data self.system_data = resource.parse_json("system.json") ## populate a dictionary of bodies for body_data in self.system_data["bodies"]: self.bodies[body_data["name"]] = body.Body() self.bodies[body_data["name"]].populate(body_data) self.sun = sf.Sprite(sun_t) self.sun.origin = (sun_t.size.x / 2., sun_t.size.y / 2.) self.sun.scale((0.001, 0.001)) ## initialize the views self.bgview = self.scn.default_view() self.bodyview = self.scn.default_view() # TODO setup so that initial view shows orbit of earth self.bodyview.move(-self.scn.size().x / 2., -self.scn.size().y / 2.) self.bodyview.zoom(0.005)
def draw(self, window): """ Draw this widget in window. Parameters: window (Window) : Window to draw. """ self.__canvas.clear(sf.Color(155, 155, 155)) self.__canvas.draw(self._text) #caret if self._focused: if self._elapsed_time < 0.5: self.__caret.position = (self._text.position.x + self._text.global_bounds.width, self._text.position.y) self.__canvas.draw(self.__caret) if self._elapsed_time > 1.0: self._elapsed_time = self._elapsed_time - 1.0 self.__canvas.display() self.__sprite = sf.Sprite(self.__canvas.texture) self.__sprite.position = self._position window.draw(self.__sprite)
def __init__(self, name: str, data, gridsize: int = 16): super().__init__() self.data = data self.name = name self._anim_state = "idle" self.anims: Dict[str, Anim] = self.data.anims self.anim_player: AnimPlayer = AnimPlayer(self.anims[self._anim_state]) self.animate = False if self.anims is None else True self.sprite = sf.Sprite(self.data.texture) self.sprite.texture_rectangle = self.anims[ self.anim_state].frames[0].rectangle self.sprite.origin = self.anims[self.anim_state].frames[0].origin self.direction = sf.Vector2(1, 1) self.gx = self.sprite.position.x self.gy = self.sprite.position.y self.rx = 0 self.ry = 0 self.collision_box = self.global_bounds self.collision_box_shape = sf.RectangleShape( (self.collision_box.width, self.collision_box.height)) self.collision_box_shape.position = (self.collision_box.left, self.collision_box.top) self.collision_box_shape.fill_color = sf.Color(200, 0, 0, 150) self.gridsize = gridsize
def parse(self): # parsing properties of the layer if self.xml.find('properties'): for prop in self.xml.find('properties'): name = prop.get('name') prop_type = prop.get('type') value = prop.get('value') if prop_type == "bool": value = True if value == "true" else False elif prop_type == "int": value = int(value) elif prop_type == "float": value = float(value) elif prop_type == "color": value = sf.Color(int(value[1:3], 16), int(value[3:5], 16), int(value[5:7], 16), int(value[7:9], 16)) self.properties[name] = value self.render_texture.clear(sf.Color.TRANSPARENT) layer_data = [int(n) for n in self.xml.find('data').text.split(',')] # iterating over the tiles of the layer for j in range(self.height): self.tiles.append([]) for i in range(self.width): gid = layer_data[i + j * self.width] if gid != 0: tile = Tile(self, i, j, gid) self.tiles[j].append(tile) self.render_texture.draw(tile) else: self.tiles[j].append(None) self.render_texture.display() self.sprite.texture = self.render_texture.texture
def nuklearSfmlDrawCircleFilled(self,cmd,window): p=pynk.ffi.cast("struct nk_command_circle_filled*",cmd) circle=sf.CircleShape() circle.radius=p.h/2 circle.position=sf.Vector2(p.x, p.y) circle.fill_color=sf.Color(p.color.r, p.color.g, p.color.b, p.color.a) window.draw(circle)
def __init__(self, id, x, y, text, font, color=[25, 25, 25], size=20): self.font = sf.Font.from_file(font) self.text = sf.Text() self.text.font = self.font self.text.string = text self.text.character_size = 20 self.text.color = sf.Color(color[0], color[1], color[2]) self.text.position = (x, y)
def __init__(self, dialog, text, action): super(DialogButton, self).__init__() #self.sprite = #sf.Sprite(sf.Texture.from_file("data/texture.png")) self.text = sf.Text(text, sf.Font.from_file("data/font.ttf")) self.focused = False self.action = action self.text.color = sf.Color(133, 109, 48) self.dialog = dialog
def __init__(self, poly, verts): self.poly = poly self.verts = [verts[vi] for vi in poly.verts] sf.Drawable.__init__(self) self.blackBorder = SFLineStrip(self.verts, col=sf.Color(128, 128, 128)) self.triFan = SFTriFan([poly.centroid] + self.verts, col=sf.Color.WHITE) self.sfBorders = [SFBorder(b, verts) for b in poly.borders]
def rect(window, colors, pos, outline_thickness=0): o = sf.RectangleShape() o.position = pos[0:2] o.size = pos[2:4] o.outline_thickness = outline_thickness try: o.outline_color = sf.Color(colors[1][0], colors[1][1], colors[1][2]) except: o.outline_color = sf.Color(0, 0, 0) o.fill_color = sf.Color(colors[0][0], colors[0][1], colors[0][2]) o.origin = (0, 0) window.draw(o) return o
def nuklearSfmlDrawTriangleFilled(self,cmd,window): p=pynk.ffi.cast("struct nk_command_triangle_filled*",cmd) convex=sf.ConvexShape() convex.point_count=3 convex.set_point(0,sf.Vector2(p.a.x, p.a.y)) convex.set_point(1, sf.Vector2(p.b.x, p.b.y)) convex.set_point(2, sf.Vector2(p.c.x, p.c.y)) convex.fill_color=sf.Color(p.color.r, p.color.g, p.color.b, p.color.a) window.draw(convex)