geom-demo/geom/draw.py
Matt Low c313b3e8ba Refactors
- Move all pygame draw calls into draw module
- Scrap indvidual shape modules for single 'geom' module
- Center of screen is now 0,0
2020-11-14 21:15:47 +04:00

42 lines
1.1 KiB
Python

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)
def line(surface, color, start, end, width=0):
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)