Exemple #1
0
def get_fonts(font_directory=DEFAULT_FONT_DIRECTORY,
              font_url=DEFAULT_FONT_URL):
    """
    If needed, download the font from the given URL and install them into the given directory.

    :param font_directory: the installation directory for the fonts.
    :type font_url: the URL where the fonts can be retrieved from.

    """
    if not exists(font_directory):
        mkdir(font_directory)

    # Retrieve the available fonts from the given directory, if possible.
    fonts = [
        create_font(join(font_directory, font.lower()), DEFAULT_FONT_SIZE)
        for font in listdir(font_directory)
        if font.lower().endswith(DEFAULT_FONT_EXTENSION)
        and isfile(join(font_directory, font))
    ]

    # Get fonts from the given website and install then into the given directory.
    if not fonts:
        temp_directory = mkdtemp()
        temp_file = mkstemp('.zip', None, temp_directory)

        response = get(font_url)
        soup = BeautifulSoup(response.content, 'html.parser')

        for el in soup.find_all('a', class_='download'):
            link = el['href']
            response = get(font_url + "../.." + link)
            with open(temp_file[1], 'wb') as file:
                file.write(response.content)
            with ZipFile(temp_file[1], 'r') as zip_file:
                zip_file.extractall(temp_directory)

        close(temp_file[0])

        for (root, dirs, files) in walk(temp_directory):
            for file in files:
                if not file.lower().startswith('.') and file.lower().endswith(
                        DEFAULT_FONT_EXTENSION):
                    copy(join(root, file), font_directory)
                    fonts.append(
                        create_font(join(font_directory, file.lower()),
                                    DEFAULT_FONT_SIZE))

        rmtree(temp_directory)

    return fonts
    def displayWord(self, word):
        self.word = word
        self.wordLength = len(word)
        self.spacing = (self.width / (self.wordLength)) / 2

        self.offset = (width / 2 - self.width / 2) + self.spacing / 2

        self.txt_size = int(self.spacing * 4 / 3)
        self.GuessFont = p5.create_font("arial.ttf", self.txt_size)
        p5.text_font(self.GuessFont, self.txt_size)
        p5.text_align("CENTER", "BASELINE")
        self.txt_width = p5.text_width("A")

        for i in range(self.wordLength):
            p5.fill(255)
            p5.text(word[i],
                    ((i * 2 * self.spacing) + self.spacing / 2 + self.offset,
                     self.y - (self.txt_width * 4 / 3) - 2))
            p5.line((i * 2 * self.spacing + self.offset, self.y),
                    (((i * 2) + 1) * self.spacing + self.offset, self.y))
Exemple #3
0
from PIL import Image
import time
from reply_processer import *

t0 = time.time()
""" Global Variables """
mid = 546195  # 老番茄

root = "./ups/mid-{}/".format(mid)
frame_path = root + "frames/"
if not os.path.exists(frame_path):
    os.mkdir(frame_path)
cover_path = root + "covers/"
info_path = root + "infos/"

font = pf.create_font("C:/windows/fonts/arialuni.ttf", 16)

# with open(info_path+"{}-vlist.json".format(mid), "r") as rf:
#     jsn = json.load(rf)

# vinfo_L: list
# each row: {aid: *, created: *, title: *, pic_url: *, length: *}, sorted by aid
with open(info_path + "vinfo.pkl", "rb") as rf:
    vinfo_L = pickle.load(rf)
# ninfo_L: 2d list (video_num x ct_group_cnt)
# each row: list of accumulate floor count of all ctime groups
with open(info_path + "ninfo.pkl", "rb") as rf:
    ninfo_L = pickle.load(rf)
# ct_L: list (1 x ct_group_cnt)
# ctime group point
with open(info_path + "tinfo.pkl", "rb") as rf:
def draw():
    global Man, wordDisplay, newLetter, Game
    p5.background(0)
    p5.fill(255)
    p5.stroke(255)
    p5.stroke_weight(1)
    if not Man.GameWon and not Man.GameOver:
        wordDisplay.displayWord(Game.revealed)
    p5.fill(255)
    p5.stroke(255)
    Man.draw()
    if not Man.GameWon and not Man.GameOver:
        if key_is_pressed:
            if key not in [
                    "ENTER", "SHIFT", "BACKSPACE", "UNKNOWN", "tab", "UP",
                    "DOWN", "LEFT", "RIGHT"
            ]:
                newLetter = str(key).lower()
            elif key == "BACKSPACE":
                newLetter = ""
            elif key == "ENTER":
                if len(newLetter
                       ) != 0 and newLetter not in Game.guessedLetters:
                    Game.enterLetter(newLetter, Man)
                    newLetter = ""

    if len(newLetter) != 0:
        txt_size = 40
        EnteredLetterFont = p5.create_font("arial.ttf", txt_size)
        p5.text_font(EnteredLetterFont, txt_size)
        p5.text_align("CENTER", "CENTER")
        p5.text(newLetter, (width / 2, height * 3 / 4 - 20))

    guessedLettersstring = ""
    for i in range(len(Game.guessedLetters)):
        guessedLettersstring += Game.guessedLetters[i]
        guessedLettersstring += " "

    guessedLetterFont = p5.create_font("arial.ttf", 20)
    p5.text_font(guessedLetterFont, 20)

    p5.text_align("CENTER", "CENTER")
    p5.text(("Already used Letters:"), (width / 2, height * 7 / 8))
    p5.text(str(guessedLettersstring), (width / 2, (height * 7 / 8) + 25))

    Man.checkIfGameOver(Game)

    if Man.GameWon:
        txt_size = 30
        #txt_size=int((width/7)*4/3)
        GameWonFont = p5.create_font("arial.ttf", txt_size)
        p5.text_font(GameWonFont, txt_size)
        p5.text_align("CENTER", "CENTER")
        p5.text("YOU WON", (width / 2, height / 2))
        p5.text("The Right word was:", (width / 2, height / 2 + 30))
        p5.text("{}".format(word), (width / 2, height / 2 + 60))
        newLetter = ""
    if Man.GameOver:
        txt_size = 30
        #txt_size=int((width/9)*4/3)
        GameOverFont = p5.create_font("arial.ttf", txt_size)
        p5.text_font(GameOverFont, txt_size)
        p5.text_align("CENTER", "CENTER")
        p5.text("YOU LOST", (width / 2, height / 2))
        p5.text("The Right word was:", (width / 2, height / 2 + 30))
        p5.text("{}".format(word), (width / 2, height / 2 + 60))
        newLetter = ""