【发布时间】:2021-05-17 23:52:01
【问题描述】:
我有这个类调用透明度函数来在我的外圆后面创建一个透明的内圆,问题是这个圆的不透明度与创建的每个对象相乘导致这个问题:
这不是我想要的,我对如何在每个圆圈中只调用一次这个函数没有太多想法,我之前尝试将函数调用放在 init def 本身中,但它不记得了它做我想做的事。
最后,所有的圆圈应该是这样的
这是我的名为透明度的类和不透明度函数(我知道它应该称为不透明度,而不是我只是 pepega),以及我通过另一个文件调用该类的函数
import pygame
def transparency(self,surface, inner_surface, size, x, y):
self.circle = pygame.draw.circle(inner_surface, (255, 255, 255, 10), (x,y), int(size[0]/2)-5)
surface.blit(inner_surface, (0,0))
surface.blit(self.image,(x-((size[0])/2),y-((size[1])/2)))
class circles(pygame.sprite.Sprite): # Initalise a new circle with set position and size (defined by cs)
def __init__(self,surface, inner_surface, x, y, cs, font):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("./assets/circle.png").convert_alpha()
size = (int(round(2.25*(109-(9*cs)))),int(round(2.25*(109-(9*cs)))))
self.image = pygame.transform.scale(self.image, size)
transparency(self, surface, inner_surface, size, x, y)
pygame.display.update()
def Place_circles(screen, curve, circle_space, font):
inner = inner_init([GetSystemMetrics(0), GetSystemMetrics(1)])
Circle_list = []
idx = [0,0]
for c in reversed(range(0,len(curve))):
for p in reversed(range(0,len(curve[c]))):
dist = math.sqrt(math.pow(curve[c][p][0] - curve[idx[0]][idx[1]][0],2)+math.pow(curve [c][p][1] - curve[idx[0]][idx[1]][1],2))
if dist > circle_space:
print(dist)
print(idx)
idx = [c,p]
Circle_list.append(circles.circles(screen, inner, curve[c][p][0], curve[c][p][1], 4, font))
【问题讨论】:
标签: python random pygame opacity polyline