예제 #1
0
파일: tiler.py 프로젝트: ikn/brjaf
 def _draw_lines (self, surface, grid_rect, tile_sizes):
     # draw border and grid lines
     c = self.line
     if c is None:
         # don't draw lines
         return
     l, t, w, h = grid_rect
     hg = type(tile_sizes[0]) is int
     b = self.border
     g = self.gap
     tl = (t, l)
     crop = self.homogeneous and self.overflow == 'crop'
     # draw border
     draw_rect(surface, c, (l, t, w, h), b)
     for i in (0, 1):
         if g[i]:
             # draw grid lines on one axis
             pos = tl[not i] + b[i] + g[i] / 2 + g[i] % 2 - 1
             start = tl[i] + b[not i]
             end = tl[i] + (h, w)[i] - b[not i] - 1
             if not hg:
                 max_size = tile_sizes[i][0]
             for j in xrange((self.w, self.h)[i] - 1):
                 tile_size = tile_sizes[i]
                 if not hg:
                     if crop and tile_sizes[i][j] < max_size:
                         break
                     tile_size = tile_size[j]
                 pos += tile_size
                 if i:
                     draw_line(surface, c, (start, pos), (end, pos), g[i])
                 else:
                     draw_line(surface, c, (pos, start), (pos, end), g[i])
                 pos += g[i]
예제 #2
0
파일: tiler.py 프로젝트: ikn/brjaf
def draw_rect (surface, colour, rect, width = 1):
    """Draw a rect border to a surface.

draw_rect(surface, colour, rect, width = 1)

surface: the surface to draw to.
colour: a standard (r, g, b) tuple.
rect: rect to draw; anything like (left, top, width, height).
width: (vertical, horizontal) rect border widths, or one int for
       vertical = horizontal, in pixels.

The border is drawn inside the given rect, unlike pygame.draw.rect, which draws
the lines with their centres on the rect's borders.

"""
    try:
        width[0]
    except TypeError:
        width = (width, width)
    l, t, w, h = rect
    x0 = l + width[0] / 2 + width[0] % 2 - 1
    x1 = l + w - width[0] / 2 - 1
    y0 = t + width[1] / 2 + width[1] % 2 - 1
    y1 = t + h - width[1] / 2 - 1
    points = (
        ((l, y0), (l + w - 1, y0)),
        ((x1, t), (x1, t + h - 1)),
        ((l + w - 1, y1), (l, y1)),
        ((x0, t + h - 1), (x0, t))
    )
    for i in xrange(len(points)):
        p, q = points[i]
        draw_line(surface, colour, p, q, width[not i % 2])
예제 #3
0
파일: tiler.py 프로젝트: ikn/ikn.org.uk
 def _draw_lines (self, surface, grid_rect, tile_sizes):
     # draw border and grid lines
     c = self.line
     if c is None:
         # don't draw lines
         return
     l, t, w, h = grid_rect
     hg = type(tile_sizes[0]) is int
     b = self.border
     g = self.gap
     tl = (t, l)
     crop = self.homogeneous and self.overflow == 'crop'
     # draw border
     draw_rect(surface, c, (l, t, w, h), b)
     for i in (0, 1):
         if g[i]:
             # draw grid lines on one axis
             pos = tl[not i] + b[i] + g[i] / 2 + g[i] % 2 - 1
             start = tl[i] + b[not i]
             end = tl[i] + (h, w)[i] - b[not i] - 1
             if not hg:
                 max_size = tile_sizes[i][0]
             for j in xrange((self.w, self.h)[i] - 1):
                 tile_size = tile_sizes[i]
                 if not hg:
                     if crop and tile_sizes[i][j] < max_size:
                         break
                     tile_size = tile_size[j]
                 pos += tile_size
                 if i:
                     draw_line(surface, c, (start, pos), (end, pos), g[i])
                 else:
                     draw_line(surface, c, (pos, start), (pos, end), g[i])
                 pos += g[i]
예제 #4
0
파일: tiler.py 프로젝트: ikn/ikn.org.uk
def draw_rect (surface, colour, rect, width = 1):
    """Draw a rect border to a surface.

draw_rect(surface, colour, rect, width = 1)

surface: the surface to draw to.
colour: a standard (r, g, b) tuple.
rect: rect to draw; anything like (left, top, width, height).
width: (vertical, horizontal) rect border widths, or one int for
       vertical = horizontal, in pixels.

The border is drawn inside the given rect, unlike pygame.draw.rect, which draws
the lines with their centres on the rect's borders.

"""
    try:
        width[0]
    except TypeError:
        width = (width, width)
    l, t, w, h = rect
    x0 = l + width[0] / 2 + width[0] % 2 - 1
    x1 = l + w - width[0] / 2 - 1
    y0 = t + width[1] / 2 + width[1] % 2 - 1
    y1 = t + h - width[1] / 2 - 1
    points = (
        ((l, y0), (l + w - 1, y0)),
        ((x1, t), (x1, t + h - 1)),
        ((l + w - 1, y1), (l, y1)),
        ((x0, t + h - 1), (x0, t))
    )
    for i in xrange(len(points)):
        p, q = points[i]
        draw_line(surface, colour, p, q, width[not i % 2])
예제 #5
0
def draw_dashed_line(surface,
                     color,
                     start_pos,
                     end_pos,
                     width=1,
                     dash_length=10):
    origin = Vector2(start_pos)
    target = Vector2(end_pos)
    displacement = target - origin
    length = displacement.length()
    slope = displacement / length

    for index in range(0, int(length / dash_length), 2):
        start = origin + (slope * index * dash_length)
        end = origin + (slope * (index + 1) * dash_length)
        draw_line(surface, color, start, end, width)
예제 #6
0
 def draw(self, window):
     self.time_2 = int(time())
     draw_rect(window, self.color,
               (self.x, self.y, self.width, self.height))
     y = self.y
     for line in self.lines:
         line_render = self.font.render(line, True, (200, 200, 200))
         window.blit(line_render, (
             self.x, y +
             (self.letter_example.get_height() - line_render.get_height())))
         y += self.letter_example.get_height()
     self.draw_line = self.time_2 - self.time_1 in range(1)
     if self.draw_line:
         draw_line(window, (255, 255, 255),
                   (self.x + line_render.get_width(),
                    y - self.letter_example.get_height() + 3),
                   (self.x + line_render.get_width(),
                    (y - self.letter_example.get_height() + 3) + 35), 2)
     else:
         if not self.time_2 - self.time_1 in range(1, 2):
             self.time_1 = int(time())