geom-demo/geom/draw.py

42 lines
1.1 KiB
Python
Raw Normal View History

import pygame
from pygame import gfxdraw
from pygame import freetype
from . import HEIGHT, WIDTH
from .math import add
OFFSET = (WIDTH/2, HEIGHT/2)
FONT = None
def init():
global FONT
freetype.init()
FONT = freetype.SysFont('Arial', 16)
2020-11-14 11:10:22 -07:00
def line(surface, color, start, end, width=1):
pygame.draw.line(surface, color,
add(*OFFSET, *start), add(*OFFSET, *end), width)
def polygon(surface, color, vertices, width):
translated = [add(*OFFSET, *vertex) for vertex in vertices]
pygame.draw.polygon(surface, color, translated, width)
def rect(surface, color, x, y, height, width, stroke_width):
pygame.draw.rect(surface, color,
pygame.Rect(OFFSET[0] + x, OFFSET[1] + y, height, width),
stroke_width)
def pixel(surface, color, x, y):
gfxdraw.pixel(surface,
int(OFFSET[0] + x),
int(OFFSET[1] + y),
color)
def text(surface, color, position, text):
FONT.render_to(surface, add(*OFFSET, *position), text, color)
def text_screen(surface, color, position, text):
FONT.render_to(surface, position, text, color)