style: 说明页改为流动光轨
This commit is contained in:
@@ -8,122 +8,98 @@ const copied = ref(false);
|
|||||||
const copyFailed = ref(false);
|
const copyFailed = ref(false);
|
||||||
let copiedTimer = 0;
|
let copiedTimer = 0;
|
||||||
let frame = 0;
|
let frame = 0;
|
||||||
let gl: WebGLRenderingContext | null = null;
|
let running = false;
|
||||||
|
|
||||||
const VERT = `
|
type Mote = { x: number; y: number; hue: number; life: number };
|
||||||
attribute vec2 aPos;
|
|
||||||
void main() {
|
|
||||||
gl_Position = vec4(aPos, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const FRAG = `
|
const motes: Mote[] = [];
|
||||||
precision highp float;
|
|
||||||
uniform vec2 uRes;
|
|
||||||
uniform float uTime;
|
|
||||||
|
|
||||||
float hash(vec2 p) {
|
function field(x: number, y: number, time: number) {
|
||||||
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
|
const scale = 0.0016;
|
||||||
|
const a = Math.sin(x * scale * 2.4 + time * 0.35);
|
||||||
|
const b = Math.cos(y * scale * 2.1 - time * 0.28);
|
||||||
|
const c = Math.sin((x + y) * scale * 1.3 + time * 0.16);
|
||||||
|
return Math.atan2(b + c, a - c);
|
||||||
}
|
}
|
||||||
|
|
||||||
float noise(vec2 p) {
|
function seed(width: number, height: number, count: number) {
|
||||||
vec2 i = floor(p);
|
motes.length = 0;
|
||||||
vec2 f = fract(p);
|
for (let index = 0; index < count; index += 1) {
|
||||||
float a = hash(i);
|
motes.push({
|
||||||
float b = hash(i + vec2(1.0, 0.0));
|
x: Math.random() * width,
|
||||||
float c = hash(i + vec2(0.0, 1.0));
|
y: Math.random() * height,
|
||||||
float d = hash(i + vec2(1.0, 1.0));
|
hue: 168 + Math.random() * 70,
|
||||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
life: Math.random(),
|
||||||
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec2 p = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;
|
|
||||||
float t = uTime;
|
|
||||||
vec3 sky = vec3(0.012, 0.018, 0.04);
|
|
||||||
vec2 cell = floor(gl_FragCoord.xy / 2.0);
|
|
||||||
float star = hash(cell);
|
|
||||||
float twinkle = 0.65 + 0.35 * sin(t * 1.7 + star * 40.0);
|
|
||||||
sky += smoothstep(0.996, 1.0, star) * twinkle;
|
|
||||||
|
|
||||||
float field = noise(vec2(p.x * 1.6 + t * 0.04, t * 0.11));
|
|
||||||
vec3 color = sky;
|
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
float fi = float(i);
|
|
||||||
float wave = sin(p.x * (2.2 + fi * 0.35) + t * (0.18 + fi * 0.03) + fi);
|
|
||||||
float y = -0.05 + fi * 0.07 + wave * 0.09 + field * 0.18;
|
|
||||||
float d = abs(p.y - y);
|
|
||||||
float curtain = exp(-d * d * (90.0 + fi * 30.0));
|
|
||||||
vec3 tint = mix(vec3(0.15, 0.95, 0.62), vec3(0.45, 0.35, 1.0), fi / 4.0);
|
|
||||||
tint = mix(tint, vec3(0.95, 0.72, 0.38), smoothstep(0.6, 1.4, p.x + fi * 0.1));
|
|
||||||
color += tint * curtain * (0.28 + 0.08 * sin(t + fi));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float horizon = exp(-pow(p.y + 0.55, 2.0) * 2.2);
|
|
||||||
color += vec3(0.05, 0.12, 0.18) * horizon;
|
|
||||||
float vignette = smoothstep(1.35, 0.25, length(p));
|
|
||||||
gl_FragColor = vec4(color * vignette, 1.0);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
function compile(context: WebGLRenderingContext, type: number, source: string) {
|
|
||||||
const shader = context.createShader(type);
|
|
||||||
if (!shader) return null;
|
|
||||||
context.shaderSource(shader, source);
|
|
||||||
context.compileShader(shader);
|
|
||||||
if (!context.getShaderParameter(shader, context.COMPILE_STATUS)) {
|
|
||||||
context.deleteShader(shader);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return shader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resize() {
|
function step(mote: Mote, width: number, height: number, time: number) {
|
||||||
const canvas = canvasEl.value;
|
const angle = field(mote.x, mote.y, time);
|
||||||
if (!canvas || !gl) return;
|
mote.x += Math.cos(angle) * 2.4;
|
||||||
const ratio = Math.min(window.devicePixelRatio || 1, 2);
|
mote.y += Math.sin(angle) * 2.4;
|
||||||
const width = Math.floor(canvas.clientWidth * ratio);
|
mote.life -= 0.004;
|
||||||
const height = Math.floor(canvas.clientHeight * ratio);
|
if (mote.life <= 0 || mote.x < -20 || mote.y < -20 || mote.x > width + 20 || mote.y > height + 20) {
|
||||||
if (canvas.width !== width || canvas.height !== height) {
|
mote.x = Math.random() * width;
|
||||||
canvas.width = width;
|
mote.y = Math.random() * height;
|
||||||
canvas.height = height;
|
mote.life = 0.6 + Math.random() * 0.4;
|
||||||
gl.viewport(0, 0, width, height);
|
mote.hue = 168 + Math.random() * 80;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function startField() {
|
function startField() {
|
||||||
const canvas = canvasEl.value;
|
const canvas = canvasEl.value;
|
||||||
if (!canvas) return;
|
if (!canvas) return;
|
||||||
gl = canvas.getContext("webgl", { antialias: false, alpha: false });
|
const context = canvas.getContext("2d");
|
||||||
if (!gl) return;
|
if (!context) return;
|
||||||
const vertex = compile(gl, gl.VERTEX_SHADER, VERT);
|
|
||||||
const fragment = compile(gl, gl.FRAGMENT_SHADER, FRAG);
|
|
||||||
if (!vertex || !fragment) return;
|
|
||||||
const program = gl.createProgram();
|
|
||||||
if (!program) return;
|
|
||||||
gl.attachShader(program, vertex);
|
|
||||||
gl.attachShader(program, fragment);
|
|
||||||
gl.bindAttribLocation(program, 0, "aPos");
|
|
||||||
gl.linkProgram(program);
|
|
||||||
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) return;
|
|
||||||
gl.useProgram(program);
|
|
||||||
const buffer = gl.createBuffer();
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
|
|
||||||
gl.enableVertexAttribArray(0);
|
|
||||||
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
|
|
||||||
const res = gl.getUniformLocation(program, "uRes");
|
|
||||||
const time = gl.getUniformLocation(program, "uTime");
|
|
||||||
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||||
const draw = (now: number) => {
|
let width = 0;
|
||||||
if (!gl) return;
|
let height = 0;
|
||||||
resize();
|
|
||||||
gl.uniform2f(res, canvas.width, canvas.height);
|
const fit = () => {
|
||||||
gl.uniform1f(time, reduced ? 8 : now * 0.001);
|
const ratio = Math.min(window.devicePixelRatio || 1, 2);
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
const nextWidth = Math.floor(canvas.clientWidth * ratio);
|
||||||
if (!reduced) frame = requestAnimationFrame(draw);
|
const nextHeight = Math.floor(canvas.clientHeight * ratio);
|
||||||
|
if (canvas.width === nextWidth && canvas.height === nextHeight) return;
|
||||||
|
canvas.width = nextWidth;
|
||||||
|
canvas.height = nextHeight;
|
||||||
|
width = nextWidth;
|
||||||
|
height = nextHeight;
|
||||||
|
seed(width, height, Math.min(900, Math.floor((width * height) / 2800)));
|
||||||
|
context.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
};
|
};
|
||||||
resize();
|
|
||||||
|
const draw = (now: number) => {
|
||||||
|
if (!running) return;
|
||||||
|
fit();
|
||||||
|
const time = now * 0.001;
|
||||||
|
context.globalCompositeOperation = "source-over";
|
||||||
|
context.fillStyle = "rgba(4, 6, 12, 0.08)";
|
||||||
|
context.fillRect(0, 0, width, height);
|
||||||
|
context.globalCompositeOperation = "lighter";
|
||||||
|
context.lineWidth = 2.2;
|
||||||
|
for (const mote of motes) {
|
||||||
|
const fromX = mote.x;
|
||||||
|
const fromY = mote.y;
|
||||||
|
if (!reduced) step(mote, width, height, time);
|
||||||
|
else {
|
||||||
|
for (let warm = 0; warm < 24; warm += 1) step(mote, width, height, 4);
|
||||||
|
}
|
||||||
|
context.strokeStyle = `hsla(${mote.hue}, 100%, 70%, 0.9)`;
|
||||||
|
context.beginPath();
|
||||||
|
context.moveTo(fromX, fromY);
|
||||||
|
context.lineTo(mote.x, mote.y);
|
||||||
|
context.stroke();
|
||||||
|
}
|
||||||
|
context.globalCompositeOperation = "source-over";
|
||||||
|
if (reduced) return;
|
||||||
|
frame = requestAnimationFrame(draw);
|
||||||
|
};
|
||||||
|
|
||||||
|
running = true;
|
||||||
|
fit();
|
||||||
|
context.fillStyle = "#04060c";
|
||||||
|
context.fillRect(0, 0, width, height);
|
||||||
frame = requestAnimationFrame(draw);
|
frame = requestAnimationFrame(draw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,9 +128,9 @@ async function copyUrl() {
|
|||||||
|
|
||||||
onMounted(startField);
|
onMounted(startField);
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
running = false;
|
||||||
cancelAnimationFrame(frame);
|
cancelAnimationFrame(frame);
|
||||||
window.clearTimeout(copiedTimer);
|
window.clearTimeout(copiedTimer);
|
||||||
gl = null;
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -179,8 +155,8 @@ onUnmounted(() => {
|
|||||||
inset: 0;
|
inset: 0;
|
||||||
z-index: 20;
|
z-index: 20;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
color: #f4fff8;
|
color: #f7fbff;
|
||||||
background: #05070c;
|
background: #04060c;
|
||||||
font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +173,7 @@ onUnmounted(() => {
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
width: min(640px, calc(100% - 48px));
|
width: min(640px, calc(100% - 48px));
|
||||||
margin: 18vh auto 48px;
|
margin: 18vh auto 48px;
|
||||||
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.65);
|
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.8);
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
@@ -211,7 +187,7 @@ h1 {
|
|||||||
p {
|
p {
|
||||||
margin: 0 0 10px;
|
margin: 0 0 10px;
|
||||||
max-width: 38rem;
|
max-width: 38rem;
|
||||||
color: rgba(244, 255, 248, 0.86);
|
color: rgba(247, 251, 255, 0.88);
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
line-height: 1.7;
|
line-height: 1.7;
|
||||||
}
|
}
|
||||||
@@ -220,7 +196,6 @@ p {
|
|||||||
margin: 22px 0 18px;
|
margin: 22px 0 18px;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
font-size: clamp(18px, 2.4vw, 28px);
|
font-size: clamp(18px, 2.4vw, 28px);
|
||||||
letter-spacing: 0.01em;
|
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
user-select: all;
|
user-select: all;
|
||||||
}
|
}
|
||||||
@@ -228,18 +203,17 @@ p {
|
|||||||
.copy-btn {
|
.copy-btn {
|
||||||
height: 42px;
|
height: 42px;
|
||||||
padding: 0 18px;
|
padding: 0 18px;
|
||||||
border: 1px solid rgba(190, 255, 214, 0.7);
|
border: 1px solid rgba(186, 230, 255, 0.75);
|
||||||
border-radius: 999px;
|
border-radius: 999px;
|
||||||
background: rgba(8, 16, 14, 0.45);
|
background: rgba(6, 12, 20, 0.4);
|
||||||
color: #e9fff3;
|
color: #f3fbff;
|
||||||
font: inherit;
|
font: inherit;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
backdrop-filter: blur(8px);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.copy-btn:hover {
|
.copy-btn:hover {
|
||||||
background: rgba(120, 255, 190, 0.16);
|
background: rgba(120, 210, 255, 0.16);
|
||||||
}
|
}
|
||||||
|
|
||||||
.result {
|
.result {
|
||||||
@@ -248,7 +222,7 @@ p {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.ok {
|
.ok {
|
||||||
color: #d8ffe6;
|
color: #d9fff1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.miss {
|
.miss {
|
||||||
|
|||||||
Reference in New Issue
Block a user