Прикреплённый файл «label.py»
Загрузка 1 #!/usr/bin/env python
2 # coding: utf
3 '''
4 Простейший пример печати текста для PyGame
5 '''
6
7 import pygame, os
8
9 def Label(scr, text, pos=(0,0), size=12, fg="White", bg=None, font="mono", centered=False):
10 '''Рисует текст text на экране scr по координатам pos.
11 Параметры fg и bg могут быть Color() или str().
12 Параметр font может быть именем файла, типом шрифта или объектом Font()
13 При установленном centered pos считается координатами центра'''
14 if type(fg) is str: fg=pygame.Color(fg)
15 if type(bg) is str: bg=pygame.Color(bg)
16 if type(font) is str:
17 if font[0] != os.path.sep:
18 font=pygame.font.match_font(font)
19 font=pygame.font.Font(font, size)
20 rect=pygame.Rect(pos,font.size(text))
21 if centered: rect.move_ip((-rect.width/2,-rect.height/2))
22 if bg:
23 scr.blit(font.render(text, True, fg, bg), rect)
24 else:
25 scr.blit(font.render(text, True, fg), rect)
26 return rect
27
28 if __name__ == "__main__":
29 import random
30 pygame.init()
31 Size=(800,400)
32 Scr=pygame.display.set_mode(Size)
33 Scr.fill(pygame.Color("Black"))
34 r=20
35 for i in xrange(100):
36 pos=random.randint(r,Size[0]-r),random.randint(r,Size[1]-r)
37 col=random.randint(10,255),random.randint(10,255),random.randint(10,255)
38 pygame.draw.circle(Scr,col,pos,r)
39 cont=True
40 while cont:
41 ev=pygame.event.wait()
42 if ev.type is pygame.QUIT:
43 cont=False
44 sz=random.randrange(10,32)
45 txt="Hello!"
46 pos=random.randrange(0,Size[0]-3*sz),random.randrange(0,Size[1]-sz)
47 rect=Label(Scr,txt,pos,sz)
48 rect.inflate_ip((sz/2,sz))
49 pygame.draw.ellipse(Scr,pygame.Color("Orange"),rect,1)
50 pygame.display.flip()
Прикреплённые файлы
Для ссылки на прикреплённый файл в тексте страницы напишите attachment:имяфайла, как показано ниже в списке файлов. Не используйте URL из ссылки «[получить]», так как он чисто внутренний и может измениться.- [получить | показать] (2013-03-15 13:03:07, 2.4 KB) [[attachment:2013-02-22.function.py]]
- [получить | показать] (2013-03-15 13:01:55, 3.1 KB) [[attachment:2013-03-01.arrow.py]]
- [получить | показать] (2013-03-15 13:00:29, 2.7 KB) [[attachment:2013-03-01.drawtree.py]]
- [получить | показать] (2013-03-15 13:02:44, 2.5 KB) [[attachment:2013-03-01.pong.py]]
- [получить | показать] (2013-03-15 13:01:31, 1.9 KB) [[attachment:label.py]]
Вам нельзя прикреплять файлы к этой странице.