目录

MoonBit Generative Pattern Library (generative_patterns)

A procedural/generative pattern library written in MoonBit for designing posters, packaging, and cultural products.

Features

  • 2D Affine Transformation Matrix: Translation, rotation, scaling, and reflection across arbitrary lines.
  • Parametric SVG Path Builder: Generates shapes like rectangles, circles, stars, and floral shapes.
  • Grid Layout Generators: Supports rectangular, hexagonal, triangular, and radial grids.
  • Point and Wallpaper Symmetry Groups: Applies cyclic (CnC_n), dihedral (DnD_n), and plane tiling symmetries (p1p1, p2p2, pmpm, pmmpmm, p4p4, p4mp4m, p6p6, p6mp6m).
  • Noise Sampling and Domain Warping: Interface for procedural noise sampling and flow fields.
  • Parametric SVG and JSON Export: Easily renders complete designs to standard SVG vector files and JSON configurations.

Architecture

The project consists of:

  • lib: Core modules for geometry, symmetry, grid, path, noise, and SVG generation.
  • cmd/main: A showcase command-line tool executing the pattern generator and saving outputs.

Usage Example

The following is a verified test case demonstrating basic affine matrix transformations and path construction:

test {
  // Create a 2D transformation matrix: translate, then scale
  let t = @generative_patterns.Matrix2D::translate(10.0, 20.0)
  let s = @generative_patterns.Matrix2D::scale(2.0, 2.0)
  let m = t.multiply(s)
  
  // Transform a point
  let (x, y) = m.transform_point(5.0, 5.0)
  assert_eq(x, 20.0)
  assert_eq(y, 30.0)
  
  // Create a rect path and transform it
  let path = @generative_patterns.Path::rect(10.0, 10.0)
  let transformed = path.transform(m)
  let d = transformed.to_svg_d()
  assert_eq(d, "M 10 20 L 30 20 L 30 40 L 10 40 Z")
}

Running & Testing

To compile, build, and test the project:

# Type check all packages
moon check

# Run unit and doc tests
moon test

# Format code warning-free
moon fmt

# Compile and run the CLI showcase
moon run cmd/main

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

关于

面向海报、包装、文创设计的 MoonBit 程序化纹样生成库。支持矩形、六角形、三角形、极坐标网格系统;内置点对称群(Cn, Dn)与墙纸群(p1, p2, pm, pmm, p4, p4m, p6, p6m)变换平铺算法;提供噪声采样适配与坐标扭曲接口;支持参数化导出标准的 SVG 矢量路径与 JSON 结构数据,零外部依赖,编译无 Warning,测试通过率 100%。

69.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号