コード例 #1
0
def draw_text(canvas: CANVAS, txt: str, color: (int, int, int), pos: (int, int), size: int) -> None:
    ctx = canvas.getContext("2d")
    x, y = pos
    ctx.fillStyle = "rgb" + str(color)
    ctx.font = str(size) + "px sans-serif";
    ctx.textBaseline = "top";
    ctx.fillText(txt, x, y)
コード例 #2
0
def image_blit(canvas: CANVAS, image: IMG, pos: (int, int), area: (int, int, int, int)=None) -> None:
    ctx = canvas.getContext("2d")
    x, y = pos
    if area:
      ax, ay, aw, ah = area
      ctx.drawImage(image, ax, ay, aw, ah, x, y, aw, ah)
    else:
      ctx.drawImage(image, x, y)
コード例 #3
0
def draw_line(canvas: CANVAS, color: (int, int, int), pt1: (int, int), pt2: (int, int)) -> None:
    ctx = canvas.getContext("2d")
    x1, y1 = pt1
    x2, y2 = pt2
    ctx.strokeStyle = "rgb" + str(color)
    ctx.moveTo(x1, y1)
    ctx.lineTo(x2, y2)
    ctx.stroke()
コード例 #4
0
def draw_circle(canvas: CANVAS, color: (int, int, int), center: (int, int), radius: int) -> None:
    from math import pi
    ctx = canvas.getContext("2d")
    x, y = center
    ctx.fillStyle = "rgb" + str(color)
    ctx.beginPath()
    ctx.arc(x, y, radius, 0, 2 * pi)
    ctx.closePath()
    ctx.fill()
コード例 #5
0
def draw_rect(canvas: CANVAS, color: (int, int, int), rectangle: (int, int, int, int)) -> None:
    ctx = canvas.getContext("2d")
    x, y, w, h = rectangle
    ctx.fillStyle = "rgb" + str(color)
    ctx.fillRect(x, y, w, h)