, . , draw.circle. , ( , ). pygame 1.9.2 Windows, - Atom 1,6 , 40 (. DT ). , . . , colorkey?
def circle(r, x0, y0, dest, value):
x1 = int(r / math.sqrt(2))
h = []
x = x1
while(1):
x += 1
if x == r:
h.append(ch/3)
break
ch = int(math.sqrt(r**2-x**2))
h.append(ch)
p = 0
dest[x0-x1:x0+x1+1, y0-x1:y0+x1+1] = value
while p < len(h):
dest[x0+x1+p+1, y0-h[p]:y0+h[p]+1] = value
dest[x0-x1-p-1, y0-h[p]:y0+h[p]+1] = value
dest[x0-h[p]:x0+h[p]+1, y0-x1-p-1] = value
dest[x0-h[p]:x0+h[p]+1, y0+x1+p+1] = value
p += 1
def put_alpha(Dest, Src):
ref = pygame.surfarray.pixels_alpha (Dest)
numpy.copyto(ref, Src)
del ref
Layer = pygame.Surface ((w,h),flags = pygame.SRCALPHA)
Layer.fill(0xff4B432E)
Mask = numpy.zeros((w,h), dtype = numpy.uint8)
Mask[:] = 255
cur_time = pygame.time.get_ticks()
old_time = cur_time
circle(125, 400, 300, Mask, 125)
circle(75, 400, 300, Mask, 255)
put_alpha(Layer, Mask)
cur_time = pygame.time.get_ticks()
DT = cur_time - old_time
print DT
:
-, 5 , pygame, , .
. -, , 24- , 256 , . , "24 32 24". . .
pygame.init()
w = 800
h = 600
DISP = pygame.display.set_mode((w, h), 0, 24)
clock = pygame.time.Clock( )
Noise = pygame.Surface ((w,h))
Noise.fill((110,0,10))
color24bit = (169, 163, 144)
color = (169, 163, 144, 255)
color_a = (169, 163, 144, 112)
Layer = pygame.Surface ((w,h), flags = pygame.SRCALPHA)
Layer.fill(color)
Layer_colorkey = pygame.Surface ((w,h))
Layer_colorkey.fill(color24bit)
color_key = (50, 50, 50)
Layer_colorkey.set_colorkey(color_key)
print Noise.get_bitsize(), Layer.get_bitsize(), Layer_colorkey.get_bitsize()
Mask = numpy.zeros((w,h), dtype = numpy.uint8)
Mask[:] = 255
t=0
cur_time = pygame.time.get_ticks()
old_time = cur_time
while t < 0:
circle(296, 400, 300, Mask, 112)
circle(15, 400, 300, Mask, 255)
put_alpha(Layer, Mask)
Noise.blit(Layer,(0,0))
DISP.blit(Noise,(0,0))
t += 1
while t < 0:
pygame.draw.circle(Layer, color_a, (400,300), 296, 0)
pygame.draw.circle(Layer, color, (400,300), 15, 0)
Noise.blit(Layer,(0,0))
DISP.blit(Noise,(0,0))
t += 1
while t < 1:
pygame.draw.circle(Layer_colorkey, color_key, (400,300), 296, 0)
pygame.draw.circle(Layer_colorkey, color, (400,300), 15, 0)
Noise.blit(Layer_colorkey,(0,0))
DISP.blit(Noise,(0,0))
t += 1
cur_time = pygame.time.get_ticks()
DT = cur_time - old_time
print "time:", DT
:
1. : , .
2. + , -. Litle (ITPC), .
3. 24- colorkey. 2x , , .