Ejemplo n.º 1
0
 def test_color_validation(self):
     surf = pygame.Surface((10, 10))
     colors = 123456, (1, 10, 100), RED # but not '#ab12df' or 'red' ...
     points = ((0, 0), (1, 1), (1, 0))
     # 1. valid colors
     for col in colors:
         draw.line(surf, col, (0, 0), (1, 1))
         draw.aaline(surf, col, (0, 0), (1, 1))
         draw.aalines(surf, col, True, points)
         draw.lines(surf, col, True, points)
         draw.arc(surf, col, pygame.Rect(0, 0, 3, 3), 15, 150)
         draw.ellipse(surf, col, pygame.Rect(0, 0, 3, 6), 1)
         draw.circle(surf, col, (7, 3), 2)
         draw.polygon(surf, col, points, 0)
     # 2. invalid colors
     for col in ('invalid', 1.256, object(), None, '#ab12df', 'red'):
         with self.assertRaises(TypeError):
             draw.line(surf, col, (0, 0), (1, 1))
         with self.assertRaises(TypeError):
             draw.aaline(surf, col, (0, 0), (1, 1))
         with self.assertRaises(TypeError):
             draw.aalines(surf, col, True, points)
         with self.assertRaises(TypeError):
             draw.lines(surf, col, True, points)
         with self.assertRaises(TypeError):
             draw.arc(surf, col, pygame.Rect(0, 0, 3, 3), 15, 150)
         with self.assertRaises(TypeError):
             draw.ellipse(surf, col, pygame.Rect(0, 0, 3, 6), 1)
         with self.assertRaises(TypeError):
             draw.circle(surf, col, (7, 3), 2)
         with self.assertRaises(TypeError):
             draw.polygon(surf, col, points, 0)
Ejemplo n.º 2
0
    def run(self):

        window = display.get_surface()

        for evt in event.get():
            if evt.type == pygame.QUIT:
                self.quit()
            elif evt.type == pygame.MOUSEMOTION:
                self.processMouseMotion(evt.pos)

            elif evt.type == pygame.KEYDOWN:
                self.processKeyDown(evt.key)

            elif evt.type == pygame.MOUSEBUTTONDOWN:
                self.processMouseButtonDown(evt.pos)

            elif evt.type == pygame.MOUSEBUTTONUP:
                self.processMouseButtonUp(evt.pos)

        window.fill(self.aColor)

        # self.testObj.rect.x = self.mouseX
        # self.testObj.rect.y = self.mouseY
        # self.activeSprites.draw(window)

        self.activeState.update(self.Clock.get_time())
        self.activeState.activeSprites.draw(window)
        if len(self.activeState.pts) > 1:
            draw.lines(window, (255, 0, 255), False, self.activeState.pts, 3)

        self.Clock.tick(30)
        display.flip()
        self.run()
Ejemplo n.º 3
0
 def get_imgs():
     """Load an return the images used as file and folder icons."""
     print("*** MCEDIT DEBUG: file_dialog:", __file__)
     print("*** MCEDIT DEBUG: directory:", os.path.dirname(__file__))
     print("*** MCEDIT DEBUG: current directory:", os.getcwd())
     try:
         file_image = get_image('file.png', prefix='')
         folder_image = get_image('folder.png', prefix='')
     except Exception as e:
         print("MCEDIT DEBUG: Could not load file dialog images.")
         print(e)
         from pygame import draw, Surface
         from pygame.locals import SRCALPHA
         from math import pi
         file_image = Surface((16, 16), SRCALPHA)
         file_image.fill((0, 0, 0, 0))
         draw.lines(file_image, (255, 255, 255, 255), False,
                    [[3, 15], [3, 1], [13, 1]], 2)
         draw.line(file_image, (255, 255, 255, 255), [3, 7], [10, 7], 2)
         folder_image = Surface((16, 16), SRCALPHA)
         folder_image.fill((0, 0, 0, 0))
         draw.line(folder_image, (255, 255, 255, 255), [3, 15], [3, 1], 2)
         draw.arc(folder_image, (255, 255, 255, 255), [0, 1, 13, 15], 0,
                  pi / 1.9, 2)
         draw.arc(folder_image, (255, 255, 255, 255), [0, 1, 13, 15],
                  3 * pi / 2, 2 * pi, 2)
     return file_image, folder_image
Ejemplo n.º 4
0
    def draw(self, surface, x, y):
        def darken(rgb, d=40):
            return max(rgb - d, 0)

        def lighten(rgb, d=40):
            return min(rgb + d, 255)

        maxV = len(self.blocks)
        maxH = len(self.blocks[0])
        for py in range(maxV):
            for px in range(maxH):
                col = self.blocks[py][px]
                if col:
                    shadow = Color(*[darken(col[i]) for i in range(3)])
                    bright = Color(*[lighten(col[i]) for i in range(3)])
                    bx = (x + px) * blockSize
                    by = (y + py) * blockSize
                    r = Rect(bx + 1, by + 1, blockSize - 1, blockSize - 1)
                    surface.fill(col, r)
                    lines(surface, shadow, False,
                          [(bx, by), (bx, by + blockSize - 1),
                           (bx + blockSize - 1, by + blockSize - 1)])
                    lines(surface, bright, False,
                          [(bx, by), (bx + blockSize - 1, by),
                           (bx + blockSize - 1, by + blockSize - 1)])
Ejemplo n.º 5
0
def drawGeom(geom):
	if type(geom) is ode.GeomBox:
		x, y, _ = geom.getPosition()
		a, b, _ = geom.getLengths()
		r = geom.getRotation()
		costheta = r[0]; sintheta = r[1]
		p1 = to_screen_pnt(x + a/2 * costheta + b/2 * sintheta, y - a/2 * sintheta + b/2 * costheta)
		p2 = to_screen_pnt(x + a/2 * costheta - b/2 * sintheta, y - a/2 * sintheta - b/2 * costheta)
		p3 = to_screen_pnt(x - a/2 * costheta - b/2 * sintheta, y + a/2 * sintheta - b/2 * costheta)
		p4 = to_screen_pnt(x - a/2 * costheta + b/2 * sintheta, y + a/2 * sintheta + b/2 * costheta)
		draw.lines(screen, actual_color(getattr(geom, 'color', blue)), True, [p1, p2, p3, p4])
	elif type(geom) is ode.GeomSphere:
		x, y, _ = geom.getPosition()
		r = geom.getRadius()
		rotmat = geom.getRotation()
		costheta = rotmat[0]; sintheta = rotmat[1]
		px, py = to_screen_pnt(x, y)
		pr = to_screen_len(r)
		draw.circle(screen, actual_color(getattr(geom, 'color', blue)), (int(px), int(py)), int(pr), 1)
		drawLine((x,y), (x + costheta * r, y - sintheta * r), getattr(geom, 'color', blue))
	elif type(geom) is ode.GeomCapsule:
		x, y, _ = geom.getPosition()
		pass
	elif isinstance(geom, ode.SpaceBase):
		for i in geom:
			drawGeom(i)
	else:
		assert False
Ejemplo n.º 6
0
def draw_appleh(origin, parent):
    """Draw an apple"""

    p1, p2 = modify(origin, 4, 4), modify(origin, 16, 4)
    p3, p4 = modify(origin, 16, 16), modify(origin, 4, 16)

    lines(parent, (255, 50, 50), False, [p1, p2, p3, p4, p1])
Ejemplo n.º 7
0
 def apply(self, surface: Surface):
     rect = surface.get_rect()
     draw.lines(surface, (150, 150, 150), False,
                [(0, 0), rect.topright, rect.bottomright], self.depth)
     draw.lines(surface, (0, 0, 0), False,
                [(0, 0), rect.bottomleft, rect.bottomright], self.depth)
     pass
Ejemplo n.º 8
0
    def InitDisplay(self, nav):
        super(ValueChangeScreen,
              self).InitDisplay({})  # why do we pass in the nav keys here?

        self.ReInitDisplay()
        # self.PaintBase()
        # write the title with name of var? maybe button should be "accept"
        for i in range(len(self.changevals)):
            fho = self.chgval[i][0][0]
            fvo = self.chgval[i][0][1]
            hw.screen.blit(
                self.chgval[i][1],
                self.offsetpoint(self.uparrowcenter[i],
                                 (fho, -self.arrowht / 2 + self.arrowht / 10)))
            hw.screen.blit(
                self.chgval[i][1],
                self.offsetpoint(
                    self.dnarrowcenter[i],
                    (fho, self.arrowht / 2 - fvo - self.arrowht / 10)))
            draw.lines(hw.screen, wc(self.Outline), True, self.uparrowverts[i],
                       5)
            draw.lines(hw.screen, wc(self.Outline), True, self.dnarrowverts[i],
                       5)
        # need to add in the value to change by l
        hw.screen.blit(self.labelrend, self.labelloc)
        self.Keys['accept'].SetKeyImages(("Accept", str(self.Value)))
        self.PaintKeys()
        pygame.display.update()
        pass
Ejemplo n.º 9
0
def button(width, height, caption):
    # line thickness
    thickness = Style.button.border.thickness

    # background
    surface = Surface((width, height))
    surface.fill(Style.button.color)

    # border
    if thickness > 0:
        draw.lines(surface, Style.button.border.color, True,
                   [(0, 0), (width - thickness, 0),
                    (width - thickness, height - thickness),
                    (0, height - thickness)], thickness)

    # label
    myfont = font.SysFont(Style.button.label.font, Style.button.label.size)
    size = myfont.size(caption)

    # center text ...
    offsetX = (width - size[0]) / 2
    offsetY = (height - size[1]) / 2

    # draw text on surface
    label = myfont.render(caption, True, Style.button.label.color)
    surface.blit(label, (offsetX, offsetY))

    return surface
Ejemplo n.º 10
0
    def run(self):
        radius = 70
        (xoff, yoff) = (self.dim[0] / 2, self.dim[1] / 2)
        (xscale, yscale) = (1, 0.5)
        while True:
            if self.iter > 2 * math.pi:
                self.iter = 0
            self.iter += 0.01

            (x1, y1) = (math.cos(self.iter) * xscale, math.sin(self.iter) * yscale)
            (x2, y2) = (math.cos(self.iter + math.pi / 2) * xscale, math.sin(self.iter + math.pi / 2) * yscale)
            (x3, y3) = (int(-x1 * radius + xoff), int(-y1 * radius + yoff))
            (x4, y4) = (int(-x2 * radius + xoff), int(-y2 * radius + yoff))
            (x1, y1) = (int(x1 * radius + xoff), int(y1 * radius + yoff))
            (x2, y2) = (int(x2 * radius + xoff), int(y2 * radius + yoff))

            # self.lock.acquire()
            self.surface.fill(black)

            draw.lines(self.surface, green, True, [(x1, y1), (x2, y2), (x3, y3), (x4, y4)], 3)
            draw.lines(self.surface, green, True, [(x1, y1 - radius), (x2, y2 - radius), (x3, y3 - radius), (x4, y4 - radius)], 3)
            draw.line(self.surface, green, (x1, y1), (x1, y1 - radius), 3)
            draw.line(self.surface, green, (x2, y2), (x2, y2 - radius), 3)
            draw.line(self.surface, green, (x3, y3), (x3, y3 - radius), 3)
            draw.line(self.surface, green, (x4, y4), (x4, y4 - radius), 3)

            vdot = rotate_vector((0, 0.6), self.iter)
            draw.circle(self.surface, green, (int(vdot[0] * radius * xscale + xoff), int(vdot[1] * radius * yscale + yoff - radius)), 5)

            # self.clock.lock.acquire()
            self.surface.blit(self.clock.surface, (self.dim[0] - self.clock.get_dimensions()[0] - 10, 0))
            # self.clock.lock.release()

            # self.lock.release()
            time.sleep(0.005)
Ejemplo n.º 11
0
def _make_object():
    """Create a vaguely interesting object to transform."""
    obj = surface.Surface((40, 80), depth=32)
    draw.line(obj, (255, 0, 0, 255), (10, 10), (10, 40), 3)
    draw.line(obj, (255, 255, 0, 255), (10, 10), (40, 10), 3)
    draw.line(obj, (255, 128, 128, 255), (40, 10), (40, 40), 2)
    draw.lines(obj, (255, 255, 255, 255), 1, [(20, 20), (20, 30), (30, 30)])
    return obj
Ejemplo n.º 12
0
def draw_cell(origin, parent):
    """Snake made out of bricks is booring"""

    p1 = modify(origin, 2, 2)
    p2 = modify(origin, 18, 2)
    p3 = modify(origin, 18, 18)
    p4 = modify(origin, 2, 18)

    lines(parent, (125, 255, 125), False, [p1, p2, p3, p4, p1])
Ejemplo n.º 13
0
def drawCapsule(pos, a, b, costheta, sintheta):
	x, y = pos
	p1 = to_screen_pnt(x + a/2 * costheta + b/2 * sintheta, y - a/2 * sintheta + b/2 * costheta)
	p2 = to_screen_pnt(x + a/2 * costheta - b/2 * sintheta, y - a/2 * sintheta - b/2 * costheta)
	p3 = to_screen_pnt(x - a/2 * costheta - b/2 * sintheta, y + a/2 * sintheta - b/2 * costheta)
	p4 = to_screen_pnt(x - a/2 * costheta + b/2 * sintheta, y + a/2 * sintheta + b/2 * costheta)
	draw.lines(screen, actual_color(blue), True, [p1, p2, p3, p4])
	drawCircle((x + a/2 * costheta, y - a/2 * sintheta), b/2)
	drawCircle((x - a/2 * costheta, y + a/2 * sintheta), b/2)
Ejemplo n.º 14
0
 def draw_network_link(self, surface):
     """ This method will draw a link between all objects in a network and the corresponding network tab """
     first_point = list(self.network_tabs.get_tab_center(self.active_tab))
     first_point[1] += 20
     second_point = [first_point[0], first_point[1] + 20]
     for obj in self.all_networks[self.active_tab['index']].objects:
         third_point = [obj.center[0], second_point[1]]
         fourth_point = [obj.center[0], int(obj.center[1] - obj.height / 2)]
         pygame_draw.lines(
             surface, colors['LIGHTGRAY'], False,
             [first_point, second_point, third_point, fourth_point])
Ejemplo n.º 15
0
	def redraw(self):
		self.pointlist = []
		self.heights = []
		if not self.pointlist:
			self.generate_terrain(self.buffer.get_size())

		if self.color:
			draw.polygon(self.buffer, white, self.pointlist)
		else:
			draw.polygon(self.buffer, black, self.pointlist)
		draw.lines(self.buffer, white, True, self.pointlist)
Ejemplo n.º 16
0
	def update_buffer(self):
		w_buffer = max(x for x, y in self.points) - min(x for x, y in self.points) + 1
		h_buffer = max(y for x, y in self.points) - min(y for x, y in self.points) + 1
		self.x_buffer = - min(x for x, y in self.points)
		self.y_buffer = - min(y for x, y in self.points)
		self.buffer = Surface((w_buffer, h_buffer))
		self.buffer.set_colorkey(transparent)
		self.buffer.fill(transparent)
		offset_points = [(x + self.x_buffer, y + self.y_buffer) for x, y in self.points]
		#draw.polygon(self.buffer, white, offset_points)
		draw.lines(self.buffer, white, True, offset_points)
Ejemplo n.º 17
0
    def draw(self, surface):
        points = []
        t = self.start
        si = self.spiral.interval
        while t <= self.end:
            t += si / self.spiral.radius(t)
            r = self.spiral.radius(t + self.dev * pi / 4.)
            pos = self.spiral.screen.to_cart(t, r)
            points.append(pos)

        draw.lines(surface, self.spiral.screen.gc("avatar", self.color), False,
                   points, 3)
Ejemplo n.º 18
0
Archivo: me.py Proyecto: bluepeppers/me
    def draw(self, surface):
        points = []
        t = self.start
        si = self.spiral.interval
        while t <= self.end:
            t += si / self.spiral.radius(t)
            r = self.spiral.radius(t + self.dev * pi/4.)
            pos = self.spiral.screen.to_cart(t, r)
            points.append(pos)

        draw.lines(surface, self.spiral.screen.gc("avatar", self.color),
                   False, points, 3)
Ejemplo n.º 19
0
 def draw(self, surf):
     if self.highlighted:
         r = self.get_margin_rect()
         fg = self.fg_color
         d = self.check_mark_tweak
         p1 = (r.left, r.centery - d)
         p2 = (r.centerx - d, r.bottom)
         p3 = (r.right, r.top - d)
         if self.smooth:
             draw.aalines(surf, fg, False, [p1, p2, p3])
         else:
             draw.lines(surf, fg, False, [p1, p2, p3])
Ejemplo n.º 20
0
    def __draw_line(self):
        if self.__pause:
            self.__pause -= 1
        else:
            scale = 1.5
            x = self.line_infected[-1][0] + 1
            total = (self.report.sick.count + self.report.sick_icu.count)
            y = int(round(500 - (total * scale), 0))
            self.line_infected.append((x, y))
            self.__pause = 1

        draw.lines(self.image, THECOLORS['black'], False, self.line_infected,
                   2)
Ejemplo n.º 21
0
 def draw_rect(self, surface):
     top_left = [
         self.objects[0].center[0] - int(self.objects[0].width / 2) - 1,
         self.objects[0].center[1] + int(self.height / 2) + 1
     ]
     top_right = [
         self.objects[2].center[0] + int(self.objects[2].width / 2) + 2,
         self.objects[2].center[1] + int(self.height / 2) + 1
     ]
     bottom_right = [top_right[0], top_right[1] - self.height - 2]
     bottom_left = [top_left[0], top_left[1] - self.height - 2]
     pygame_draw.lines(surface, colors['WHITE'], True,
                       [top_left, top_right, bottom_right, bottom_left])
Ejemplo n.º 22
0
def draw_points_of_interest(img, dest, roi=None):
    points = get_points_of_interest(img, 25, roi)
    indexes = nearest_indexes(points, roi)
    
    ordered_points = []
    for i in indexes:
        pt = quantize_point(points[i], roi)
        ordered_points.append(pt)
    
    draw.lines(dest, 
               pygame.Color("green"), 
               0, # filled
               ordered_points, 
               2)
Ejemplo n.º 23
0
 def draw(self):
     self.clear(self.viewport, globals.background)
     dirties=set(self.level.getDirtyLocations()).union(self.perception.getDirtyLocations())
     #dirties=[(i,j) for j in xrange(self.height) for i in xrange(self.width)]
     gray=globals.darkest_gray
     gray=ar((gray,gray,gray))
     white=1.0
     white=ar((white,white,white))
     npcs=[]
     for loc in dirties:
         if self.perception[loc].cover==1.0:
             self[loc].hue=copy(gray)
         else:
             self[loc].hue=copy(white)
             #obj = self.perception[loc].top().obj if self.perception[loc].top() else None
             #if isinstance(obj, Actor) and obj!=self.perception.actor:
             #   npcs.append((ar(loc), obj.facing, STATE_HUE_MAP[obj.state]))
     """
     for loc, facing, hue in npcs:
         print loc, facing, hue
         index=HEX_NEIGHBORS.index(facing)
         self[tuple(loc+facing)].hue+=hue
         self[tuple(loc+HEX_NEIGHBORS[index-1])].hue+=hue/2
         try:
             self[tuple(loc+HEX_NEIGHBORS[index+1])].hue+=hue/2
         except IndexError:
             self[tuple(loc+HEX_NEIGHBORS[0])].hue+=hue/2
     """
     for loc in dirties:
         try:
             element=self.perception[loc].top()
             #self[loc].image = globals.font.render(element.symbol,True,ar(map(max,map(min, self[loc].hue, MAX_COLOR), MIN_COLOR))*element.hue*(255,255,255))
             self[loc].image = element.obj.render(ar(map(max,map(min, self[loc].hue, MAX_COLOR), MIN_COLOR))*(255,255,255))
             if element.facing and element.obj != self.ctx.pc and (element.facing[0] or element.facing[1]):
                 h, w = globals.cell_height-1, globals.cell_width-1
                 pointlist = ()
                 vertical, horizontal = h*((element.facing[0] or element.facing[1])*0.5+0.5), w*((element.facing[1]-element.facing[0])*0.5+0.5)
                 print horizontal, w/2.0
                 if horizontal == w/2.0:
                     pointlist = ((horizontal-3, vertical-cmp(vertical, 1)*3), (horizontal, vertical), (horizontal+3, vertical-cmp(vertical,1)*3))
                 else:
                     pointlist = ((horizontal, vertical-cmp(vertical,1)*3), (horizontal, vertical), (horizontal-cmp(horizontal,1)*3, vertical))
                 draw.lines(self[loc].image, STATE_HUE_MAP[element.obj.state], False, pointlist, True)
         except AttributeError:
             pass
     pygame.display.update(super(GridView, self).draw(self.viewport))
     for tile in self.level.tiles:
         tile.dirty=0
     for tile in self.perception.tiles:
         tile.dirty=0
Ejemplo n.º 24
0
def draw(surface, colour, pos, radius, width, direction):
    left, right = "left" == direction, "right" == direction
    points = list()
    for i in range(radius):
        if left:
            angle = radians((i / radius) * 180 + 90)
        elif right:
            angle = radians((i / radius) * 180 - 90)
        else:
            angle = radians((i / radius) * 180)
        points.append(
            [cos(angle) * radius + pos[0],
             sin(angle) * radius + pos[1]])
    lines(surface, colour, False, points, width)
def renderHex(name, size = 64, color = Color(128,128,128), smooth = False, fill = False, dashed = False, width = 5):
    outscribeSize = size*2*math.tan(30*math.pi/180)
    surf = Surface((int(outscribeSize*2)+width*2,int(outscribeSize*2)+width*2))
    surf.fill(Color(0,0,0))
    points = []
    for deg in range(0,360,60):
        rad = math.pi/180 * deg
        points.append((outscribeSize+width+math.cos(rad)*(outscribeSize),
                       outscribeSize+width+math.sin(rad)*(outscribeSize)))
    if smooth:
        Draw.aalines(surf, color, True, points)
    else:
        Draw.lines(surf, color, True, points)
    Image.save(surf,name)
    print ("Hex {} rendered.  Inscribed radius: {}".format(name,outscribeSize*math.cos(30*math.pi/180)))
Ejemplo n.º 26
0
def test_lines_function(test_surf):
    """Test the draw.lines function"""
    points = [(10, 10), (20, 20), (30, 30), (10, 40), (20, 80), (20, 100),
              (200, 10), (200, 200), (10, 100), (20, 100), (30, 300),
              (40, 400), (50, 500)]
    draw.lines(test_surf, (255, 255, 255, 255), 0, points)
    points2 = [(x[0] + 5, x[1] + 5) for x in points]
    draw.lines(test_surf, (255, 255, 0, 255), 0, points2, 2)
    points2 = [(x[0] + 10, x[1] + 10) for x in points]
    draw.lines(test_surf, (255, 0, 0, 255), 0, points2, 3)
    points2 = [(x[0] + 30, x[1] + 30) for x in points]
    draw.lines(test_surf, (0, 255, 0, 255), 0, points2, 5)
    draw.lines(test_surf, (255, 255, 255, 255), 1, [(346, 134), (368, 146),
                                                    (362, 144), (371, 81),
                                                    (304, 116), (343, 102),
                                                    (375, 150), (334, 82),
                                                    (331, 94), (317, 134),
                                                    (312, 99), (337, 96)], 2)
Ejemplo n.º 27
0
def test_lines_function(test_surf):
    """Test the draw.lines function"""
    points = [(10, 10), (20, 20), (30, 30), (10, 40), (20, 80),
              (20, 100), (200, 10), (200, 200), (10, 100), (20, 100),
              (30, 300), (40, 400), (50, 500)]
    draw.lines(test_surf, (255, 255, 255, 255), 0, points)
    points2 = [(x[0] + 5, x[1] + 5) for x in points]
    draw.lines(test_surf, (255, 255, 0, 255), 0, points2, 2)
    points2 = [(x[0] + 10, x[1] + 10) for x in points]
    draw.lines(test_surf, (255, 0, 0, 255), 0, points2, 3)
    points2 = [(x[0] + 30, x[1] + 30) for x in points]
    draw.lines(test_surf, (0, 255, 0, 255), 0, points2, 5)
    draw.lines(test_surf, (255, 255, 255, 255), 1, [(346,134), (368, 146),
                                                    (362, 144), (371, 81),
                                                    (304, 116), (343, 102),
                                                    (375, 150), (334, 82),
                                                    (331, 94), (317, 134),
                                                    (312, 99), (337, 96)], 2)
Ejemplo n.º 28
0
 def blit_borders_on(self, surface):
     rect = Rect((0, 0), self.size)
     for x in range(0, self.thick):
         r = rect.inflate(-x, -x)
         tc = get_top_coords(r)
         bc = get_bottom_coords(r)
         if self.pressed:
             lines(surface, self.dark, False, tc, 1)
             lines(surface, self.light, False, bc, 1)
         else:
             lines(surface, self.light, False, tc, 1)
             lines(surface, self.dark, False, bc, 1)
Ejemplo n.º 29
0
 def blit_borders_on(self, surface):
     rect = Rect((0, 0), self.size)
     for x in range(0, self.thick):
         r = rect.inflate(-x, -x)
         tc = get_top_coords(r)
         bc = get_bottom_coords(r)
         if self.pressed:
             lines(surface, self.dark, False, tc, 1)
             lines(surface, self.light, False, bc, 1)
         else:
             lines(surface, self.light, False, tc, 1)
             lines(surface, self.dark, False, bc, 1)
Ejemplo n.º 30
0
    def _draw_lines(self, max_temp, min_temp, spacing, data, color):
        """
        Draws the lines for the weather graph

        :param max_temp: Maximum center_value of the graph
        :param min_temp: Minimum center_value of the graph
        :param spacing: the desired spacing between points
        :param data: the actual data to plot only the y values
        :param color:
        """
        circle_padding = 3
        font = pygame.font.SysFont('Arial', int(spacing // 8))

        # draw lines for center_value graph
        # generate point list based off of center_value values and sprite width
        point_list = []
        for x, temp in enumerate(data):
            point_list.append([
                x * spacing + spacing / 2,
                variable_mapping(temp, min_temp, max_temp,
                                 self.height - self.padding, self.padding)
            ])

        if self.antialiased:
            get_aalines_surface(self.image, point_list, self.thickness, color)
        else:
            draw.lines(self.image, color, False, point_list, self.thickness)

        # draw circles and center_value values
        for temp, point in zip(data, point_list):
            textsurface = font.render(f'{round(float(temp))}{self.unit}', True,
                                      self.text_color)
            textsurface_rect = textsurface.get_rect()
            textsurface_rect.center = point
            gfxdraw.aacircle(self.image, textsurface_rect.centerx,
                             textsurface_rect.centery,
                             textsurface_rect.width // 2 + circle_padding,
                             self.text_background_color)
            gfxdraw.filled_circle(self.image, textsurface_rect.centerx,
                                  textsurface_rect.centery,
                                  textsurface_rect.width // 2 + circle_padding,
                                  self.text_background_color)
            self.image.blit(textsurface, textsurface_rect)
Ejemplo n.º 31
0
    def draw(self, theSurface: Surface):
        """

        Args:
            theSurface:  The surface to draw on


        """
        if self.highlighted:
            r = self.get_margin_rect()
            fg = self.fg_color
            d = CHECK_MARK_TWEAK
            p1 = (r.left, r.centery - d)
            p2 = (r.centerx - d, r.bottom)
            p3 = (r.right, r.top - d)
            if self.smooth:
                draw.aalines(theSurface, fg, False, [p1, p2, p3])
            else:
                draw.lines(theSurface, fg, False, [p1, p2, p3])
Ejemplo n.º 32
0
    def draw(self, screen):

        self.dPoints = rtPoints(self.subdivPts)
        draw.polygon(screen, (0, 100, 0), self.dPoints, 0)
        gfxdraw.aapolygon(screen, self.dPoints, (0, 150, 0))

        draw.circle(screen, (255, 255, 255),
                    (int(self.center[0]), int(self.center[1])), 5)
        # for p in range(len(self.dPoints)):
        # 	pt = self.dPoints[p]
        # 	angle = self.normals[p]+cameraRotation
        # 	normal = pt[0]+cos(angle)*15,pt[1]+sin(angle)*15
        # 	draw.line(screen,(255,0,0),self.dPoints[p],normal,1)
        ins = rtPoints(self.inside)

        draw.polygon(screen, (112, 71, 71), ins, 0)
        gfxdraw.aapolygon(screen, ins, (112, 71, 71))

        for p in self.spikes:
            t = rtPoint(p)
            draw.lines(screen, (255, 0, 0), False, self.dPoints[p[0]:p[1]], 4)
Ejemplo n.º 33
0
 def get_imgs():
     """Load an return the images used as file and folder icons."""
     print "*** MCEDIT DEBUG: file_dialog:", __file__
     print "*** MCEDIT DEBUG: directory:", os.path.dirname(__file__)
     print "*** MCEDIT DEBUG: current directory:", os.getcwd()
     try:
         file_image = get_image('file.png', prefix='')
         folder_image = get_image('folder.png', prefix='')
     except Exception, e:
         print "MCEDIT DEBUG: Could not load file dialog images."
         print e
         from pygame import draw, Surface
         from pygame.locals import SRCALPHA
         from math import pi
         file_image = Surface((16, 16), SRCALPHA)
         file_image.fill((0,0,0,0))
         draw.lines(file_image, (255, 255, 255, 255), False, [[3, 15], [3, 1], [13, 1]], 2)
         draw.line(file_image, (255, 255, 255, 255), [3, 7], [10, 7], 2)
         folder_image = Surface((16, 16), SRCALPHA)
         folder_image.fill((0,0,0,0))
         draw.line(folder_image, (255, 255, 255, 255), [3, 15], [3, 1], 2)
         draw.arc(folder_image, (255, 255, 255, 255), [0, 1, 13, 15], 0, pi/1.9, 2)
         draw.arc(folder_image, (255, 255, 255, 255), [0, 1, 13, 15], 3*pi/2, 2*pi, 2)
Ejemplo n.º 34
0
 def draw_network_info(self, network, surface):
     """
     This method simultaneously displays the object name in the GUI bar and draws a path to the network name tab
     """
     topleft = [10, 10]
     first_point = list(
         self.tab_list.get_tab_center(self.networks.index(network)))
     second_point = [first_point[0], first_point[1] + 20]
     for obj in network.objects:
         # Display obj name on top-left
         text_render = self.basic_font.render(obj.name, True,
                                              (255, 255, 255))
         text_rect = text_render.get_rect()
         text_rect.topleft = topleft
         surface.blit(text_render, text_rect)
         topleft = [topleft[0], topleft[1] + 20]
         # Show network connection
         # print('GUI says object center is: {}'.format(obj_center))
         third_point = [obj.center[0], second_point[1]]
         fourth_point = [obj.center[0], int(obj.center[1] - obj.height / 2)]
         # print('Trying to draw network lines: {}'.format([first_point, second_point, third_point, fourth_point]))
         pygame_draw.lines(
             surface, colors['LIGHTGRAY'], False,
             [first_point, second_point, third_point, fourth_point])
Ejemplo n.º 35
0
 def draw_select_box(self, camera):
     if self.selected:
         self.resourcemgr.screen.lock()
         dx = self.w / 10
         dy = self.h / 10
         draw.lines(self.resourcemgr.screen, BLUE, False, (
             (self.rect.x - camera.rect.x + 3,
                 self.rect.y - camera.rect.y + 3 + dy),
             (self.rect.x - camera.rect.x + 3,
                 self.rect.y - camera.rect.y + 3),
             (self.rect.x - camera.rect.x + 3 + dx,
                 self.rect.y - camera.rect.y + 3),
         ), 2)
         draw.lines(self.resourcemgr.screen, BLUE, False, (
             (self.rect.x - camera.rect.x - 3 + self.w - dx,
                 self.rect.y - camera.rect.y + 3),
             (self.rect.x - camera.rect.x - 3 + self.w,
                 self.rect.y - camera.rect.y + 3),
             (self.rect.x - camera.rect.x - 3 + self.w,
                 self.rect.y - camera.rect.y + 3 + dy),
         ), 2)
         draw.lines(self.resourcemgr.screen, BLUE, False, (
             (self.rect.x - camera.rect.x - 3 + self.w,
                 self.rect.y - camera.rect.y - 3 + self.h - dy),
             (self.rect.x - camera.rect.x - 3 + self.w,
                 self.rect.y - camera.rect.y - 3 + self.h),
             (self.rect.x - camera.rect.x - 3 + self.w - dx,
                 self.rect.y - camera.rect.y - 3 + self.h),
         ), 2)
         draw.lines(self.resourcemgr.screen, BLUE, False, (
             (self.rect.x - camera.rect.x + 3 + dx,
                 self.rect.y - camera.rect.y - 3 + self.h),
             (self.rect.x - camera.rect.x + 3,
                 self.rect.y - camera.rect.y - 3 + self.h),
             (self.rect.x - camera.rect.x + 3,
                 self.rect.y - camera.rect.y - 3 + self.h - dy),
         ), 2)
         self.resourcemgr.screen.unlock()
Ejemplo n.º 36
0
    def lines(self, color, closed, pointlist, width=1):
        """複数の連結された直線を描画します.

        Parameters
        ----------
        color : tuple of int
            描画に使用される色を指定します.
        closed : bool
            Trueに設定された場合, 始点と終点を直線でつないで描画します.
        pointlist : array-like
            頂点の座標を格納した2次元配列.
            配列の2次元目の要素数は2で, 少なくとも2点以上の座標を設定する必要があります.
        width : float
            描画される直線の太さ.

        Returns
        -------
        rect : pygame.Rect
            描画によって影響を受けた範囲を示すpygame.Rectオブジェクトを返します.

        """

        return pyd.lines(self.pg.screen, color, closed, pointlist, width)
Ejemplo n.º 37
0
d.line(sun, (255, 255, 255, 150), (160, 134), (520, 141), 30)
d.line(sun, (255, 255, 255, 150), (345, -10), (327, 312), 30)
sun.set_colorkey(black)
main_screen.blit(sun, (0, 0))

# bobber (поплавок)
d.ellipse(bear, red, (447, 577, 20, 30))
d.rect(bear, see_water_color, (447, 592, 20, 30))
d.rect(bear, red, (447, 592, 20, 10))

# coil (катушка)
d.circle(bear, green, (249, 406), 15)
d.circle(bear, black, (249, 406), 10, 5)

# stick (палка = удочка)
d.lines(bear, black, False, [(180, 497), (220, 430), (450, 240)], 4)

# bear body
d.ellipse(bear, white, (95, 294, 120, 71))  # face
d.ellipse(bear, black, (94, 293, 122, 73), 2)  # head
d.circle(bear, black, (145, 323), 5)  # left eye
d.circle(bear, black, (215, 326), 5)  # right eye
d.lines(bear, black, False, [(144, 348), (173, 350), (210, 343)], 2)  # smile
d.ellipse(bear, white, (14, 350, 170, 320))  # body
d.ellipse(bear, black, (13, 349, 172, 322), 2)  # body
d.ellipse(bear, white, (102, 580, 135, 100))  # leg
d.ellipse(bear, black, (101, 579, 135, 102), 2)  # leg
d.ellipse(bear, white, (150, 421, 70, 30))  # hand
d.ellipse(bear, black, (149, 420, 72, 32), 2)  # hand

# bear ear
Ejemplo n.º 38
0
    def step(self, dots, shapes):
        for e in event.get():
            if e.type == QUIT:
                return True
            elif e.type == KEYDOWN:
                if e.key == K_ESCAPE:
                    return True
            elif e.type == VIDEORESIZE:
                self._make_screen(e.size)
                self.size_changed(self.size)
            elif e.type == MOUSEBUTTONDOWN and e.button == 1:
                self._drag_start = mouse.get_pos()
            elif e.type == MOUSEMOTION and 1 in e.buttons:
                if self._drag_start is not None:
                    p = mouse.get_pos()
                    if p != self._drag_start:
                        self.dragged(self._drag_start, p)
                        self._drag_start = p
            elif e.type == MOUSEBUTTONUP and e.button == 1:
                self._drag_start = None

                p = mouse.get_pos()
                w, h = self.size
                dw = 0
                for c in self._controls:
                    dw += c.width
                    if w - dw <= p[0] < w - dw + c.width:
                        c.click((p[0] - (w - dw), p[1]))
                        break

        self._sprites.empty()

        for dot in dots:
            sprite = Sprite()
            sprite.image = pygame.Surface((2 * dot.radius, 2 * dot.radius),
                                          flags=SRCALPHA)
            draw.circle(sprite.image, dot.color,
                        (dot.radius,dot.radius), dot.radius)
            sprite.rect = Rect(tuple([int(c) - dot.radius for c in dot.location]),
                               sprite.image.get_size())
            self._sprites.add(sprite)

        for shape in shapes:
            sprite = Sprite()
            sprite.image = pygame.Surface((int(shape.width), int(shape.height)),
                                          flags=SRCALPHA)
            points = [tuple([int(c) for c in p]) for p in shape.points]
            if len(points) > 2:
                draw.polygon(sprite.image, shape.color, points)
            else:
                draw.lines(sprite.image, shape.color, False, points)
            sprite.rect = Rect(tuple([int(c) for c in shape.location]),
                               sprite.image.get_size())
            self._sprites.add(sprite)
        
        self._sprites.clear(self._screen, self._background)
        self._sprites.draw(self._screen)
        
        display.flip()

        return False
Ejemplo n.º 39
0
	def redraw(self):
		offset_pointlist = [(self.buffer_x + x, self.buffer_y + y) for x, y in self.pointlist]
		draw.polygon(self.buffer, black, offset_pointlist)
		draw.lines(self.buffer, white, True, offset_pointlist)
Ejemplo n.º 40
0
	def render_to(self, screen):
		points = [(pole.x, pole.y - pole.size) for pole in self.poles]
		draw.polygon(screen, white, points)
		draw.lines(screen, white, True, points)
Ejemplo n.º 41
0
 def custom_update_actions(self, platforms, new_sprites_group, player):
     self.image.fill(PINK_TRANSPARENT)
     points = map(self.global2local, self._last_positions)
     draw.lines(self.image, WHITE, False, points, 1)
Ejemplo n.º 42
0
d.circle(sc, (255, 255, 255), (175, 135), 10)

d.circle(sun, (255, 255, 255, 150), (340, 140), 180, 25)
d.line(sun, (255, 255, 255, 150), (160, 134), (520, 141), 30)
d.line(sun, (255, 255, 255, 150), (345, -10), (327, 312), 30)
sun.set_colorkey((0, 0, 0))
sc.blit(sun, (0, 0))

d.ellipse(med, (255, 0, 0), (447, 577, 20, 30))
d.rect(med, (22, 80, 68), (447, 592, 20, 30))
d.rect(med, (0, 0, 255), (447, 592, 20, 10))

d.circle(med, (128, 128, 192), (249, 406), 15)
d.circle(med, (0, 0, 0), (249, 406), 10, 5)

d.lines(med, (0, 0, 1), False, [(180, 497), (220, 430), (450, 240)], 4)

d.ellipse(med, (255, 255, 255), (95, 294, 120, 71))
d.ellipse(med, (0, 0, 1), (94, 293, 122, 73), 1)
d.circle(med, (1, 0, 0), (145, 323), 5)
d.circle(med, (1, 0, 0), (215, 326), 5)
d.lines(med, (0, 0, 1), False, [(144, 348), (173, 350), (210, 343)], 1)
d.ellipse(med, (255, 255, 255), (14, 350, 170, 320))
d.ellipse(med, (0, 0, 1), (13, 349, 172, 322), 1)
d.ellipse(med, (255, 255, 255), (102, 580, 135, 100))
d.ellipse(med, (0, 0, 1), (101, 579, 135, 102), 1)
d.ellipse(med, (255, 255, 255), (183, 660, 100, 35))
d.ellipse(med, (0, 0, 1), (182, 659, 102, 37), 1)
d.ellipse(med, (255, 255, 255), (150, 421, 70, 30))
d.ellipse(med, (0, 0, 1), (149, 420, 72, 32), 1)
d.polygon(med, (255, 255, 255),
Ejemplo n.º 43
0
 def draw(self, win):
     self.refresh()
     draw.lines(win, self.color, False, self.pts, 1)
Ejemplo n.º 44
0
 def lines(self, color, points, closed=False, width=1, screen=False):
     points = points if screen else list(map(self._vec2_to_screen, points))
     return draw.lines(self.surface, color, closed, points, width)
Ejemplo n.º 45
0
        vertex = right

    elif down in coords and down not in vertices:
        vertices.append(coords.pop(coords.index(down)))
        vertex = down
    # Spanish
    # el problema parece estar acá. Con este orden, "cross" funciona pero "ene" es rotado 90º.
    # si pongo primero arriba y después izquierda, "ene" se renderiza bien, pero cross queda
    # en un loop infinito.

    # English
    # The problem seems to be here. With this order, "cross" works well, but "ene" is rotated 90º.
    # if I invert the order (up then left), "ene" renderizes correctly, but "cross" loops indefinitely.
    elif left in coords and left not in vertices:
        vertices.append(coords.pop(coords.index(left)))
        vertex = left

    elif up in coords and up not in vertices:
        vertices.append(coords.pop(coords.index(up)))
        vertex = up

# Here the result is rendered in a 32x32px image to make it more visible.
img = Surface((32, 32))
img.fill((255, 0, 0))

# the lines drawn are not antialialized. We want to see the pixeles.
draw.lines(img, (255, 255, 255), 1, [(x * 10, y * 10) for x, y in vertices])

# Here the image is saved. It always gets the same name to avoid wasting space.
image.save(img, 'result.png')
Ejemplo n.º 46
0
    print "*** MCEDIT DEBUG: file_dialog:", __file__
    print "*** MCEDIT DEBUG: directory:", os.path.dirname(__file__)
    print "*** MCEDIT DEBUG: current directory:", os.getcwd()
    try:
        file_image = image.load("file.png")
        folder_image = image.load("folder.png")
    except Exception, e:
        print "MCEDIT DEBUG: Could not load file dialog images."
        print e
        from pygame import draw, Surface
        from pygame.locals import SRCALPHA
        from math import pi

        file_image = Surface((16, 16), SRCALPHA)
        file_image.fill((0, 0, 0, 0))
        draw.lines(file_image, (255, 255, 255, 255), False, [[3, 15], [3, 1], [13, 1]], 2)
        draw.line(file_image, (255, 255, 255, 255), [3, 7], [10, 7], 2)
        folder_image = Surface((16, 16), SRCALPHA)
        folder_image.fill((0, 0, 0, 0))
        draw.line(folder_image, (255, 255, 255, 255), [3, 15], [3, 1], 2)
        draw.arc(folder_image, (255, 255, 255, 255), [0, 1, 13, 15], 0, pi / 1.9, 2)
        draw.arc(folder_image, (255, 255, 255, 255), [0, 1, 13, 15], 3 * pi / 2, 2 * pi, 2)
else:  # windows
    file_image = image.load("file.png")
    folder_image = image.load("folder.png")


class DirPathView(Widget):
    def __init__(self, width, client, **kwds):
        Widget.__init__(self, **kwds)
        self.set_size_for_text(width)
Ejemplo n.º 47
0
        print("*** MCEDIT DEBUG: file_dialog:", __file__)
        print("*** MCEDIT DEBUG: directory:", os.path.dirname(__file__))
        print("*** MCEDIT DEBUG: current directory:", os.getcwd())
        try:
            file_image = image.load('file.png')
            folder_image = image.load('folder.png')
        except Exception as e:
            print("MCEDIT DEBUG: Could not load file dialog images.")
            print(e)
            from pygame import draw, Surface
            from pygame.locals import SRCALPHA
            from math import pi

            file_image = Surface((16, 16), SRCALPHA)
            file_image.fill((0, 0, 0, 0))
            draw.lines(file_image, (255, 255, 255, 255), False,
                       [[3, 15], [3, 1], [13, 1]], 2)
            draw.line(file_image, (255, 255, 255, 255), [3, 7], [10, 7], 2)
            folder_image = Surface((16, 16), SRCALPHA)
            folder_image.fill((0, 0, 0, 0))
            draw.line(folder_image, (255, 255, 255, 255), [3, 15], [3, 1], 2)
            draw.arc(folder_image, (255, 255, 255, 255), [0, 1, 13, 15], 0,
                     pi / 1.9, 2)
            draw.arc(folder_image, (255, 255, 255, 255), [0, 1, 13, 15],
                     3 * pi / 2, 2 * pi, 2)
    else:  # windows
        # file_image = image.load(os.path.join(getDataDir(), 'file.png'))
        # folder_image = image.load(os.path.join(getDataDir(), 'folder.png'))
        file_image = image.load(getDataFile('file.png'))
        folder_image = image.load(getDataFile('folder.png'))