Untitled
unknown
python
2 years ago
2.0 kB
16
Indexable
#7font test
#pip install pygame
#^^^раскомменитровать, если нет библиотеки^^^
import pygame
# Инициализация Pygame
pygame.init()
BLACK = (0, 0, 0)
GREY = (235, 235, 235)
WHITE = (255, 255, 255)
# Определение базы
WIDTH = 335
HEIGHT = 300
FPS = 30
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Fonts")
clock = pygame.time.Clock()
class font_7s: #класс для семисегментного шрифта с фоном.
def __init__(self, len, size=112, color = BLACK, b_color = GREY):
self.len = len
self.x = 40
self.y = 40
self.value = "".join(" " for i in range(self.len-1)) + "0"
self.value_b = "8" * self.len
self.size = size
self.color = color
self.b_color = b_color
def draw(self):
font_7s_file = 'SevenSegmentiments-ywMVM.ttf'
font_7s = pygame.font.Font(font_7s_file, self.size)
font_7s_render = font_7s.render(self.value, False,
self.color) #значение
b_font_7s_render = font_7s.render(self.value_b, False,
self.b_color) #красивый аутентичный фон из восьмёрочек
#отрисовываем:
screen.blit(b_font_7s_render, (self.x, self.y))
screen.blit(font_7s_render, (self.x, self.y))
def inc(self, num=1):
if self.value != self.len * "9":
self.value = str(int(self.value)+num)
self.value = "".join(" " for i in range(self.len-len(self.value))) + self.value
score = font_7s(3)
speed = font_7s(2)
speed.y = 150 #пониже чтоб второй
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
screen.fill(WHITE)
score.draw()
speed.draw()
score.inc()
speed.inc()
pygame.display.flip()
clock.tick(FPS)
# Выход из Pygame
pygame.quit()Editor is loading...
Leave a Comment