登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
用MeteoInfoLab代码绘制雪容融,参考了网上的MatLab代码(https://zhuanlan.zhihu.com/p/466671100):
- # 椭圆数据点生成函数
- def getEllipse(Mu, XR, YR, theta, pntNum):
- # Mu | 中心点
- # XR,YR | 旋转前X,Y半轴长度
- # theta | 旋转角度
- # pntNum | 生成数据点个数
- tList = linspace(0, 2*pi, pntNum)
- X = cos(tList) * XR
- Y = sin(tList) * YR
- rotateMat = array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]])
- XY = dot(rotateMat, vstack([X, Y])) + expand_dims(array(Mu), axis=1)
- X = XY[0]
- Y = XY[1]
- return X, Y
- # 数据旋转角度
- def rotateData(X, Y, theta):
- rotateMat = array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]])
- XY = dot(rotateMat, vstack([X, Y]))
- X = XY[0]
- Y = XY[1]
- return X, Y
- ############################################################
- antialias(True)
- ax = axes(outerposition=[0,0,1,1], aspect='equal', axis=False)
- xlim(-5, 5)
- ylim(-5, 5)
- # 绘制胳膊
- X, Y = getEllipse([-1,-2.5], .4, .6, -pi/5, 200)
- fill(X, Y, facecolor=[212,3,28], edgecolor=[182,50,2], linewidth=3)
- X, Y = getEllipse([1.7,-1.89], .4, .6, pi/3.6, 200)
- fill(X, Y, facecolor=[212,3,28], edgecolor=[182,50,2], linewidth=3)
- # 绘制腿
- rectangle([-.95,-4.2,1.3,1], curvature=.8, facecolor=[182,50,2],
- edgecolor=[182,50,2], linewidth=3)
- rectangle([-1,-3.9,1.4,1], curvature=.8, facecolor=[246,168,68],
- edgecolor=[246,168,68], linewidth=3)
- rectangle([-1,-3.8,1.4,1], curvature=.8, facecolor=[212,3,28],
- edgecolor=[182,50,2], linewidth=3)
- rectangle([.5,-4.2,1.2,2], curvature=.8, facecolor=[182,50,2],
- edgecolor=[182,50,2], linewidth=3)
- rectangle([.45,-3.9,1.3,2], curvature=.8, facecolor=[246,168,68],
- edgecolor=[246,168,68], linewidth=3)
- rectangle([.45,-3.8,1.3,2], curvature=.8, facecolor=[212,3,28],
- edgecolor=[182,50,2], linewidth=3)
- # 绘制身体
- rectangle([-.9,-3.5,2.6,3], curvature=.6, facecolor=[212,3,28],
- edgecolor=[212,3,28], linewidth=3)
- # 绘制头
- X0, Y0 = getEllipse([-.15,.65], 2.9, 2.3, pi/11, 200)
- fill(X0, Y0, facecolor=[212,3,28], edgecolor=[153,12,40], linewidth=3)
- X, Y = getEllipse([-.15,.65], 2.7, 2.3, pi/11, 200)
- plot(X, Y, color=[236,136,74], linewidth=3)
- X, Y = getEllipse([-.15,.65], 1.7, 2.3, pi/11, 200)
- plot(X, Y, color=[236,136,74], linewidth=3)
- X = linspace(0, pi, 100)
- Y = sin(X)
- X = X * 1.4
- Y = Y * 0.2
- X, Y = rotateData(X, Y, -pi/11)
- plot(Y+.41, X-1.46, color=[236,136,74], linewidth=4)
- plot(X0, Y0, color=[212,3,28], linewidth=6)
- # 绘制脸上的云
- X, Y = getEllipse([-1.2,-.3], .5, .6, pi/3.4, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
- X, Y = getEllipse([-1.3,.4], .45, .55, -pi/3.4, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
- X, Y = getEllipse([-.65,1], .45, .7, -pi/4, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
- X, Y = getEllipse([0,1], .45, .7, -pi/4, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
- X, Y = getEllipse([1.8,.5], .4, .5, pi/5, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
- X, Y = getEllipse([1.63,.92], .4,.5, pi/12, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
- X, Y = getEllipse([.3,.25], 1.6, 1, pi/13, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
- X, Y = getEllipse([.95,1.42], .3, .3, pi/12, 200)
- fill(X, Y, facecolor=[212,3,28], edgecolor=[212,3,28], linewidth=3)
- # 绘制腮红
- X, Y = getEllipse([-1.1,-.5], .35, .35, pi/12, 200)
- fill(X, Y, facecolor=[212,3,28], edgecolor=None, alpha=.2)
- [X,Y]=getEllipse([-1.1,-.5],.32,.32,pi/12,200);
- fill(X+3, Y+.9, facecolor=[212,3,28], edgecolor=None, alpha=.2)
- # 绘制眼睛
- X, Y = getEllipse([-.76,.16], .15, .24, pi/20, 200)
- fill(X, Y, facecolor=[38,23,26], edgecolor=[38,23,26])
- X, Y = getEllipse([1.25,.47], .15, .24, pi/20, 200)
- fill(X, Y, facecolor=[38,23,26], edgecolor=[38,23,26])
- X, Y = getEllipse([-.81,.21], .05, .05, pi/20, 200)
- fill(X, Y, facecolor=[230,230,230], edgecolor=None)
- X, Y = getEllipse([1.2,.52], .05, .05, pi/20, 200)
- fill(X, Y, facecolor=[230,230,230], edgecolor=None)
- ## 绘制头饰
- X, Y = getEllipse([-1.85,2.2], .48, .15, pi/20, 200)
- fill(X, Y, facecolor=[236,136,74], edgecolor=[236,136,74], linewidth=3)
- X, Y = getEllipse([-.7,2.4], .47, .2, pi/15, 200)
- fill(X, Y, facecolor=[236,136,74], edgecolor=[236,136,74], linewidth=3)
- X, Y = getEllipse([.32,2.55], .47, .15, pi/15, 200)
- fill(X, Y, facecolor=[236,136,74], edgecolor=[236,136,74], linewidth=3)
- X, Y = getEllipse([1.2,2.6], .25, .14, pi/30, 200)
- fill(X, Y, facecolor=[236,136,74], edgecolor=[236,136,74], linewidth=3)
- #
- X, Y = getEllipse([-1.8,2.1], .08, .2, -pi/10, 200)
- fill(X, Y, facecolor=[212,3,28], edgecolor=[212,3,28], linewidth=3)
- X, Y = getEllipse([-.7,2.3], .08, .2, -pi/40, 200)
- fill(X, Y, facecolor=[212,3,28], edgecolor=[212,3,28], linewidth=3)
- X, Y = getEllipse([.4,2.5], .08, .2, -pi/40, 200)
- fill(X, Y, facecolor=[212,3,28], edgecolor=[212,3,28], linewidth=3)
- X, Y = getEllipse([1.25,2.5], .04, .12, pi/10, 200)
- fill(X, Y, facecolor=[212,3,28], edgecolor=[212,3,28], linewidth=3)
- # 绘制金色云纹
- X, Y = getEllipse([-.3,3.6], .3, .35, pi/10-pi/5, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[246,168,68], linewidth=4)
- X, Y = getEllipse([-1,3.4], .3, .35, pi/10+pi/5, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[246,168,68], linewidth=4)
- X, Y = getEllipse([-.7,3.6], .35, .4, pi/10, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[246,168,68], linewidth=4)
- X = linspace(0+pi/10, pi-pi/10, 200)
- Y = sin(X)
- X = X * .4; Y = Y * .3
- X, Y = rotateData(X, Y, pi/10)
- plot(X-1.3, Y+3.2, color=[250,250,250], linewidth=7)
- # 绘制小帽子
- X, Y = getEllipse([0,0], 1, .9, pi/12, 200); Y = Y - .3
- Y[Y<=0] = Y[Y<=0] * .2
- X, Y = rotateData(X, Y, pi/14)
- fill(X-.4, Y+2.8, facecolor=[212,3,28], edgecolor=[182,50,2], linewidth=3)
- # 绘制头上的雪
- X1 = linspace(-2*pi/3, (5+2/3.)*pi, 200)
- Y1 = sin(X1)
- X2 = linspace(0, pi, 200)
- Y2 = sin(X2)
- X1 = X1 * .22; Y1 = Y1 * .1
- X1, Y1 = rotateData(X1, Y1, pi/20)
- X1 = X1 - 1.9; Y1 = Y1 + 2.2
- X2 = X2 * 1.3; Y2 = Y2 * .58
- X2, Y2 = rotateData(X2, Y2, pi/16)
- X2 = X2 - 2.4; Y2 = Y2 + 2.1
- fill(concatenate([X1, X2[::-1]]), concatenate([Y1, Y2[::-1]]),
- facecolor=[250,250,250], edgecolor=[240,240,240], linewidth=5)
- # 绘制肚子
- X, Y = getEllipse([.6,-2.6], .8, .75, pi/12, 200)
- fill(X, Y, facecolor=[250,250,250], edgecolor=[230,230,230], linewidth=3)
- # 绘制围巾
- X = array([-.35,-.39])
- Y = array([-1.8,-2.5])
- plot(X, Y-.05, color=[157,107,43], linewidth=18)
- plot(X, Y, color=[246,168,68], linewidth=16)
- X = linspace(0, pi, 100); Y = sin(X)
- X = X * .9; Y = -Y * .2
- X, Y = rotateData(X, Y, pi/14)
- plot(X*1.05-1.05, Y-1.8, color=[157,107,43], linewidth=18)
- plot(X-.99, Y-1.8, color=[246,168,68], linewidth=16)
- # 文本
- text(.6, -2.7, 'BEIJING 2022', xalign='center', yalign='center', color=[.2,.2,.2],
- fontsize=9, fontname='Comic Sans MS', rotation=10, bold=True)
- # 标志
- X = linspace(0, 5*pi/6, 100); Y = -sin(X)
- X = X * .13; Y = Y * .13
- X, Y = rotateData(X, Y, -2*pi/3)
- plot(X+.6, Y-2.9, color=[212,62,80], linewidth=3)
- X, Y = rotateData(X, Y, pi/4)
- plot(X+.65, Y-2.95, color=[51,119,180], linewidth=3)
- X, Y = rotateData(X, Y, pi/4)
- plot(X+.7, Y-3, color=[174,222,93], linewidth=3)
- dx = 0.6
- dy = -0.4
- fill(array([.1,-.12,-.08])+dx, array([0,0-0.05,-0.15])-1.5+dy, facecolor=[98,118,163], edgecolor=[98,118,163])
- fill(array([-.08,-.35,.1])+dx, array([-0.1,-.2,-.1])-1.6+dy, facecolor=[98,118,163], edgecolor=[98,118,163])
- fill(array([-.08,-.08,.1,.1])+dx, array([-0.1,-0.15,-.2,-.15])-1.5+dy, facecolor=[192,15,45], edgecolor=[192,15,45])
- plot(array([-.35,-.3,-.25,-.2,-.15,-.1,-.05,.1])+.02+dx,
- array([0,.02,.04,.06,.04,.02,0,.02])-1.82+dy, color=[120,196,219], lLinewidth=1.8)
- plot(array([-.33,.05])+.02+dx, array([0,-.08])-1.82+dy, color=[190,215,84], linewidth=1.8)
- plot(array([.05,-.2])+.02+dx, array([-.08,-.15])-1.82+dy, color=[32,162,218], linewidth=1.8)
- plot(array([-.2,.05])+.02+dx, array([-.15,-.2])-1.82+dy, color=[99,118,151], linewidth=1.8)
|