Versión de código de Python de amor en movimiento de Li Xun

Recientemente, he visto muchos videos y artículos sobre el corazón de amor de Li Xun. Hoy compartiremos la versión en código Python del corazón de amor de Li Xun. ¿Quién es Li Xun? No sé muy bien, puedes Baidu por ti mismo, este es el resultado de mi Baidu, solo como referencia.

En pocas palabras, el corazón de amor de Li Xun es un efecto dinámico en forma de ♥. El código principal de Python se implementa de la siguiente manera: (búsqueme para obtener el código fuente completo)

def build(self, number): 
for _ in range(number): 
 t = random.uniform(0, 2 * pi) 
 x, y = heart(t) 
 self._points.add((x, y)) 
# 爱心内扩散
for _x, _y in list(self._points): 
 for _ in range(3): 
  x, y = scatter_inside(_x, _y, 0.05) 
  self._edge_diffusion_points.add((x, y)) 
# 爱心内再次扩散
point_list = list(self._points) 
for _ in range(4000): 
 x, y = random.choice(point_list) 
 x, y = scatter_inside(x, y, 0.17) 
 self._center_diffusion_points.add((x, y) ) 

@staticmethodstaticmethod 
def calc_position(x, y, ratio): 
fuerza = 1 / (((x - X) ** 2 + 
     (y - Y) ** 2) ** 0.520) 
dx = ratio * fuerza * (x - X) + random.randint(-1, 1)
dy = relación * fuerza * (y - Y) + random.randint(-1, 1) 
return x - dx, y - dy 

def calc(self, generar_fotograma): 
relación = 10 * curva(generar_fotograma / 10 * pi) 
halo_radius = int(4 + 6 * (1 + curva(generar_fotograma / 10 * pi))) 
número_halo = int( 
 3000 + 4000 * abs(curva(generar_fotograma / 10 * pi) ** 2)) 
todos_puntos = [] 
# 光环
heart_halo_point = set() 
for _ in range(halo_number): 
 t = random.uniform(0, 2 * pi) 
 x, y = corazón(t, Shrink_ratio=11.6) 
 x, y = Shrink(x, y, halo_radius) 
 if ( x, y) no en heart_halo_point: 
  heart_halo_point.add((x, y))  
  x += random.randint(-14, 14 )
  y += random.randint(-14, 14) 
  size = random.choice((1, 2, 2)) 
  all_points.append((x, y, size)) 
# 轮廓
for x, y in self._points: 
 x, y = self.calc_position(x, y, ratio) 
 size = random.randint(1, 3) 
 all_points.append((x, y, size)) 
# 内容
for x, y in self._edge_diffusion_points: 
 x, y = self.calc_position(x, y, ratio) 
 size = random. randint(1, 2) 
 all_points.append((x, y, size)) 
self.all_points[generate_frame] = all_points 
for x, y in self._center_diffusion_points: 
 x, y = self.calc_position(x, y, ratio) 
 tamaño = random.randint(1, 2) 
 all_points.append((x, y, size)) 
self.all_points[generate_frame] = all_points

El efecto es el siguiente (corazón en movimiento):

Supongo que te gusta

Origin blog.csdn.net/weixin_73136678/article/details/128150619
Recomendado
Clasificación