本文整理汇总了Python中pygame.draw.line函数的典型用法代码示例。如果您正苦于以下问题:Python line函数的具体用法?Python line怎么用?Python line使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了line函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: draw
def draw(self, surface):
frame = self.get_margin_rect()
fg = self.fg_color
font = self.font
focused = self.has_focus()
text, i = self.get_text_and_insertion_point()
if focused and i is None:
if self.selection_start is None or self.selection_end is None:
surface.fill(self.sel_color, frame)
else:
startStep = self.selection_start
endStep = self.selection_end
if startStep > endStep:
x1, h = font.size(text[0:endStep])[0], font.get_linesize()
x2, h = font.size(text[0:startStep])[0], font.get_linesize()
x1 += frame.left
x2 += frame.left
y = frame.top
selRect = pygame.Rect(x1, y, (x2 - x1), h)
else:
x1, h = font.size(text[0:startStep])[0], font.get_linesize()
x2, h = font.size(text[0:endStep])[0], font.get_linesize()
x1 += frame.left
x2 += frame.left
y = frame.top
selRect = pygame.Rect(x1, y, (x2 - x1), h)
draw.rect(surface, self.sel_color, selRect)
image = font.render(text, True, fg)
surface.blit(image, frame)
if focused and i is not None:
x, h = font.size(text[:i]) #[0], font.get_linesize()
x += frame.left
y = frame.top
draw.line(surface, fg, (x, y), (x, y + h - 1))
开发者ID:cosmoharrigan,项目名称:MCEdit-Unified,代码行数:35,代码来源:fields.py
示例2: draw
def draw(self):
bgrect = wzglobals.background.get_rect()
menupos = wzglobals.menu_bg.get_rect()
menupos.centery = wzglobals.background.get_rect().centery
# label X coord (left side from center)
self.label_rect.left = bgrect.centerx - self.label_rect.width - 7
self.label_rect.top = menupos.top + 50 + \
(self.label_rect.height + 5) * self.pos
# text X coord (right size from center)
self.text_rect.left = bgrect.centerx + 7
self.text_rect.top = self.label_rect.top
self.image = pygame.Surface(
(self.label_rect.width + 14 + self.size, self.font.get_linesize()),
pygame.SRCALPHA
)
self.rect = self.image.get_rect()
self.rect.left = self.label_rect.left
self.rect.top = self.label_rect.top
self.image.blit(self.label_image, (0, 0))
self.image.blit(self.text_image, (self.label_rect.width + 14, 0))
if self.focus:
# X coordinate of the cursor
cursorx = self.font.size(self.text[:self.currpos])[0]
cursorx += self.label_rect.width + 14
draw.line(
self.image,
(255, 255, 255),
(cursorx, 0),
(cursorx, self.font.get_height())
)
wzglobals.background.blit(self.image, self.label_rect)
开发者ID:sandrobonazzola,项目名称:wizards-magic2,代码行数:34,代码来源:widgets.py
示例3: draw_graph_box_and_legend
def draw_graph_box_and_legend(self):
x_end = self.left_bottom_corner_of_graph[0] + self.graph_box_length
# y_end = self.left_bottom_corner_of_graph[1] - self.graph_box_length
color = (30,30,30)
draw.line(self.screen, color,
self.left_bottom_corner_of_graph,
(self.left_bottom_corner_of_graph[0] + self.graph_box_length,
self.left_bottom_corner_of_graph[1]))
draw.line(self.screen, color,
self.left_bottom_corner_of_graph,
(self.left_bottom_corner_of_graph[0],
self.left_bottom_corner_of_graph[1] - self.graph_box_length))
# legend
x = self.field_length+padding_graph
y = 10
if not compare_wv_counts:
rectsize = 15
for legend_item_name, (legend_item_color,_) in self.legend_items.items():
draw.rect(self.screen, Color(legend_item_color), [x,y, rectsize,rectsize])
x += rectsize + 10
x_size_text = self.draw_text(legend_item_name, x, y)
x += x_size_text + 20
elif compare_avg_qual_per_wv==1:
self.draw_text("Average quality per WV",x,y)
else:
self.draw_text("WV distribution",x,y)
开发者ID:Arnatar,项目名称:ideas-papo2014,代码行数:26,代码来源:draw.py
示例4: draw_spring
def draw_spring(self, spring):
draw.line(
self.window.display_surface,
(80, 120, 90),
spring.verts_to_anchor1(spring.p1.verts),
spring.verts_to_anchor2(spring.p2.verts),
15)
开发者ID:mjs,项目名称:ldnpydojo,代码行数:7,代码来源:render.py
示例5: refresh
def refresh(self):
self.offset = self.style['offset']
if self.size[1] < self.style['font'].get_ascent() + self.offset[1] * 2:
self.size = (self.size[0], self.style['font'].get_ascent() + self.offset[1] * 2)
self.textsurf = self.style['font'].render(self.pwdtext, self.style['antialias'], self.style['font-color'])
if not self.surf or self.surf.get_size() != self.size:
self.surf = pygame.Surface(self.size, pygame.SRCALPHA)
if self.hasFocus:
suffix = '-focus'
else:
suffix = '-normal'
self.surf.fill(self.style['bg-color' + suffix])
textpos = (self.offset[0], self.size[1] / 2.0 - self.textsurf.get_height() / 2)
cursorWidth = self.style['font'].size(self.pwdtext[:self.currpos])[0]
cursorx = cursorWidth + self.offset[0]
self.textWidth = self.textsurf.get_width()
if cursorWidth - self._textStartX < self.size[0] - self.offset[0] * 2:
if cursorx - self._textStartX < 0:
self._textStartX = max(0, cursorx - (self.size[0] - self.offset[0] * 2))
else:
self._textStartX = cursorWidth - (self.size[0] - self.offset[0] * 2)
self.surf.blit(self.textsurf, textpos, Rect(self._textStartX, 0, self.size[0] - self.offset[0] * 2, self.textsurf.get_height()))
if self.hasFocus:
cursorx -= self._textStartX
draw.line(self.surf, (255, 255, 255), (cursorx, self.offset[1]), (cursorx, self.size[1] - self.offset[1]))
if self.style['appearence'] == APP_FLAT:
draw.rect(self.surf, self.style['border-color' + suffix], Rect((0, 0), self.size), self.style['border-width'])
else:
bgcolor = self.style['bg-color' + suffix]
color_dark = colorLuminosity(bgcolor, -50)
color_light = colorLuminosity(bgcolor, +30)
draw.line(self.surf, color_dark, (0, 0), (self.size[0] - 2, 0))
draw.line(self.surf, color_dark, (0, 0), (0, self.size[1] - 2))
draw.line(self.surf, color_light, (1, self.size[1] - 1), (self.size[0], self.size[1] - 1))
draw.line(self.surf, color_light, (self.size[0] - 1, 1), (self.size[0] - 1, self.size[1] - 1))
开发者ID:249550148,项目名称:mygame,代码行数:35,代码来源:gui.py
示例6: draw_points
def draw_points(poly, surface, color=None, width=None):
polygon = orient_multipoint(poly)
c = polygon.centroid.coords[0]
p = poly.position
dx, dy = [p[i] - c[i] for i in range(2)]
if color is None:
color = (0,255,0)
if width is None:
width = 1
maxd = (0,None,None)
for i in range(len(polygon.geoms)):
p = polygon.geoms[i]
draw.circle(surface, color,
defloat(scale(offset((p.x,p.y), dx, dy))),
3*width)
for j in range(i+1, len(polygon.geoms)):
q = polygon.geoms[j]
d = p.distance(q)
if d > maxd[0]:
maxd = (d, p, q)
if maxd[0] > 0:
p, q = maxd[1], maxd[2]
draw.line(surface, color,
defloat(scale(offset((p.x,p.y), dx, dy))),
defloat(scale(offset((q.x,q.y), dx, dy))), width)
开发者ID:tps12,项目名称:Why-So-Spherious,代码行数:27,代码来源:Collide.py
示例7: draw
def draw(self, surface, offset):
adjusted_origin = (self.origin[0] + offset[0], self.origin[1] + offset[1])
adjusted_target = (self.target[0] + offset[0], self.target[1] + offset[1])
real_colour = [self.colour[i] - self.degrade[i] * self.age for i in range(3)]
draw.line(surface, bound_colour(real_colour), adjusted_origin, adjusted_target, 2)
开发者ID:erasmusa,项目名称:sequtus,代码行数:7,代码来源:effects.py
示例8: update
def update(self):
ps = [self._position(loc)
for loc in self.region]
if len(self._ps) == len(ps) and all([self._ps[i] == ps[i]
for i in range(len(ps))]):
return
self._ps = ps
pos = [min([p[i] for p in self._ps]) for i in range(2)]
adj = self._zoom.width+self._zoom.height/3, self._zoom.height + 1
size = [max([p[i] for p in self._ps]) - pos[i] + adj[i]
for i in range(2)]
self.image = Surface(size, flags=SRCALPHA)
lines = []
for p in self._ps:
for edge in [sorted([[v[j][i] + p[i] - pos[i]
for i in range(2)]
for j in range(2)])
for v in self._lines()]:
if edge in lines:
lines.remove(edge)
else:
lines.append(edge)
for line in lines:
draw.line(self.image, self._color, line[0], line[1])
self.rect = self.image.get_rect().move((pos[0]-self._zoom.height/3,
pos[1]))
self.dirty = 1
开发者ID:tps12,项目名称:Dorftris,代码行数:29,代码来源:playfield.py
示例9: _blit_cursor
def _blit_cursor(self):
"""
Blits the cursor at proper position
"""
self.cursorx -= self._textStartX
strt = self.cursorx ,self.size[1]-self.textsurf.get_height()
end = self.cursorx , self.size[1] - self.offset[1]
draw.line(self.surf, (255,255,255), strt, end)
开发者ID:geijoenr,项目名称:pyXPS,代码行数:8,代码来源:CConsole.py
示例10: test_horz_line_width
def test_horz_line_width(test_surf):
"""Draw several horizontal lines, varying in width."""
y = 10
for width in range(20):
y += 5 + 2*width
length = 10 * width
draw.line(test_surf, (255, 255, 255, 255), (y, y), (y + length, y),
width)
开发者ID:GertBurger,项目名称:pygame_cffi,代码行数:8,代码来源:test_lines.py
示例11: test_vert_line_width
def test_vert_line_width(test_surf):
"""Draw several vertical lines, varying in width."""
x = 10
for width in range(20):
x += 5 + 2*width
length = 10 * width
draw.line(test_surf, (255, 255, 255, 255), (x, 2*width),
(x, 2*width + length), width)
开发者ID:GertBurger,项目名称:pygame_cffi,代码行数:8,代码来源:test_lines.py
示例12: draw_quad_node
def draw_quad_node(screen, qnode):
print("xmid: ", qnode.xmid)
print("ymid: ", qnode.ymid)
draw.line(screen, (0,0,0), (qnode.xmid, qnode.ymin), (qnode.xmid, qnode.ymax), 2)
draw.line(screen, (0,0,0), (qnode.xmin, qnode.ymid), (qnode.xmax, qnode.ymid), 2)
if qnode.children:
for child in qnode.children:
draw_quad_node(screen, child)
开发者ID:pagea,项目名称:quadtree-demo,代码行数:8,代码来源:front.py
示例13: refresh
def refresh(self):
#Save this information coz it's frequently used
self.offset = self.style['offset']
if self.size[1] < self.style['font'].get_ascent() + self.offset[1]* 2:
self.size = self.size[0], self.style['font'].get_ascent() + self.offset[1]* 2
#Creates the surface with the rendered text
self.textsurf = self.style['font'].render(self.text, self.style['antialias'], self.style['font-color'])
#Creates a new widget surface if None or different size from widget size
if not self.surf or self.surf.get_size() != self.size:
self.surf = pygame.Surface(self.size, pygame.SRCALPHA)
if self.hasFocus:
suffix = "-focus"
else:
suffix = "-focus"
#Background
self.surf.fill(self.style['bg-color' + suffix])
#Calculates the position of the text surface
textpos = self.offset[0], self.size[1] / 2. - self.textsurf.get_height() / 2
#Width of the text until the cursor
cursorWidth = self.style['font'].size(self.text[:self.currpos])[0]
#X coordinate of the cursor
cursorx = cursorWidth + self.offset[0]
#Total width of the text
self.textWidth = self.textsurf.get_width()
if cursorWidth - self._textStartX < self.size[0] - self.offset[0] * 2 :
if cursorx - self._textStartX < 0:
self._textStartX = max(0, cursorx - (self.size[0] - self.offset[0] * 2))
else:
self._textStartX = cursorWidth - (self.size[0] - self.offset[0] * 2)
#Blits the text surface in the appropriate position
self.surf.blit(self.textsurf, textpos, Rect(self._textStartX ,0, self.size[0] - self.offset[0] * 2, self.textsurf.get_height()))
#Draws the cursor
cursorx -= self._textStartX
draw.line(self.surf, (255,255,255), (cursorx ,self.offset[1]),(cursorx , self.size[1] - self.offset[1]))
#Renders the border
if self.style['appearence'] == APP_FLAT:
draw.rect(self.surf, self.style['border-color' + suffix], Rect((0,0), self.size), self.style['border-width'])
else:
bgcolor = self.style['bg-color' + suffix]
color_dark = colorLuminosity(bgcolor,-50)
color_light = colorLuminosity(bgcolor,+30)
#color_corner = mixColors(color_dark, color_light)
draw.line(self.surf,color_dark, (0,0), (self.size[0]-2,0)) #TOP
draw.line(self.surf,color_dark, (0,0), (0,self.size[1]-2)) #LEFT
draw.line(self.surf,color_light, (1,self.size[1]-1), (self.size[0],self.size[1]-1)) #LEFT
draw.line(self.surf,color_light, (self.size[0]-1,1), (self.size[0]-1,self.size[1]-1)) #LEFT
开发者ID:danielz360,项目名称:Maya,代码行数:58,代码来源:gui.py
示例14: test_lines
def test_lines(test_surf):
"""Draw a collection of angled and overlapping lines."""
start = [(10, 10), (20, 20), (30, 30), (10, 40), (20, 80),
(20, 100), (200, 10), (200, 200)]
end = [(10, 100), (20, 100), (30, 300), (40, 400), (50, 500)]
for p1 in start:
for p2 in end:
draw.line(test_surf, (255, 255, 255, 255), p1, p2)
开发者ID:GertBurger,项目名称:pygame_cffi,代码行数:9,代码来源:test_lines.py
示例15: draw_board
def draw_board(screen, gobang):
clear_screen(screen)
size = gobang.board_size + 1
lines = size + 1
for i in xrange(lines):
draw.line(screen, linecolor, (edge_width, edge_width + i * grid_size),\
(edge_width + size * grid_size, edge_width + i * grid_size))
draw.line(screen, linecolor, (edge_width + i * grid_size, edge_width),\
(edge_width + i * grid_size, edge_width + size * grid_size))
draw_chess(screen, gobang)
开发者ID:chqiwang,项目名称:gobang,代码行数:10,代码来源:inter.py
示例16: show
def show(self):
h = self.FONT.get_height()
x,y = self._x,self._y
r = pygame.Rect(x,y,0,h)
for e,i in enumerate(self.OUTPUT+'\n'):
if e == self.CURSORINDEX+1: break
if i not in '\n\t':
r = pygame.Rect(x,y,*self.FONT.size(i))
x = r.right
elif i == '\n':
r = pygame.Rect(x,y,1,h)
x = self._x
y = r.bottom
else:
t = self.FONT.size(self.TAB*' ')[0]
t = ((((x-self._x) / t) + 1) * t ) - (x-self._x)
r = pygame.Rect(x,y,t,h)
x = r.right
rclamp = r.clamp(self)
self._x += rclamp.x - r.x
self._y += rclamp.y - r.y
clip = self.SRC.get_clip()
self.SRC.set_clip(self.clip(clip))
try: self.SRC.fill(self.BG,self)
except: self.SRC.blit(self.BG,self)
x = self._x
y = self._y
select1,select2 = sorted((self.SELECTSTART,self.CURSORINDEX))
self.C = []
for e,i in enumerate(self.OUTPUT):
if i not in '\n\t':
self.C.append(pygame.Rect(x,y,*self.FONT.size(i)))
if select1 <= e < select2:
scr.blit(self.FONT.render(i,1,self.HLCOLOR),(x,y))
else:
scr.blit(self.FONT.render(i,1,self.FGCOLOR),(x,y))
x = self.C[-1].right
elif i == '\n':
self.C.append(pygame.Rect(x,y,0,h))
x=self._x
y = self.C[-1].bottom
else:
t = self.FONT.size(self.TAB*' ')[0]
t = ((((x-self._x) / t) + 1) * t ) - (x-self._x)
self.C.append(pygame.Rect(x,y,t,h))
x = self.C[-1].right
self.C.append(pygame.Rect(x,y,0,h))
if self.CURSOR:
p = self.C[self.CURSORINDEX]
draw.line(scr,self.CURSCOLOR,p.topleft,(p.left,p.bottom),1)
pygame.display.update(self)
self.SRC.set_clip(clip)
开发者ID:rashrag,项目名称:LogSim,代码行数:54,代码来源:input.py
示例17: draw
def draw(self, surface):
frame = self.get_margin_rect()
fg = self.fg_color
font = self.font
text, i = self.get_text_and_insertion_point()
image = font.render(text, True, fg)
surface.blit(image, frame)
if self.has_focus():
x, h = font.size(text[:i])
x += frame.left
y = frame.top
draw.line(surface, fg, (x, y), (x, y + h - 1))
开发者ID:FinnStokes,项目名称:orpheus,代码行数:12,代码来源:controls.py
示例18: draw
def draw( self ):
width, height = self.surface.get_size()
# vertical lines
vertical_line_spacing = width / self.grid_lines
for i in range( self.grid_lines ):
draw.line( self.surface, self.color, ( i * vertical_line_spacing, 0 ), ( i * vertical_line_spacing, height ), 1 )
# horizontal lines
horizontal_line_spacing = int( height / self.grid_lines )
for j in range( self.grid_lines ):
draw.line( self.surface, self.color, ( 0, j * horizontal_line_spacing ), ( width, j * horizontal_line_spacing ), 1 )
开发者ID:gvenkat,项目名称:chain-reaction,代码行数:12,代码来源:grid.py
示例19: redraw
def redraw(self):
"""Basic screens do not have scrolling capabilities
you'd need to use a subclass for that"""
if time.time() < self._next_redraw:
return
surf = self.engine.display
surf.fill(self.background_colour)
# Draw divider lines
draw.line(surf, (0,0,0), (200, 0), (200, 600), 5)
draw.line(surf, (0,0,0), (400, 0), (400, 600), 5)
draw.line(surf, (0,0,0), (0, 200), (600, 200), 5)
draw.line(surf, (0,0,0), (0, 400), (600, 400), 5)
# Draw game state
for i in range(9):
x = i % 3
y = math.floor(i/3)
self.draw_place(surf, x, y, self.state[i])
self.draw_transition()
pygame.display.flip()
self._next_redraw = time.time() + self._redraw_delay
开发者ID:Teifion,项目名称:mp_tictactoe,代码行数:30,代码来源:ttt_screen.py
示例20: show
def show(self, screen):
W, H = self.wc, self.hc
sx , sy = self.sx, self.sy
for y in range(self.h - 1):
for x in range(self.w - 1):
c = self.get_cell(x, y)
if c.gate[const.right]:
draw.line(screen, const.black, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
if c.gate[const.down]:
draw.line(screen, const.black, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
x = self.w - 1
for y in range(self.h - 1):
c = self.get_cell(x, y)
if c.gate[const.down]:
draw.line(screen, const.black, ((sx + (x * W)), (sy + ((y+1) * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
y = self.h - 1
for x in range(self.w - 1):
c = self.get_cell(x, y)
if c.gate[const.right]:
draw.line(screen, const.black, (sx + ((x + 1) * W), (sy + (y * H))), (sx + ((x + 1) * W), sy + ((y+1) * H)), 2)
draw.rect(screen, const.black, (sx, sy, W * self.w, H * self.h), 2)
开发者ID:tbourg,项目名称:perso,代码行数:32,代码来源:Classe.py
注:本文中的pygame.draw.line函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论