import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0,2*np.pi,1000)
x =16*np.sin(t)**3
y =13*np.cos(t)-5*np.cos(2*t)-2*np.cos(3*t)- np.cos(4*t)
plt.plot(x, y, color='red')
plt.axis('equal')
plt.show()
动态爱心效果
结合pygame实现跳动爱心动画
颜色渐变和大小变化的实现方法
代码示例:
import pygame
import math
pygame.init()
screen = pygame.display.set_mode((800,600))
clock = pygame.time.Clock()
running =Truewhile running:for event in pygame.event.get():if event.type== pygame.QUIT:running =Falsescreen.fill((0,0,0))time = pygame.time.get_ticks()/1000size =10+5* math.sin(time *3)points =[]for i inrange(360):angle = math.radians(i)r = size *(1- math.sin(angle))x =400+ r * math.cos(angle)y =300+ r * math.sin(angle)points.append((x, y))pygame.draw.polygon(screen,(255,0,0), points)pygame.display.flip()clock.tick(60)
pygame.quit()
3D爱心渲染
使用matplotlib或PyOpenGL创建3D爱心模型
参数方程在3D空间的应用
代码示例:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
u = np.linspace(0,2*np.pi,100)
v = np.linspace(0, np.pi,100)
x = np.outer(16*np.sin(u)**3, np.ones(np.size(v)))
y = np.outer(13*np.cos(u)-5*np.cos(2*u)-2*np.cos(3*u)-np.cos(4*u), np.sin(v))
z = np.outer(13*np.cos(u)-5*np.cos(2*u)-2*np.cos(3*u)-np.cos(4*u), np.cos(v))
ax.plot_surface(x, y, z, color='red')
plt.show()
C基础问题
掌握形参默认带缺省值的函数
函数调用时
#include <iostream>int sum(int a, int b 20) {return a b;
}int main() {int a 10, b 20;int ret sum(a, b);cout << "ret: " << ret << endl;ret sum(a);/*a 使用默认值压栈: …
Adobe PDF Library 是 Adobe 公司提供的一个软件开发工具包(SDK),它本质上是 Adobe Acrobat 的"无界面"版本,但功能更为强大。作为 PDF 处理领域的专业解决方案,它为开发者提供了创建、操作和管理 PDF 文档的全面能力。 #mermaid-s…