Example #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)
Example #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)
Example #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()
Example #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()
Example #5
0
def startGame(string):

    global tableau
    global canvas
    global idTimer

    document["zone"].text = ""

    tableau = initPlateau()
    
    if len(string) != 0:
        tableau = convertStringToTab(string)

    canvas = CANVAS(width = tailleTableau*64 + tailleTableau*5, height = tailleTableau*64 + tailleTableau*5)
    canvas.bind("click", cellClickEvent)

    document["zone"] <= canvas
    idTimer = timer.set_interval(gameLoop, 16)
Example #6
0
from browser import document, timer, ajax
from browser.html import TABLE, TD, TR, CANVAS, IMG
import math
from verif import *

tailleTableau = 4
tailleCase = 64
casePadding = 5
tableau = []
clickableTableau = []
currentTableauString = ""
correctedTableau = []
canvas = CANVAS(width=64, height=64)

sizeX = 0
sizeY = 0

idTimer = 0

image1 = IMG(src="TileOne.png")
image0 = IMG(src="TileZero.png")
imageE = IMG(src="EmtyTile.png")


def getIndexByMousePos(mouseX, mouseY):
    yOrigin = canvas.abs_top
    xOrigin = canvas.abs_left

    return {
        'x': math.floor((mouseX - xOrigin) / (tailleCase + casePadding)),
        'y': math.floor((mouseY - yOrigin) / (tailleCase + casePadding))
Example #7
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)