跳到正文
网页珍奇柜Web Curio

CSS 网格涂鸦

css-doodle,Yuan Chuan,2017 年

正在布展…

原作直展:这是 Yuan Chuan 的原始作品,按 MIT 许可证收录(版本 c4dc242)。收录 npm 0.67.0 原版库,配一张本柜写的演示页:四个 <css-doodle> 元素分别用几行规则生成迷宫、Truchet 拼贴、旋转方框螺旋和编织纹样。点击任一图案会重新随机。 许可证全文 · 收录说明

它是怎么做的

  1. 第 1 步Web Component 在 Shadow DOM 中生成 N×M 个格子。
  2. 第 2 步自定义语法在每个格子上展开,@i、@x、@y 提供索引。
  3. 第 3 步@rand、@pick 等函数在编译期为每格产出不同值。
  4. 第 4 步点击可重新随机,生成新的变体。

复刻配方

一段技术配方,可以直接交给 AI 编程助手,也可以自己照着写。想指定技术栈、位置和性能预算,就把它加入实现方案。

Create a custom element that reads its text content as a template, parses a grid size, and renders that many child divs in a shadow root using CSS grid. Before injecting styles, expand placeholder functions per cell: index, row, column, a seeded random range, and pick-one-of-list. Emit one :nth-child rule per cell (or inline custom properties) so each cell gets its own values. Re-seed and re-render on click for instant variations.

档案

能不能拿来用

原作以 MIT 许可开源:可以阅读源码学习,按许可证条款使用;在自己的项目里引用时保留原作者署名。

性能开销

视觉强度

实现难度

尺度为策展判断(1 到 5),用于比较和推荐。

核实记录:Repo via gh api: MIT, created 2017-02-14, homepage css-doodle.com. The site itself returned a Cloudflare challenge (403) to curl/WebFetch, so the live demo is unverified beyond the repo.