WIDTH = 0 HEIGHT = 0 ORI = (0, 0) COLOR = {'0': '#070920', 'navyblue': '#000080'} FIRE = [] def setParam(): global WIDTH global HEIGHT global ORI global FIRE WIDTH = t.window_width() HEIGHT = t.window_height() ORI = (0, -HEIGHT / 2) # gold FIRE.append(['white', '#FFD700', '#DAA520', '#BDB76B', ]) # red FIRE.append(['white', '#F08080', '#A0522D', '#DC143C', ]) # green FIRE.append(['white', '#7FFF00', '#32CD32', '#006400', ]) # cyan FIRE.append(['white', '#40E0D0', '#00FFFF', '#008080', ]) # pink FIRE.append(['white', '#FF69B4', '#FF1493', '#8B008B', ]) # buff FIRE.append(['white', '#FFE4C4', '#FFDAB9', '#F0FFF0', ]) # bluish FIRE.append(['white', '#ADD8E6', '#AFEEEE', '#00BFFF', ]) def dist(a, b): # 距离 return ((a - b) * (a - b)).sum() def shoot(): t.tracer(4) # 在循环中,图形将一次画出4次循环的图 t.pu() target = np.array((np.random.randint(-WIDTH // 6, WIDTH // 6), HEIGHT // 6)) # 都在同一高度 angle = atan((target - ORI)[1] / (target - ORI)[0]) if angle < 0: angle += math.pi # 纠正负方向 unit = np.array([cos(angle), sin(angle)]) # 方向向量 print('angle: ', angle) print('target: ', target) # 镜头的顺序坐标 seq = np.array([ORI, ORI - 55 * unit, ORI - 105 * unit, ORI - 155 * unit]) t.speed(0) # 瞬动 while dist(seq[0], target) > 120: # 如果没有到达爆炸中心 seq = seq + 30 * unit t.goto(seq[1]) t.pd() t.width(3) t.pencolor('white') t.goto(seq[0]) t.pu() t.goto(seq[2]) t.pd() t.width(3) t.pencolor('yellow') t.goto(seq[1]) t.pu() # 清除发射上去的光束尾迹 t.goto(seq[3]) t.pd() t.width(10) t.pencolor(COLOR['0']) t.goto(seq[2]) t.pu() time.sleep(0.05) # 发射上去的光束最后清除 t.pd() t.width(10) t.goto(seq[0]) t.pu() time.sleep(0.1) return target # 就在爆炸中心 def explode(center): number = np.random.randint(50, 100) # 光束数 colormode = np.random.randint(0, 5) unit = np.array([]) # 方向向量 spd = [] # 每个光束的速度 seq = [] # 每个波束的顺序坐标 if colormode : coloridx = [np.random.randint(0, len(FIRE))] elif colormode == 2: coloridx = [np.random.randint(0, len(FIRE)), np.random.randint(0, len(FIRE))] elif colormode == 3: coloridx = [np.random.randint(0, len(FIRE)), np.random.randint(0, len(FIRE)), np.random.randint(0, len(FIRE))] elif colormode == 4: coloridx = []
Original: https://www.cnblogs.com/hahaa/p/16967548.html
Author: 轻松学Python
Title: 圣诞节快到了,教大家用Python画一个简单的圣诞树和烟花,送给那个她
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/808225/
转载文章受原作者版权保护。转载请注明原作者出处!