Example #1
0
def brezenham_c(xc, yc, r, colour):
    points = list()

    x = 0
    y = r
    points.append(Point(x + xc, y + yc, colour))
    delta = 2 - r - r

    while x < y:
        if delta <= 0:
            d1 = delta + delta + y + y - 1
            x += 1
            if d1 >= 0:
                y -= 1
                delta += 2 * (x - y + 1)
            else:
                delta += x + x + 1

        else:
            d2 = 2 * (delta - x) - 1
            y -= 1
            if d2 < 0:
                x += 1
                delta += 2 * (x - y + 1)
            else:
                delta -= y + y - 1

        points.append(Point(x + xc, y + yc, colour))

    dup_biss(points, xc, yc)
    dup_x(points, xc, yc)
    dup_y(points, xc, yc)

    return points
Example #2
0
def middle_point_c(xc, yc, r, colour):

    points = list()
    x = r
    y = 0

    points.append(Point(xc + x, yc + y, colour))
    p = 1 - r

    while x > y:
        y += 1

        if p >= 0:
            x -= 1
            p -= x + x

        p += y + y + 1

        points.append(Point(xc + x, yc + y, colour))

    dup_biss(points, xc, yc)
    dup_x(points, xc, yc)
    dup_y(points, xc, yc)

    return points
Example #3
0
def brezenham_o(xc, yc, a, b, colour):
    points = list()

    x = 0
    y = b
    sqr_b = b * b
    sqr_a = a * a
    points.append(Point(x + xc, y + yc, colour))
    delta = sqr_b - sqr_a * (2 * b + 1)

    while y > 0:
        if delta <= 0:
            d1 = 2 * delta + sqr_a * (2 * y - 1)
            x += 1
            delta += sqr_b * (2 * x + 1)
            if d1 >= 0:
                y -= 1
                delta += sqr_a * (-2 * y + 1)

        else:
            d2 = 2 * delta + sqr_b * (-2 * x - 1)
            y -= 1
            delta += sqr_a * (-2 * y + 1)
            if d2 < 0:
                x += 1
                delta += sqr_b * (2 * x + 1)

        points.append(Point(x + xc, y + yc, colour))

    dup_x(points, xc, yc)
    dup_y(points, xc, yc)

    return points
Example #4
0
 def recursive_dig(self, x, y, space, pointlist):
     if not self.food:
         return
     # Define the eight possible directions to go
     north = Point(x, y-1)
     south = Point(x, y+1)
     west = Point(x-1, y)
     east = Point(x+1, y)
     northwest = Point(x-1, y-1)
     northeast = Point(x+1, y-1)
     southwest = Point(x-1, y+1)
     southeast = Point(x+1, y+1)
     # weirddirections = [northwest, northeast, southwest, southeast]
     # Put them in a list for random pick
     directions = [north, south, west, east]
     # Check in a random direction...
     if random.randint(0, 100) < 5:
         pass
         # directions += weirddirections
     random.shuffle(directions)
     for point in directions:
         if not self.food:
             return
         # If its allowed to dig
         if self.validate(point.x, point.y, space):
             self.map[point.x][point.y].dug = True
             self.map[point.x][point.y].is_wall = False
             self.food = self.food - 1
             pointlist.append(point)
             self.recursive_dig(point.x, point.y, space, pointlist)
     return
Example #5
0
def left_click(event):
    vertex_list.append(Point(event.x, event.y))
    if len(vertex_list) > 1:
        section = brezenham_int(draw_color, vertex_list[-2].x,
                                vertex_list[-2].y, vertex_list[-1].x,
                                vertex_list[-1].y)
        draw_section(section)
Example #6
0
 def __init__(self, x, y, regionid, rockimage, wallimage, floorimage,
              vertdoor, hordoor, enter, exiti, playerimage):
     """Constructor for tiles."""
     self.rockimage = rockimage
     self.wall_image = wallimage
     self.floor_image = floorimage
     self.door_image = vertdoor
     self.hor_door = hordoor
     self.enter_image = enter
     self.exit_image = exiti
     self.playerimage = playerimage
     self.pos = Point(x, y)
     self.rect = pg.Rect(x, y, TILESIZE, TILESIZE)
     self.id = regionid
     self.color = colors[self.id % len(colors)]
     self.dug = False
     self.rock = True
     self.roomid = None
     self.corridor = False
     self.is_mapped = False
     self.is_digable = True
     self.is_door = False
     self.is_wall = False
     self.space = False
     self.enter = False
     self.exit = False
     self.player = False
Example #7
0
def plot_line(x1, y1, x2, y2):
    """The classic Brensenham line drawing algorithm.
    Returns a list of points(tuples) along the line.
    """
    dx = x2 - x1
    dy = y2 - y1
    if dy < 0:
        dy = -dy
        stepy = -1
    else:
        stepy = 1
    if dx < 0:
        dx = -dx
        stepx = -1
    else:
        stepx = 1
    dy = dy * 2
    dx = dx * 2
    x = x1
    y = y1
    pixelpoints = [Point(x, y)]

    if dx > dy:
        fraction = dy - (dx / 2)
        while x is not x2:
            if fraction >= 0:
                y = y + stepy
                fraction = fraction - dx
            x = x + stepx
            fraction = fraction + dy
            pixelpoints.append(Point(x, y))
    else:
        fraction = dx - (dy / 2)
        while y is not y2:
            if fraction >= 0:
                x = x + stepx
                fraction = fraction - dy
            y = y + stepy
            fraction = fraction + dx
            pixelpoints.append(Point(x, y))
    pixelpoints.reverse()
    # print(pixelpoints)
    return pixelpoints
Example #8
0
def brezenham_double(colour, xb, yb, xe, ye):
    section = list()
    x, y = xb, yb
    dx = xe - xb
    dy = ye - yb
    sx = int(np.sign(dx))
    sy = int(np.sign(dy))
    dx, dy = abs(dx), abs(dy)

    if dx > dy:
        obmen = 0
    else:
        obmen = 1
        dx, dy = dy, dx

    m = dy / dx
    e = 1 / 2
    w = 1

    if not obmen:
        for _ in range(dx):
            section.append(Point(int(x), int(y),
                                 colour.intensity_apply(1 - e)))
            section.append(
                Point(int(x), int(y + sy), colour.intensity_apply(e)))
            if e >= w - m:
                y += sy
                e -= w
            x += sx
            e += m
    else:
        for _ in range(dx):
            section.append(Point(int(x), int(y),
                                 colour.intensity_apply(1 - e)))
            section.append(
                Point(int(x + sx), int(y), colour.intensity_apply(e)))
            if e >= w - m:
                x += sx
                e -= w
            y += sy
            e += m

    return section
Example #9
0
def middle_point_o(xc, yc, a, b, colour):
    points = list()
    sqr_a = a * a
    sqr_b = b * b

    # x, where y` = -1
    limit = round(a / sqrt(1 + sqr_b / sqr_a))

    x = 0
    y = b
    points.append(Point(x + xc, y + yc, colour))

    fu = sqr_b - round(sqr_a * (b - 1 / 4))
    while x < limit:
        if fu > 0:
            y -= 1
            fu -= 2 * sqr_a * y

        x += 1
        fu += sqr_b * (2 * x + 1)
        points.append(Point(x + xc, y + yc, colour))

    # y, where y` = -1
    limit = round(b / sqrt(1 + sqr_a / sqr_b))

    y = 0
    x = a
    points.append(Point(x + xc, y + yc, colour))

    fu = sqr_a - round(sqr_b * (a - 1 / 4))
    while y < limit:
        if fu > 0:
            x -= 1
            fu -= 2 * sqr_b * x

        y += 1
        fu += sqr_a * (2 * y + 1)
        points.append(Point(x + xc, y + yc, colour))

    dup_y(points, xc, yc)
    dup_x(points, xc, yc)

    return points
Example #10
0
def vu(colour: Colour, xb, yb, xe, ye):
    section = list()
    x, y = xb, yb
    dx = xe - xb
    dy = ye - yb
    sx = 1 if dx == 0 else int(np.sign(dx))
    sy = 1 if dy == 0 else int(np.sign(dy))
    dx, dy = abs(dx), abs(dy)

    if dx > dy:
        obmen = 0
    else:
        obmen = 1
        dx, dy = dy, dx

    m = dy / dx
    e = -1

    if not obmen:
        for _ in range(dx):
            section.append(Point(int(x), int(y), colour.intensity_apply(-e)))
            section.append(
                Point(int(x), int(y + sy), colour.intensity_apply(1 + e)))

            e += m
            if e >= 0:
                y += sy
                e -= 1
            x += sx
    else:
        for _ in range(dx):
            section.append(Point(int(x), int(y), colour.intensity_apply(-e)))
            section.append(
                Point(int(x + sx), int(y), colour.intensity_apply(1 + e)))

            e += m
            if e >= 0:
                x += sx
                e -= 1
            y += sy

    return section
Example #11
0
def param_o(x, y, r1, r2, colour):
    points = list()
    step = 1 / r1 if r1 > r2 else 1 / r2
    for t in np.arange(0, pi / 2 + step, step):
        a = x + r1 * cos(t)
        b = y + r2 * sin(t)
        points.append(Point(a, b, colour))

    dup_x(points, x, y)
    dup_y(points, x, y)

    return points
Example #12
0
def normal_c(x, y, r, colour):
    points = list()
    R = r * r
    for a in range(x, round(x + r / sqrt(2)) + 1):
        b = y + sqrt(R - (a - x) * (a - x))
        points.append(Point(a, b, colour))

    dup_biss(points, x, y)
    dup_x(points, x, y)
    dup_y(points, x, y)

    return points
Example #13
0
def brezenham_float(colour, xb, yb, xe, ye):
    section = list()

    x, y = xb, yb
    dx = xe - xb
    dy = ye - yb

    sx = int(np.sign(dx))
    sy = int(np.sign(dy))
    dx, dy = abs(dx), abs(dy)

    if dx > dy:
        obmen = 0
    else:
        obmen = 1
        dx, dy = dy, dx

    m = dy / dx
    e = m - 1 / 2

    if not obmen:
        for _ in range(dx):
            section.append(Point(int(x), int(y), colour))

            if e >= 0:
                y += sy
                e -= 1
            x += sx
            e += m
    else:
        for _ in range(dx):
            section.append(Point(int(x), int(y), colour))

            if e >= 0:
                x += sx
                e -= 1
            y += sy
            e += m

    return section
Example #14
0
def param_c(x, y, r, colour):
    points = list()
    step = 1 / r
    for t in np.arange(0, pi / 4 + step, step):
        a = x + r * cos(t)
        b = y + r * sin(t)
        points.append(Point(a, b, colour))

    dup_biss(points, x, y)
    dup_x(points, x, y)
    dup_y(points, x, y)

    return points
Example #15
0
File: main.py Project: izen57/kg
def left_click(event):
    update_max_area(event)
    vertex_list[-1].append(Point(event.x, event.y, draw_color))
    if len(vertex_list[-1]) > 1:
        section = brezenham_int(draw_color, vertex_list[-1][-2].x,
                                vertex_list[-1][-2].y, vertex_list[-1][-1].x,
                                vertex_list[-1][-1].y)

        if len(vertex_list[-1]) > 2:
            update_extrems(vertex_list[-1],
                           len(vertex_list[-1]) - 2, extrems[-1])

        draw_section(section)
Example #16
0
def normal_o(xc, yc, a, b, colour):
    points = list()
    sqr_a = a * a
    sqr_b = b * b
    sqr_ab = sqr_a * sqr_b

    limit1 = round(xc + a / sqrt(1 + sqr_b / sqr_a))

    for x in range(xc, limit1):
        y = yc + sqrt(sqr_ab - (x - xc) * (x - xc) * sqr_b) / a
        points.append(Point(x, y, colour))

    limit2 = round(yc + b / sqrt(1 + sqr_a / sqr_b))

    for y in range(limit2, yc - 1, -1):
        x = xc + sqrt(sqr_ab - (y - yc) * (y - yc) * sqr_a) / b
        points.append(Point(x, y, colour))

    dup_x(points, xc, yc)
    dup_y(points, xc, yc)

    return points
Example #17
0
def cda(colour, xb, yb, xe, ye):
    section = list()
    dx, dy = xe - xb, ye - yb
    delta_x, delta_y = abs(dx), abs(dy)
    l = delta_x if delta_x > delta_y else delta_y
    dx /= l
    dy /= l
    x, y = xb, yb
    for _ in range(l):
        section.append(Point(int(x), int(y), colour))
        x += dx
        y += dy
    return section
Example #18
0
def brezenham_int(colour, xb, yb, xe, ye):
    section = list()
    x, y = xb, yb
    dx = xe - xb
    dy = ye - yb
    sx = int(np.sign(dx))
    sy = int(np.sign(dy))
    dx, dy = abs(dx), abs(dy)

    if dx > dy:
        obmen = 0
    else:
        obmen = 1
        dx, dy = dy, dx

    e = dy + dy - dx

    if not obmen:
        for _ in range(dx):
            section.append(Point(x, y, colour))

            if e >= 0:
                y += sy
                e -= dx + dx
            x += sx
            e += dy + dy
    else:
        for _ in range(dx):
            section.append(Point(x, y, colour))

            if e >= 0:
                x += sx
                e -= dx + dx
            y += sy
            e += dy + dy

    return section
Example #19
0
def dup_x(points, x, y):
    points += list(map(lambda p: Point(p.x, 2 * y - p.y, p.colour), points))
Example #20
0
def put_point():
    p = Point(int(x_entry.get()), int(y_entry.get()))
    left_click(p)
Example #21
0
def dup_y(points, x, y):
    points += list(map(lambda p: Point(2 * x - p.x, p.y, p.colour), points))
Example #22
0
def dup_biss(points, x, y):
    points += list(
        map(lambda p: Point(x + p.y - y, y + p.x - x, p.colour), points))
Example #23
0
File: main.py Project: izen57/kg
import time
import tkinter as tk
import tkinter.messagebox as mb
from tkinter import colorchooser

import numpy as np

import config as cfg
from config import Point

draw_color = cfg.DEFAULT_COLOUR

vertex_list = [[]]
extrems = [[]]

pmax = Point()
pmin = Point(cfg.FIELD_WIDTH, cfg.FIELD_HEIGHT)


def get_mark_color():
    return "#000000" if draw_color != "#000000" else "#ff0000"


def get_mark_tuple():
    return (0, 0, 0) if draw_color != "#000000" else (255, 0, 0)


def reset():
    global vertex_list, extrems
    vertex_list = [[]]
    extrems = [[]]
Example #24
0
 def center(self):
     return Point(self.pos.x + (TILESIZE / 2), self.pos.y + (TILESIZE / 2))