Mathematica应用——正方形拼图

 时间:2026-02-12 01:52:11

1、准备一个正方形图片,把它加载到Mathematica里面,命名为b。

Mathematica应用——正方形拼图

2、给图片随机的替换颜色,并根据不同的权重进行拼图:

ImageCollage[(#^2 -> Show[ColorReplace[b, RGBColor[

0.10588235294117647`, 0.6274509803921569, 0.8823529411764706] -> 

        RGBColor[Random[], Random[], Random[]]], 

      Epilog -> Inset[Style[#, 20*#, Bold], Center]]) & /@ Range[6]

 Background -> RGBColor[0.1, 0.9, 0.9], ImagePadding -> 0, 

 Method -> "ClosestPacking", ImageSize -> 500]

Mathematica应用——正方形拼图

3、把上面代码里面的Range[6]换成10。

不过,这可能不是最优排列方案。

Mathematica应用——正方形拼图

4、用边长分别是1, 4, 7, 8, 9, 10, 14, 15, 18的正方形来试试。

c = ImageCollage[(#^2 -> Show[ColorReplace[b, RGBColor[

0.10588235294117647`, 0.6274509803921569, 0.8823529411764706] -> 

         RGBColor[Random[], Random[], Random[]]], 

Epilog -> Inset[Style[#, If[4*# < 36, 60, 4*#], Bold], 

         Center]]) & /@ {1, 4, 7, 8, 9, 10, 14, 15, 18}, 

  Background -> RGBColor[0.1, 0.9, 0.9], ImagePadding -> 0, 

  Method -> "ClosestPacking", ImageSize -> 1000]

Mathematica应用——正方形拼图

5、但是,上面这个图形明显不是最优方案。因为,这是一个完美矩形的例子。

Mathematica应用——正方形拼图

6、前24个整数的平方和是70^2,但是,边长为1到24的正方形不可能拼成完美正方形,不知道能不能拼成完美矩形。

Mathematica应用——正方形拼图

  • 穿袜子睡觉好不好?怎么才能有助睡眠?
  • 上海居住证积分测试模拟/居住证积分怎么测试
  • 搜狗浏览器极速版如何设置小说模式
  • 如何不引爆坚果炸僵尸
  • 江湖悠悠如何领取江湖行任务奖励
  • 热门搜索
    户口迁移需要什么材料 月经期间能吃什么水果 cad是什么软件 雾里看花是什么生肖 王牌对王牌什么时候播 型号是什么意思 喜出望外是什么意思 男孩学什么乐器好 表征是什么意思 什么的身影