用Mathematica绘制随机的雪花图案

本文用Mathematica绘制形态各异的雪花图案。

2e223d85e036e29156b59955b2723d03baea5bf6.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80

工具/原料

  • 电脑
  • Mathematica

方法/步骤

  1. 1

    给出平面上五个随机的点:

    a = RandomReal[{-1, 1}, {5, 2}]

    这五个点可以连当作一个五边形。

    22c4fe36e29147e821bd93c7b603bbea3f8658f6.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  2. 2

    再加上一个点,获得六个点,也就是一个六边形。

    b = Join[{{0, 0.1}}, a]

    e177fc9147e833e02a2f97b630ea3e86314859f6.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  3. 3

    从六边形的极点{0,0.1}出发,累加六边形的极点坐标:

    c = Accumulate[b]

    e3d059e833e03972295e115fb5863048604356f6.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  4. 4

    扭转c对应的六边形:

    d = c.(RotationMatrix[{c[[-1]], {0, 1}}])\[Transpose]

    54a89daee8d7592ae6b14acd9f31dfb6336c67f7.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  5. 5

    翻转d:

    e = Reverse[d.{{-1, 0}, {0, 1}}]

    这近似于关于y轴的对称变换。

    82eff6d7592ae3efe626be8454b6326c566664f7.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  6. 6

    去失e的第一个极点,获得五边形:

    f = Rest[e]

    e996472ae3efe078136f7503b96c576698cf65f7.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  7. 7

    归并d和f的极点,获得一个11边形:

    g = Join[d, f]

    586bfdefe0781431d7e898d9dc6699cf035362f7.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  8. 8

    扭转11边形g,扭转角度别离是0*π/3,1*π/3,2*π/3,3*π/3,4*π/3,5*π/3;

    把这些极点归并起来,获得一个庞大的66边形;

    这就是我们获得的雪花图案。

    h = (g.RotationMatrix[#*60 \[Degree]] & /@ Range[6]) // Flatten[#, 1] &;

    e2aefe781431dfb63b32fdd312cf02532e6363f7.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  9. 9

    这样,可以整合一个雪花函数。

    e1390a31dfb6326c5d38337a89532f63228560f7.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  10. 10

    下面是10个随机雪花的动态图。

    Graphics[{White, 雪花}, Background -> Black]

    1570c1b6326c57669291a8e6a4632385e13661f7.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  11. 11

    下面是100个雪花。

    def72c6c576699cf0e0d85d6a885e036e3915ef7.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80END

注重事项

  • 本文参考的是stereohomology的CSDN博客。
  • 发表于 2022-08-22 20:02
  • 阅读 ( 173 )
  • 分类:其他类型

相关问题

0 条评论

请先 登录 后评论