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…