graphics_engine.py

Created by valmontechno

Created on June 12, 2024

978 Bytes


import kandinsky as kd
kd = kd
from v_math import *

WIDTH = 320
HEIGHT = 222
TOP = 0

Vector2.setScreenSize(WIDTH, HEIGHT)

def drawEdge(edge:Edge2, color):
    v1, v2 = edge.v1, edge.v2
    dx = abs(v2.x - v1.x)
    sx = 1 if v1.x < v2.x else -1
    dy = -abs(v2.y - v1.y)
    sy = 1 if v1.y < v2.y else -1
    er = dx + dy
    while True:
        if 0 <= v1.x <= WIDTH and TOP <= v1.y <= HEIGHT:
            kd.set_pixel(v1.x, v1.y, color)
        if v1.x == v2.x and v1.y == v2.y:
            break
        e2 = 2 * er
        if e2 >= dy:
            if v1.x == v2.x: break
            er += dy
            v1.x += sx
        if e2 <= dx:
            if v1.y == v2.y: break
            er += dx
            v1.y += sy

def logNumber(number:float, position:Vector2, color, length:int=6, decimals:int=2):
    number = ('{:>' + str(length) + '.' + str(decimals) + 'f}').format(number)
    kd.draw_string(number, position.x, position.y, '#ffffff', color)