颗粒质感
Grain Texture
细小而不规则的斑点打破平滑表面,像胶片或未涂布的纸。
适用场景
让平整的大色块带一点可触摸的印刷质感。 让颗粒足够细,看起来像纸面或胶片本身的纹理,并把它放在文字和控件图层下面。
应用示例
活版印刷工作室在纸样背后的奶油色区域铺一层细小、不规则的颗粒。底纹像未涂布的信纸,纸样报价和下单按钮依然清楚。
AI 提示词
给【目标背景】加颗粒质感。在底色上方放一层低透明度的平铺噪点。保持文字图层干净,避免个别高反差颗粒,并在缩放后检查可读性。
示例代码
保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。
查看 HTML
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>颗粒质感</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.visual-specimen {
width: min(100%, 290px);
height: 124px;
display: grid;
place-items: center;
position: relative;
isolation: isolate;
}
.grain-comparison { overflow: hidden; width: min(100%, 220px); border-radius: 11px; }
.grain-comparison canvas { width: 100%; display: block; height: auto; }
</style>
</head>
<body>
<main class="demo">
<div class="visual-specimen" aria-hidden="true"><div class="grain-comparison"><canvas width="220" height="96"></canvas></div></div>
</main>
<script>
const canvas = document.querySelector('canvas');
const context = canvas.getContext('2d');
const { width, height } = canvas;
const gradient = context.createLinearGradient(0, 0, width, height);
gradient.addColorStop(0, '#ffe398');
gradient.addColorStop(1, '#ba5976');
context.fillStyle = gradient;
context.fillRect(0, 0, width, height);
const half = width / 2;
const texture = context.getImageData(half, 0, half, height);
for (let index = 0; index < texture.data.length; index += 4) {
const grain = (Math.random() - .5) * 54;
for (let channel = 0; channel < 3; channel++) {
texture.data[index + channel] += grain;
}
}
context.putImageData(texture, half, 0);
</script>
</body>
</html>UI Skills 原创示例