爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 4101|回复: 4

绘制雪容融

[复制链接]

新浪微博达人勋

发表于 2022-4-18 16:22:19 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
用MeteoInfoLab代码绘制雪容融,参考了网上的MatLab代码(https://zhuanlan.zhihu.com/p/466671100):

xuerongrong.png

  1. # 椭圆数据点生成函数
  2. def getEllipse(Mu, XR, YR, theta, pntNum):
  3.     # Mu     | 中心点
  4.     # XR,YR  | 旋转前X,Y半轴长度
  5.     # theta  | 旋转角度
  6.     # pntNum | 生成数据点个数
  7.     tList = linspace(0, 2*pi, pntNum)
  8.     X = cos(tList) * XR
  9.     Y = sin(tList) * YR
  10.     rotateMat = array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]])
  11.     XY = dot(rotateMat, vstack([X, Y])) + expand_dims(array(Mu), axis=1)
  12.     X = XY[0]
  13.     Y = XY[1]
  14.     return X, Y

  15. # 数据旋转角度
  16. def rotateData(X, Y, theta):
  17.     rotateMat = array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]])
  18.     XY = dot(rotateMat, vstack([X, Y]))
  19.     X = XY[0]
  20.     Y = XY[1]
  21.     return X, Y

  22. ############################################################
  23. antialias(True)
  24. ax = axes(outerposition=[0,0,1,1], aspect='equal', axis=False)
  25. xlim(-5, 5)
  26. ylim(-5, 5)

  27. # 绘制胳膊
  28. X, Y = getEllipse([-1,-2.5], .4, .6, -pi/5, 200)
  29. fill(X, Y, facecolor=[212,3,28], edgecolor=[182,50,2], linewidth=3)

  30. X, Y = getEllipse([1.7,-1.89], .4, .6, pi/3.6, 200)
  31. fill(X, Y, facecolor=[212,3,28], edgecolor=[182,50,2], linewidth=3)

  32. # 绘制腿
  33. rectangle([-.95,-4.2,1.3,1], curvature=.8, facecolor=[182,50,2],
  34.     edgecolor=[182,50,2], linewidth=3)
  35. rectangle([-1,-3.9,1.4,1], curvature=.8, facecolor=[246,168,68],
  36.     edgecolor=[246,168,68], linewidth=3)
  37. rectangle([-1,-3.8,1.4,1], curvature=.8, facecolor=[212,3,28],
  38.     edgecolor=[182,50,2], linewidth=3)

  39. rectangle([.5,-4.2,1.2,2], curvature=.8, facecolor=[182,50,2],
  40.     edgecolor=[182,50,2], linewidth=3)
  41. rectangle([.45,-3.9,1.3,2], curvature=.8, facecolor=[246,168,68],
  42.     edgecolor=[246,168,68], linewidth=3)
  43. rectangle([.45,-3.8,1.3,2], curvature=.8, facecolor=[212,3,28],
  44.     edgecolor=[182,50,2], linewidth=3)

  45. # 绘制身体
  46. rectangle([-.9,-3.5,2.6,3], curvature=.6, facecolor=[212,3,28],
  47.     edgecolor=[212,3,28], linewidth=3)

  48. # 绘制头
  49. X0, Y0 = getEllipse([-.15,.65], 2.9, 2.3, pi/11, 200)
  50. fill(X0, Y0, facecolor=[212,3,28], edgecolor=[153,12,40], linewidth=3)

  51. X, Y = getEllipse([-.15,.65], 2.7, 2.3, pi/11, 200)
  52. plot(X, Y, color=[236,136,74], linewidth=3)


  53. X, Y = getEllipse([-.15,.65], 1.7, 2.3, pi/11, 200)
  54. plot(X, Y, color=[236,136,74], linewidth=3)

  55. X = linspace(0, pi, 100)
  56. Y = sin(X)
  57. X = X * 1.4
  58. Y = Y * 0.2
  59. X, Y = rotateData(X, Y, -pi/11)
  60. plot(Y+.41, X-1.46, color=[236,136,74], linewidth=4)
  61. plot(X0, Y0, color=[212,3,28], linewidth=6)

  62. # 绘制脸上的云
  63. X, Y = getEllipse([-1.2,-.3], .5, .6, pi/3.4, 200)
  64. fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
  65. X, Y = getEllipse([-1.3,.4], .45, .55, -pi/3.4, 200)
  66. fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
  67. X, Y = getEllipse([-.65,1], .45, .7, -pi/4, 200)
  68. fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
  69. X, Y = getEllipse([0,1], .45, .7, -pi/4, 200)
  70. fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
  71. X, Y = getEllipse([1.8,.5], .4, .5, pi/5, 200)
  72. fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
  73. X, Y = getEllipse([1.63,.92], .4,.5, pi/12, 200)
  74. fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
  75. X, Y = getEllipse([.3,.25], 1.6, 1, pi/13, 200)
  76. fill(X, Y, facecolor=[250,250,250], edgecolor=[250,250,250], linewidth=3)
  77. X, Y = getEllipse([.95,1.42], .3, .3, pi/12, 200)
  78. fill(X, Y, facecolor=[212,3,28], edgecolor=[212,3,28], linewidth=3)

  79. # 绘制腮红
  80. X, Y = getEllipse([-1.1,-.5], .35, .35, pi/12, 200)
  81. fill(X, Y, facecolor=[212,3,28], edgecolor=None, alpha=.2)
  82. [X,Y]=getEllipse([-1.1,-.5],.32,.32,pi/12,200);
  83. fill(X+3, Y+.9, facecolor=[212,3,28], edgecolor=None, alpha=.2)

  84. # 绘制眼睛
  85. X, Y = getEllipse([-.76,.16], .15, .24, pi/20, 200)
  86. fill(X, Y, facecolor=[38,23,26], edgecolor=[38,23,26])
  87. X, Y = getEllipse([1.25,.47], .15, .24, pi/20, 200)
  88. fill(X, Y, facecolor=[38,23,26], edgecolor=[38,23,26])
  89. X, Y = getEllipse([-.81,.21], .05, .05, pi/20, 200)
  90. fill(X, Y, facecolor=[230,230,230], edgecolor=None)
  91. X, Y = getEllipse([1.2,.52], .05, .05, pi/20, 200)
  92. fill(X, Y, facecolor=[230,230,230], edgecolor=None)

  93. ## 绘制头饰
  94. X, Y = getEllipse([-1.85,2.2], .48, .15, pi/20, 200)
  95. fill(X, Y, facecolor=[236,136,74], edgecolor=[236,136,74], linewidth=3)
  96. X, Y = getEllipse([-.7,2.4], .47, .2, pi/15, 200)
  97. fill(X, Y, facecolor=[236,136,74], edgecolor=[236,136,74], linewidth=3)
  98. X, Y = getEllipse([.32,2.55], .47, .15, pi/15, 200)
  99. fill(X, Y, facecolor=[236,136,74], edgecolor=[236,136,74], linewidth=3)
  100. X, Y = getEllipse([1.2,2.6], .25, .14, pi/30, 200)
  101. fill(X, Y, facecolor=[236,136,74], edgecolor=[236,136,74], linewidth=3)
  102. #
  103. X, Y = getEllipse([-1.8,2.1], .08, .2, -pi/10, 200)
  104. fill(X, Y, facecolor=[212,3,28], edgecolor=[212,3,28], linewidth=3)
  105. X, Y = getEllipse([-.7,2.3], .08, .2, -pi/40, 200)
  106. fill(X, Y, facecolor=[212,3,28], edgecolor=[212,3,28], linewidth=3)
  107. X, Y = getEllipse([.4,2.5], .08, .2, -pi/40, 200)
  108. fill(X, Y, facecolor=[212,3,28], edgecolor=[212,3,28], linewidth=3)
  109. X, Y = getEllipse([1.25,2.5], .04, .12, pi/10, 200)
  110. fill(X, Y, facecolor=[212,3,28], edgecolor=[212,3,28], linewidth=3)

  111. # 绘制金色云纹
  112. X, Y = getEllipse([-.3,3.6], .3, .35, pi/10-pi/5, 200)
  113. fill(X, Y, facecolor=[250,250,250], edgecolor=[246,168,68], linewidth=4)
  114. X, Y = getEllipse([-1,3.4], .3, .35, pi/10+pi/5, 200)
  115. fill(X, Y, facecolor=[250,250,250], edgecolor=[246,168,68], linewidth=4)
  116. X, Y = getEllipse([-.7,3.6], .35, .4, pi/10, 200)
  117. fill(X, Y, facecolor=[250,250,250], edgecolor=[246,168,68], linewidth=4)
  118. X = linspace(0+pi/10, pi-pi/10, 200)
  119. Y = sin(X)
  120. X = X * .4; Y = Y * .3
  121. X, Y = rotateData(X, Y, pi/10)
  122. plot(X-1.3, Y+3.2, color=[250,250,250], linewidth=7)

  123. # 绘制小帽子
  124. X, Y = getEllipse([0,0], 1, .9, pi/12, 200); Y = Y - .3
  125. Y[Y<=0] = Y[Y<=0] * .2
  126. X, Y = rotateData(X, Y, pi/14)
  127. fill(X-.4, Y+2.8, facecolor=[212,3,28], edgecolor=[182,50,2], linewidth=3)

  128. # 绘制头上的雪
  129. X1 = linspace(-2*pi/3, (5+2/3.)*pi, 200)
  130. Y1 = sin(X1)
  131. X2 = linspace(0, pi, 200)
  132. Y2 = sin(X2)

  133. X1 = X1 * .22; Y1 = Y1 * .1
  134. X1, Y1 = rotateData(X1, Y1, pi/20)
  135. X1 = X1 - 1.9; Y1 = Y1 + 2.2
  136. X2 = X2 * 1.3; Y2 = Y2 * .58
  137. X2, Y2 = rotateData(X2, Y2, pi/16)
  138. X2 = X2 - 2.4; Y2 = Y2 + 2.1
  139. fill(concatenate([X1, X2[::-1]]), concatenate([Y1, Y2[::-1]]),
  140.     facecolor=[250,250,250], edgecolor=[240,240,240], linewidth=5)

  141. # 绘制肚子
  142. X, Y = getEllipse([.6,-2.6], .8, .75, pi/12, 200)
  143. fill(X, Y, facecolor=[250,250,250], edgecolor=[230,230,230], linewidth=3)

  144. # 绘制围巾
  145. X = array([-.35,-.39])
  146. Y = array([-1.8,-2.5])
  147. plot(X, Y-.05, color=[157,107,43], linewidth=18)
  148. plot(X, Y, color=[246,168,68], linewidth=16)


  149. X = linspace(0, pi, 100); Y = sin(X)
  150. X = X * .9; Y = -Y * .2
  151. X, Y = rotateData(X, Y, pi/14)
  152. plot(X*1.05-1.05, Y-1.8, color=[157,107,43], linewidth=18)
  153. plot(X-.99, Y-1.8, color=[246,168,68], linewidth=16)

  154. # 文本
  155. text(.6, -2.7, 'BEIJING 2022', xalign='center', yalign='center', color=[.2,.2,.2],
  156.     fontsize=9, fontname='Comic Sans MS', rotation=10, bold=True)

  157. # 标志
  158. X = linspace(0, 5*pi/6, 100); Y = -sin(X)
  159. X = X * .13; Y = Y * .13
  160. X, Y = rotateData(X, Y, -2*pi/3)
  161. plot(X+.6, Y-2.9, color=[212,62,80], linewidth=3)
  162. X, Y = rotateData(X, Y, pi/4)
  163. plot(X+.65, Y-2.95, color=[51,119,180], linewidth=3)
  164. X, Y = rotateData(X, Y, pi/4)
  165. plot(X+.7, Y-3, color=[174,222,93], linewidth=3)

  166. dx = 0.6
  167. dy = -0.4
  168. fill(array([.1,-.12,-.08])+dx, array([0,0-0.05,-0.15])-1.5+dy, facecolor=[98,118,163], edgecolor=[98,118,163])
  169. fill(array([-.08,-.35,.1])+dx, array([-0.1,-.2,-.1])-1.6+dy, facecolor=[98,118,163], edgecolor=[98,118,163])
  170. 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])
  171. plot(array([-.35,-.3,-.25,-.2,-.15,-.1,-.05,.1])+.02+dx,
  172.      array([0,.02,.04,.06,.04,.02,0,.02])-1.82+dy, color=[120,196,219], lLinewidth=1.8)
  173. plot(array([-.33,.05])+.02+dx, array([0,-.08])-1.82+dy, color=[190,215,84], linewidth=1.8)
  174. plot(array([.05,-.2])+.02+dx, array([-.08,-.15])-1.82+dy, color=[32,162,218], linewidth=1.8)
  175. plot(array([-.2,.05])+.02+dx, array([-.15,-.2])-1.82+dy, color=[99,118,151], linewidth=1.8)


评分

参与人数 1金钱 +20 收起 理由
lightmoon + 20 很给力!

查看全部评分

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2022-4-18 23:15:55 | 显示全部楼层
好棒
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2022-4-18 23:59:31 来自手机 | 显示全部楼层
很棒,科研娱乐两手抓

                               
登录/注册后可看大图
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2022-4-19 00:14:51 | 显示全部楼层
太好看了,点个赞
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2022-4-22 10:36:51 | 显示全部楼层
好好看!!好厉害!
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表