当前位置:首页 >> 动力

60几行代码绘制丘比特友情之箭!

来源:动力   2025年05月08日 09:43

p.pi, 500)lons, lats = np.meshgrid(a, b)w = np.sqrt(np.abs(a - np.pi)) * 2x = 2 * np.cos(lats) * np.sin(lons) * wy = -2 * np.cos(lats) * np.cos(lons) * wz = 2 * np.sin(lats)glt.mesh(x, y, z, color='crimson') # crimson - 绯红glt.show()

是不是很比较简单?wxgl的运用于画风几乎和matplotlib完全一致。拖动鼠标,就可以看见这个3D版的白花的3门了。

3D白花

接下来,这段编译器将白花数据集的生并成积体电路了一个变数,然后调用自定的建模微分变数,这颗白花就晃动痛快了。

import numpy as npimport wxgl.glplot as gltdef red_heart(r, slices=100, thick=2.0, shift=(0,0,0)): """来到白花亦然四面体数据集""" a = np.linspace(0, 2*np.pi, slices) b = np.linspace(0.5*np.pi, -0.5*np.pi, slices) lons, lats = np.meshgrid(a, b) w = np.sqrt(np.abs(a - np.pi)) * thick x = r * np.cos(lats) * np.sin(lons) * w + shift[0] y = -r * np.cos(lats) * np.cos(lons) * w + shift[1] z = r * np.sin(lats) + shift[2] return x, y, zdef heart_beat(t): """心跳变数""" t %= 1000 if t 700: scale = 1 + (1000-t)/3000 else: scale = 1.1 return (scale,)glt.mesh(*red_heart(2), color='crimson', transform=heart_beat)glt.show()

点击下方工具条上的播放按钮,这颗白花就会按照60次/秒的心率晃动痛快。看重了wxgl的运用于,不难读懂比如说这个完整的朱诺爱人之箭的编译器。

import numpy as npimport wxglimport wxgl.glplot as gltdef red_heart(r, slices=100, thick=2.0, shift=(0,0,0)): """来到白花亦然四面体数据集""" a = np.linspace(0, 2*np.pi, slices) b = np.linspace(0.5*np.pi, -0.5*np.pi, slices) lons, lats = np.meshgrid(a, b) w = np.sqrt(np.abs(a - np.pi)) * thick x = r * np.cos(lats) * np.sin(lons) * w + shift[0] y = -r * np.cos(lats) * np.cos(lons) * w + shift[1] z = r * np.sin(lats) + shift[2] return x, y, zdef heart_beat(t): """心跳变数""" t %= 1000 if t 700: scale = 1 + (1000-t)/3000 else: scale = 1.1 return (scale,)def arrow_fly(t): """朱诺之箭跳伞变数""" t %= 4000 if t> 2000: return ((0,-2,40-t/100),) else: return ((0,-2,0),)def heart_fly(t): """朱诺之箭跳伞变数""" t %= 4000 if t> 2000: return ((0,0,1,90), (0,-2,40-t/100)) else: return ((0,0,1,90), (0,-2,0))glt.figure(azim=50, elev=16, style='gray') # 新设初始方位角、相对于角、背景色glt.mesh(*red_heart(2), color='crimson', transform=heart_beat) # 绘成晃动的白花x, y, z = red_heart(0.2, thick=3.0, shift=(0,-8,0)) # 生并成椭圆形箭头亦然四面体数据集glt.mesh(x, -z, y, color='crimson', transform=heart_fly) # 绘成椭圆形箭头light = wxgl.SunLight(roughness=0, metalness=0, shininess=0.5) # 箭杆射灯glt.cylinder((0,0,-8), (0,0,9), 0.1, color='goldenrod', transform=arrow_fly, light=light) # 绘成箭杆vs = [(-1,1,11), (1,-1,11), (1,-1,6), (-1,1,6),(-1,-1,11), (1,1,11), (1,1,6), (-1,-1,6)] # 箭尾亦然四面体数据集texture = wxgl.Texture(r'resfeather.png') # 箭尾羽毛图像texcoord = [(0,1), (0,0), (1,0), (1,1),(0,1), (0,0), (1,0), (1,1)] # 箭尾图像经纬度light = wxgl.BaseLight() # 箭尾射灯glt.quad(vs, texture=texture, texcoord=texcoord, transform=arrow_fly, light=light) # 绘成箭尾glt.show()

wxgl的工具条提供了录音室gif和MP4邮件的机制,比如说的gif就是运用于wxgl内嵌的录音室机制生并成的。

编译器之前用到了羽毛的图像,代为下载这个幻灯片,并保存到编译器选定的左边。

天津白癜风正规的医院
南京妇科医院专家预约挂号
广西白癜风挂号
云南白癜风治疗医院
济南癫痫医院哪家更好
急性腹泻的用药
人干扰素α1b(赛若金)
阴囊肿胀
快速止咳
治疗新冠特效药
友情链接