예제 #1
0
    def redraw(self):
        xoffset, yoffset = self.player.x - self.pos_center[
            0], self.player.y - self.pos_center[1]
        if abs(xoffset) >= self.additional // 2 or abs(
                yoffset) >= self.additional // 2:  # подгрузка
            self.pos_center = (int(self.player.x), int(self.player.y))
            self.redraw_all()
        self.draw_blocks_in_screen(1)  # чтобы солнце под землей не рисовалось
        self.sun.draw()
        self.moon.draw()
        self.draw_blocks_in_screen(2)

        for i in self.other_players.values():
            if i['model'].moving:
                i['model'].simulate_move(i['model'].model.direction, 300 / fps)
            else:
                i['model'].simulate_move(0, 300 / fps)
            i['model'].update_model(self.player.x, self.player.y)
            i['model'].model.draw(i['selected'], self.block_size)
            glLoadIdentity()
            bf = i['model'].model.get_current_tile().rect
            glTranslate(bf.x + bf.width // 2, bf.y - self.block_size // 2, 0)
            draw_text(i['name'], self.text_font, color=(225, 225, 225, 125))
        self.player.draw()
        self.draw_all_light()
예제 #2
0
 def draw(self, rect):
     glLoadIdentity()
     pos = pygame.mouse.get_pos()
     glTranslate(rect.x, rect.y, 0)
     if rect.x <= pos[0] <= rect.x + rect.width and rect.y <= pos[
             1] <= rect.y + rect.height:
         draw_resized_image(self.selected_image, rect.width, rect.height)
         if pygame.mouse.get_pressed()[0] == 1 and self.interactor.check():
             self.interactor.update()
             self.event()
     else:
         draw_resized_image(self.image, rect.width, rect.height)
     glTranslate(rect.width // 2, rect.height // 2, 0)
     draw_text(self.text, self.font)
예제 #3
0
파일: commute.py 프로젝트: knyar/accent
    def image(self, user, width, height):
        """Generates the current commute image."""

        # Extract the directions data.
        try:
            directions = self._google_maps.directions(user)
            status = directions['status']
            if status != 'OK':
                try:
                    error_message = directions['error_message']
                    raise DataError(error_message)
                except KeyError:
                    raise DataError(status)
            routes = directions['routes']
            route = routes[0]
            polyline = route['overview_polyline']['points']
            summary = route['summary']
            leg = route['legs'][0]  # Expect one leg.
            try:
                duration = leg['duration_in_traffic']['text']
            except KeyError:
                duration = leg['duration']['text']
        except (DataError, IndexError, KeyError) as e:
            raise ContentError(e)

        # Get the static map with the route as an image.
        try:
            image = self._google_maps.map_image(width,
                                                height,
                                                polyline=polyline)
        except DataError as e:
            raise ContentError(e)

        # Draw the directions text inside a centered box.
        if summary:
            directions_text = '%s via %s' % (duration, summary)
        else:
            directions_text = duration
        draw_text(directions_text,
                  font_spec=SUBVARIO_CONDENSED_MEDIUM,
                  text_color=DIRECTIONS_TEXT_COLOR,
                  anchor='center',
                  box_color=DIRECTIONS_BOX_COLOR,
                  box_padding=DIRECTIONS_BOX_PADDING,
                  border_color=DIRECTIONS_BORDER_COLOR,
                  border_width=DIRECTIONS_BORDER_WIDTH,
                  image=image)

        return image
예제 #4
0
def settings_response(key, image_func):
    """Creates an image response to start the new user flow."""

    # Draw the image with the link text and a computer.
    image = Image.new(mode='RGB', size=(DISPLAY_WIDTH, DISPLAY_HEIGHT),
                      color=BACKGROUND_COLOR)
    draw_text(settings_url(key),
              font_spec=SUBVARIO_CONDENSED_MEDIUM,
              text_color=TEXT_COLOR,
              xy=LINK_TEXT_XY,
              anchor='center_x',
              image=image)
    computer = Image.open(COMPUTER_FILE).convert(mode='RGBA')
    image.paste(computer, box=COMPUTER_XY, mask=computer)

    return image_func(image)
예제 #5
0
파일: schedule.py 프로젝트: zane-deg/accent
    def empty_timeline(self):
        """Generates an empty timeline image."""

        image = Image.new(mode='RGB',
                          size=(TIMELINE_WIDTH, TIMELINE_HEIGHT),
                          color=TIMELINE_BACKGROUND)
        draw = Draw(image)

        # Draw each day of the week.
        num_days = len(day_abbr)
        for day_index in range(num_days):
            x = TIMELINE_DRAW_WIDTH * day_index / num_days

            # Draw a dashed vertical line.
            for y in range(0, TIMELINE_HEIGHT, 2 * TIMELINE_LINE_DASH):
                draw.line([(x, y), (x, y + TIMELINE_LINE_DASH - 1)],
                          fill=TIMELINE_FOREGROUND,
                          width=TIMELINE_LINE_WIDTH)

            # Draw the abbreviated day name.
            name = day_abbr[day_index]
            day_x = x + TIMELINE_DRAW_WIDTH / num_days / 2
            day_y = TIMELINE_HEIGHT - SCREENSTAR_SMALL_REGULAR['height']
            draw_text(name,
                      SCREENSTAR_SMALL_REGULAR,
                      TIMELINE_FOREGROUND,
                      xy=(day_x, day_y),
                      anchor=None,
                      box_color=None,
                      box_padding=0,
                      border_color=None,
                      border_width=0,
                      image=image,
                      draw=draw)

        # Draw another dashed line at the end.
        for y in range(0, TIMELINE_HEIGHT, 2 * TIMELINE_LINE_DASH):
            draw.line([(TIMELINE_DRAW_WIDTH, y),
                       (TIMELINE_DRAW_WIDTH, y + TIMELINE_LINE_DASH - 1)],
                      fill=TIMELINE_FOREGROUND,
                      width=TIMELINE_LINE_WIDTH)

        return image
예제 #6
0
    def map_image(self, polyline=None, markers=None, marker_icon=None):
        """Creates a map image with optional route or markers."""

        # Get the static map as an image.
        image_data = self._download_map(polyline=polyline, markers=markers,
                                        marker_icon=marker_icon)
        image = Image.open(image_data).convert('RGB')

        # Replace the copyright text with a more readable pixel font.
        copyright_text = self._copyright_text(polyline=polyline,
                                              markers=markers,
                                              marker_icon=marker_icon)
        draw_text(copyright_text,
                  font_spec=SCREENSTAR_SMALL_REGULAR,
                  text_color=COPYRIGHT_TEXT_COLOR,
                  anchor='bottom_right',
                  box_color=COPYRIGHT_BOX_COLOR,
                  box_padding=COPYRIGHT_BOX_PADDING,
                  image=image)

        return image
예제 #7
0
파일: draw.py 프로젝트: BenchLord/Dodge
def draw():
    """
    Drawing logic
    """

    # Draw background
    game.background.draw()
    game.background2.draw()

    # Drawing a sprite called my_sprite
    # my_sprite.draw()
    if game.player.alive:
        game.player.draw()

    if game.player.alive:
        for baddie in game.baddies:
            baddie.draw()
        for coin in game.coins:
            coin.draw()

    # Draw some text
    # graphics.draw_text("Hello World", (255, 255, 255), (50, 50))
    if game.player.alive:
        graphics.draw_text("Score: " + str(game.score), (255,255,255), (10,10))
    else:
        graphics.draw_text("Final Score: " + str(game.score), (255,255,255), (210,275))
        graphics.draw_text("PRESS SPACE TO PLAY AGAIN", (255,255,255), (100,325))

    return
예제 #8
0
    def image(self, _):
        """Generates an image with MTB status"""

        resp = requests.get('https://www.trianglemtb.com')
        soup = BeautifulSoup(resp.text, 'html.parser')
        status_dict = {}
        a = soup.findAll("span")
        for item in a:
            if 'CLOSED' in item.text or 'OPEN' in item.text:
                test = item
                status_dict[test.parent.parent.parent.a.
                            text] = True if 'OPEN' in item.text else False
        status = status_dict
        trail_num = len(status.keys())
        # Create a blank image.
        image = Image.new(mode='RGB',
                          size=(DISPLAY_WIDTH, DISPLAY_HEIGHT),
                          color=BACKGROUND_COLOR)
        draw = Draw(image)
        # Determine the spacing of the trails in the image.
        y_stride = DISPLAY_HEIGHT // (trail_num + 1)

        #Draw title text
        draw_text('Mountain Bike',
                  SCREENSTAR_LARGE_REGULAR,
                  TEXT_COLOR,
                  xy=(200, (DISPLAY_HEIGHT / 2) - 20),
                  image=image)
        draw_text('Trail Status',
                  SCREENSTAR_LARGE_REGULAR,
                  TEXT_COLOR,
                  xy=(200, (DISPLAY_HEIGHT / 2)),
                  image=image)

        # Draw each trail status
        trails = list(status.keys())
        for trail_index in range(trail_num):

            if not status[trails[trail_index]]:
                bg_color = HIGHLIGHT_COLOR
                color = HIGHLIGHT_COLOR
            else:
                color = TEXT_COLOR
                bg_color = None

            y = (trail_index + 1) * y_stride
            draw_text(str(trails[trail_index]),
                      SUBVARIO_CONDENSED_MEDIUM,
                      TEXT_COLOR,
                      xy=(400, y - NUMBER_Y_OFFSET),
                      image=image,
                      box_color=bg_color)

            dot = Image.open(DOT_FILE).convert(mode='RGBA')
            dot = dot.resize((15, 15))
            dot_xy = [600, y - dot.width // 2]
            draw.bitmap(dot_xy, dot, color)

        return image
예제 #9
0
    def image(self, user, width, height):
        """Generates an image with a calendar view."""

        # Show a calendar relative to the current date.
        try:
            time = self._local_time.now(user)
        except DataError as e:
            raise ContentError(e)

        # Get the number of events per day from the API.
        event_counts = self._event_counts(time, user)

        # Create a blank image.
        image = Image.new(mode='RGB',
                          size=(width, height),
                          color=BACKGROUND_COLOR)
        draw = Draw(image)

        # Get this month's calendar.
        try:
            firstweekday = WEEK_DAYS[user.get('first_week_day')]
        except KeyError:
            firstweekday = SUNDAY
        calendar = Calendar(firstweekday=firstweekday)
        weeks = calendar.monthdayscalendar(time.year, time.month)

        # Determine the spacing of the days in the image.
        x_stride = width // (DAYS_IN_WEEK + 1)
        y_stride = height // (len(weeks) + 1)

        # Draw each week in a row.
        for week_index in range(len(weeks)):
            week = weeks[week_index]

            # Draw each day in a column.
            for day_index in range(len(week)):
                day = week[day_index]

                # Ignore days from other months.
                if day == 0:
                    continue

                # Determine the position of this day in the image.
                x = (day_index + 1) * x_stride
                y = (week_index + 1) * y_stride

                # Mark the current day with a squircle.
                if day == time.day:
                    squircle = Image.open(SQUIRCLE_FILE).convert(mode='RGBA')
                    squircle_xy = (x - squircle.width // 2,
                                   y - squircle.height // 2)
                    draw.bitmap(squircle_xy, squircle, HIGHLIGHT_COLOR)
                    number_color = TODAY_COLOR
                    event_color = TODAY_COLOR
                else:
                    number_color = NUMBER_COLOR
                    event_color = HIGHLIGHT_COLOR

                # Draw the day of the month number.
                number = str(day)
                draw_text(number,
                          SUBVARIO_CONDENSED_MEDIUM,
                          number_color,
                          xy=(x, y - NUMBER_Y_OFFSET),
                          image=image)

                # Draw a dot for each event.
                num_events = min(MAX_EVENTS, event_counts[day])
                dot = Image.open(DOT_FILE).convert(mode='RGBA')
                if num_events > 0:
                    events_width = (num_events * dot.width +
                                    (num_events - 1) * DOT_MARGIN)
                    for event_index in range(num_events):
                        event_offset = (event_index *
                                        (dot.width + DOT_MARGIN) -
                                        events_width // 2)
                        dot_xy = [
                            x + event_offset, y + DOT_OFFSET - dot.width // 2
                        ]
                        draw.bitmap(dot_xy, dot, event_color)

        return image
예제 #10
0
 def draw(self, rect):
     glLoadIdentity()
     glTranslate(rect.x, rect.y, 0)
     draw_text(self.text, self.font, translate_x=False)
예제 #11
0
파일: schedule.py 프로젝트: knyar/accent
    def timeline(self, user):
        """Generate a timeline image of the schedule for settings."""
        image = self.empty_timeline()
        draw = Draw(image)

        # Find the user or return the empty timeline.
        try:
            now = self._local_time.now(user)
        except DataError as e:
            return image

        # Start the timeline with the most recent beginning of the week.
        start = now.replace(hour=0, minute=0, second=0)
        start -= timedelta(days=start.weekday())
        stop = start + timedelta(weeks=1)
        start_timestamp = datetime.timestamp(start)
        stop_timestamp = datetime.timestamp(stop)
        timestamp_span = stop_timestamp - start_timestamp

        # Draw a dashed line in highlight color at the current time.
        now_timestamp = datetime.timestamp(now)
        now_x = TIMELINE_DRAW_WIDTH * (now_timestamp -
                                       start_timestamp) / timestamp_span
        for y in range(0, TIMELINE_HEIGHT, 2 * TIMELINE_LINE_DASH):
            draw.line([(now_x, y), (now_x, y + TIMELINE_LINE_DASH - 1)],
                      fill=TIMELINE_HIGHLIGHT,
                      width=TIMELINE_LINE_WIDTH)

        # Generate the schedule throughout the week.
        entries = user.get('schedule')
        if not entries:
            # Empty timeline.
            return image
        for i in range(len(entries)):
            entries[i]['index'] = i
        time = start
        while time < stop:
            # Find the next entry.
            next_entries = [(self._next(entry['start'], time,
                                        user), entry['index'], entry)
                            for entry in entries]
            next_datetime, next_index, next_entry = min(next_entries,
                                                        key=lambda x: x[0])

            # Draw the entry's index and a vertical line, with a tilde to mark
            # the variable sunrise and sunset times.
            timestamp = datetime.timestamp(next_datetime)
            x = TIMELINE_DRAW_WIDTH * (timestamp -
                                       start_timestamp) / timestamp_span
            y = TIMELINE_HEIGHT / 2
            text = str(next_index + 1)
            next_entry_start = next_entry['start']
            if 'sunrise' in next_entry_start or 'sunset' in next_entry_start:
                text = '~' + text
            box = draw_text(text,
                            SCREENSTAR_SMALL_REGULAR,
                            TIMELINE_FOREGROUND,
                            xy=(x, y),
                            anchor=None,
                            box_color=None,
                            box_padding=4,
                            border_color=None,
                            border_width=0,
                            image=image,
                            draw=draw)
            draw.line([(x, 0), (x, box[1])], fill=TIMELINE_FOREGROUND, width=1)

            # Jump to the next entry.
            time = next_datetime

        return image
예제 #12
0
파일: draw.py 프로젝트: alveyworld-dev/game
def draw_hud():
    """
    This is seperate mearly for simplicity
    """

    graphics.draw_text("Score: " + str(game.score), (14, 14, 14), (25, 25))