Прикреплённый файл «sgcradio.py»
Загрузка 1 #!/usr/bin/env python
2 # coding: utf
3 '''
4 Try to decorate sgc Radio()
5 '''
6
7 from pygame.locals import *
8 from pygame import draw, gfxdraw, Color
9 from sgc import Radio
10
11 class AARadio(Radio):
12 _default_size = (27,27)
13
14 def _light(self, c, n, F=100):
15 for i in xrange(n):
16 col = Color(*c)
17 H,S,L,A = col.hsla
18 col.hsla = H, S, (L*(n-1-i)+F*i)/n, A
19 yield col
20
21 def _draw_base(self):
22 pos = self.rect.center
23 r = min(self.rect.size) / 2
24 # Background circles
25 for rr, col in zip(xrange(r,1,-1),self._light((128,128,128,255),r-1)):
26 draw.circle(self._images["image"], col, pos, rr)
27 #gfxdraw.filled_circle(self._images["image"], pos[0], pos[1], r, (255,255,255))
28 for rr, col in zip(xrange(r,1,-1),self._light(self._settings["col"],r-1)):
29 draw.circle(self._images["over"], col, pos, rr)
30 # Border circles
31 gfxdraw.aacircle(self._images["image"], pos[0], pos[1], r, (0,0,1))
32 gfxdraw.aacircle(self._images["over"], pos[0], pos[1], r, (0,0,1))
33
34 def _draw_active(self, image, size):
35 # Central dot for 'active' state
36 r = min(size) / 2
37 pos = (size[0] / 2, size[1] / 2)
38 for rr, col in zip(xrange(r,1,-1),self._light((240,240,240),r-1,0)):
39 print col
40 draw.circle(image, col, pos, rr)
41
42 def __example__():
43 import pygame
44 import sgc
45 pygame.init()
46 f = pygame.font.SysFont("Droid sans",24)
47 root = sgc.surface.Screen((800,600))
48 root.image.fill((16,64,0))
49 clock = pygame.time.Clock()
50 r = [sgc.Radio(group="r", label=l, col = (192,200,255)) for l in "One","Two","Three"]
51 ar = [AARadio(group="ar", label=l, col = (192,200,255), label_font = f) for l in "One","Two","Three"]
52 rbox = sgc.VBox(widgets=r, pos=(3,3))
53 arbox = sgc.VBox(widgets=ar, pos=(100,3))
54 rbox.add(order=1)
55 arbox.add(order=2)
56 again = True
57
58 while again:
59 time = clock.tick(30)
60 for event in pygame.event.get():
61 if event.type == pygame.QUIT:
62 again = False
63 sgc.event(event)
64 sgc.update(time)
65 pygame.display.flip()
66
67 if __name__ == "__main__":
68 __example__()
Прикреплённые файлы
Для ссылки на прикреплённый файл в тексте страницы напишите attachment:имяфайла, как показано ниже в списке файлов. Не используйте URL из ссылки «[получить]», так как он чисто внутренний и может измениться.- [получить | показать] (2014-03-14 14:56:06, 2.2 KB) [[attachment:2014-03-07-grafun-sgc.py]]
- [получить | показать] (2014-03-14 14:56:17, 2.2 KB) [[attachment:sgcradio.py]]
Вам нельзя прикреплять файлы к этой странице.