def __init__(self, tilesx, tilesy, posx, posy): self.tilesx = tilesx self.tilesy = tilesy self.font = pyglet.image.load(data_path("tiles.png")).get_texture() self.ch_tex = Texture(tilesx, tilesy, GL_RED, GL_UNSIGNED_BYTE) self.fg_tex = Texture(tilesx, tilesy, GL_RGB, GL_UNSIGNED_BYTE) self.bg_tex = Texture(tilesx, tilesy, GL_RGB, GL_UNSIGNED_BYTE) self.shader = Shader(data_file("tiles.vert"), data_file("tiles.frag")) self.shader.bind() self.shader.uniformf("ntiles", tilesx, tilesy) self.shader.uniformf("potsize", self.ch_tex.pot_width, self.ch_tex.pot_height) self.shader.uniformf("fontscale", self.font.tex_coords[6], self.font.tex_coords[7]) self.shader.uniformf("fontbg", 1.0, 0.0, 1.0) self.shader.uniformf("nchars", 16.0, 16.0) self.shader.unbind() self.batch = pyglet.graphics.Batch() w = tilesx * self.CHAR_WIDTH h = tilesy * self.CHAR_HEIGHT self.batch.add( 4, GL_QUADS, None, ("v2f/static", (posx, posy, posx + w, posy, posx + w, posy + h, posx, posy + h)), ("t2f/static", (0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0)))
def __init__(self): self.image_opened = image.load(data_file('garbagecan-open.png')) self.image_closed = image.load(data_file('garbagecan-closed.png')) self.image_lid = image.load(data_file('garbagecan-lid.png')) self.image_opened.anchor_x = self.image_opened.width/2 self.image_opened.anchor_y = self.image_opened.height/2 self.image_closed.anchor_x = self.image_opened.width/2 self.image_closed.anchor_y = self.image_opened.height/2 self.candidateLeaves = {} self.opened = True self.lid_active = False self.can_active = False self.fallen = False self.can_highlighted = False self.lid_highlighted = True self.can_rect = Rect(0, 0, self.image_closed) self.can_rect.center = (80, 90) self.can_sprite = Sprite(self.image_opened) self.can_sprite.set_position(self.can_rect.x, self.can_rect.y) self.lid_rect = Rect(20, 40, self.image_lid) window.game_window.push_handlers(self.on_mouse_release) window.game_window.push_handlers(self.on_mouse_press) window.game_window.push_handlers(self.on_mouse_drag) window.game_window.push_handlers(self.on_mouse_motion) events.AddListener(self)
def __init__(self, tilesx, tilesy, posx, posy): self.tilesx = tilesx self.tilesy = tilesy self.font = pyglet.image.load(data_path("tiles.png")).get_texture() self.ch_tex = Texture(tilesx, tilesy, GL_RED, GL_UNSIGNED_BYTE) self.fg_tex = Texture(tilesx, tilesy, GL_RGB, GL_UNSIGNED_BYTE) self.bg_tex = Texture(tilesx, tilesy, GL_RGB, GL_UNSIGNED_BYTE) self.shader = Shader( data_file("tiles.vert"), data_file("tiles.frag") ) self.shader.bind() self.shader.uniformf("ntiles", tilesx, tilesy) self.shader.uniformf("potsize", self.ch_tex.pot_width, self.ch_tex.pot_height) self.shader.uniformf("fontscale", self.font.tex_coords[6], self.font.tex_coords[7]) self.shader.uniformf("fontbg", 1.0, 0.0, 1.0) self.shader.uniformf("nchars", 16.0, 16.0) self.shader.unbind() self.batch = pyglet.graphics.Batch() w = tilesx * self.CHAR_WIDTH; h = tilesy * self.CHAR_HEIGHT self.batch.add( 4, GL_QUADS, None, ("v2f/static", (posx, posy, posx+w, posy, posx+w, posy+h, posx, posy+h)), ("t2f/static", (0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0)) )
def queue_soundtrack(song='8bp069-06-she-streets.mp3', soundtrack=None): if not soundtrack: soundtrack = media.Player() soundtrack.eos_action = 'loop' soundtrack.queue(media.load(data_file(song))) return soundtrack
def __init__(self): self.images = [ image.load(data_file('fire0.png')), image.load(data_file('fire2.png')), image.load(data_file('fire1.png')), ] self.image = self.images[0] pos = (randint(140, 350), randint(270, 400)) self.rect = Rect(pos[0], pos[1], self.image) self.lives = 3 self.delay = 0.2 self.timer = self.delay self.image_count = 0
def __init__(self): self.current_phase = 0 self.days_until_phasechange = 2 self.phases = [image.load(data_file('moon-full.png')), ] self.deg = 0 OrbitingObject.__init__(self)
def __init__(self): GrillObject.__init__(self) self.image = image.load(data_file('beef.png')) self.rect = Rect(520, 230, self.image) self.cooking = False self.reset()
def __init__(self): GrillObject.__init__(self) self.image = image.load(data_file('spritzer.png')) self.rect = Rect(600, 20, self.image) self.drop_range = (50, 100) self.build_drop() self.reset()
def __init__(self): self.image = image.load(data_file('grill.png')) self.rect = Rect(500, 250, self.image) window.game_window.push_handlers(self.on_mouse_press) window.game_window.push_handlers(self.on_mouse_motion) self.highlighted = False self.active = False
def __init__(self, mower): self.street = image.load(data_file('street.png')) self.house = image.load(data_file('house.png')) self.fence_left = image.load(data_file('fence-left.png')) #self.truck = image.load(data_file('truck.png')) self.dogpiss = image.load(data_file('dogpiss.png')) self.mower = mower self.lawn = [] self.unsmearedPoos = [] self.current_segment = 0 for y in range(130, 260, 10): for x in range(0, SCREEN_WIDTH, 40): # only build up to the edge of the lawn if x > 440 + (y - 130) / 10 * 20: continue self.lawn.append( LawnSegment(len(self.lawn), rect=Rect(x, y, 40, 10))) self.rebuild_time = 0.5 self.rebuild_counter = self.rebuild_time # randomly update the various segments of the lawn self.update_list = range(0, len(self.lawn)) random.shuffle(self.update_list) self.green_value = 0.3 self.green_time = 1 self.green_counter = self.green_time self.segment = len(self.lawn) - 1 self.mow_time = 0.2 self.mow_counter = self.mow_time self.mowing = False events.AddListener(self)
def create_db(self, dbfile): self.con = sqlite3.connect( data_file(dbfile) if dbfile != ':memory:' else dbfile, ) self.execute( 'create table if not exists ' 'fc(feature, category, count, unique(feature, category))' ) self.execute('create table if not exists ' 'cc(category primary key, count) ' )
def direct_find(title, exact=False): normalized_title = normalize(title) hash = abs(java_string_hashcode(normalized_title)) % NUM_PARTITIONS prefix = normalized_title + '\t' articles = [] with open(util.data_file('wikinet/partitions/%04x' % hash)) as fh: for line in fh: if line.startswith(prefix): article = from_tsv(line) if not exact or article.title == title: articles.append(article) return articles
def __init__(self, color, cloud_position): self.image = image.load(data_file('cloud.png')) cloud_min, cloud_max = CLOUD_COVERAGE[CURRENT_CLOUD_COVERAGE] pos_min = int((cloud_position - 1) / float(cloud_max) * SCREEN_WIDTH) pos_max = int(cloud_position / float(cloud_max) * SCREEN_WIDTH) self.pos = euclid.Vector2(randint(pos_min, pos_max), SCREEN_HEIGHT - randint(40, 100)) self.color = color self.hsv_color = [0.666, 1, 1] self.alpha = 0 self.state = 'spawning'
def __init__(self): self.image = image.load(data_file('biggrill.png')) self.beef = Beef() self.spritzer = Spritzer() self.table = Table() self.exit = Exit() self.rect = Rect(150, 300, 300, 200) self.flareups = [] self.flareup_range = (10, 50) self.flareup_counter = randint(*self.flareup_range) / 10.0 window.game_window.push_handlers(self.on_mouse_press) window.game_window.push_handlers(self.on_mouse_release) window.game_window.push_handlers(self.on_mouse_motion) #events.AddListener(self) self.active = False self.beef_hint_done = False self.flareup_hint_done = False
def __init__(self): self.image = image.load(data_file('back.png')) self.rect = Rect(700, 500, 100, 100)
if nb_dir not in sys.path: sys.path.append(nb_dir) import pandas as pd import numpy as np from util import data_file import seaborn as sns sns.set(color_codes=True) df = pd.read_table(data_file('Inputs','train.csv'),sep=',') df.columns comments = [c[1:-1] for c in df.Comment] # strip offleading and trailing '"' chars) comment_lengths = [len(c) for c in comments] print("Number of comments is " + str(len(comment_lengths))) print("Longest comment is " + str(max(comment_lengths))) # remove extremes n = 1 # num standard deviations comment_lengths = [x for x in comment_lengths if abs(x - np.mean(comment_lengths)) < np.std(comment_lengths) * n]
def __init__(self): OrbitingObject.__init__(self) self.image = image.load(data_file('sun.png')) self.deg = 180
def __init__(self): self.image = image.load(data_file('table-corner.png')) self.rect = Rect(570, -20, 200, 150)
import cPickle as pickle from util import data_file import os klass_path = lambda klass: data_file(klass.__name__.lower()) klass_name_path = lambda klass, name: os.path.join(klass_path(klass), name + '.pickle') class Pickleable(object): __cache = {} @classmethod def load_or_gen(klass, name, *args, **kwargs): try: return klass.load(name) except ValueError: value = klass.gen(name, *args, **kwargs) klass.save(name, value) return value @classmethod def load(klass, name): parent_path = klass_path(klass) path = klass_name_path(klass, name) if path in klass.__cache: return klass.__cache[path] if not os.path.exists(parent_path): os.makedirs(parent_path) if not os.path.exists(path): raise ValueError(path)
import requests import requests_cache from util import data_file from parsers import get_page_content_cc, iter_pages requests_cache.install_cache(data_file('cache')) def wget(url): r = requests.get(url) if r.status_code == 200: return r.text class Spider(object): def __init__(self, train_f): self.train_f = train_f def parse_blog(self, url): if not url.endswith('/'): # url must end with slash url = url + '/' sitemap = wget(url + 'sitemap.xml') for page in iter_pages(sitemap): if is_article(page): self.parse_page(page) def parse_page(self, page): print print page text = wget(page)