style: 说明页改为流动光轨
This commit is contained in:
@@ -8,122 +8,98 @@ const copied = ref(false);
|
||||
const copyFailed = ref(false);
|
||||
let copiedTimer = 0;
|
||||
let frame = 0;
|
||||
let gl: WebGLRenderingContext | null = null;
|
||||
let running = false;
|
||||
|
||||
const VERT = `
|
||||
attribute vec2 aPos;
|
||||
void main() {
|
||||
gl_Position = vec4(aPos, 0.0, 1.0);
|
||||
}
|
||||
`;
|
||||
type Mote = { x: number; y: number; hue: number; life: number };
|
||||
|
||||
const FRAG = `
|
||||
precision highp float;
|
||||
uniform vec2 uRes;
|
||||
uniform float uTime;
|
||||
const motes: Mote[] = [];
|
||||
|
||||
float hash(vec2 p) {
|
||||
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
|
||||
function field(x: number, y: number, time: number) {
|
||||
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) {
|
||||
vec2 i = floor(p);
|
||||
vec2 f = fract(p);
|
||||
float a = hash(i);
|
||||
float b = hash(i + vec2(1.0, 0.0));
|
||||
float c = hash(i + vec2(0.0, 1.0));
|
||||
float d = hash(i + vec2(1.0, 1.0));
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
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));
|
||||
function seed(width: number, height: number, count: number) {
|
||||
motes.length = 0;
|
||||
for (let index = 0; index < count; index += 1) {
|
||||
motes.push({
|
||||
x: Math.random() * width,
|
||||
y: Math.random() * height,
|
||||
hue: 168 + Math.random() * 70,
|
||||
life: Math.random(),
|
||||
});
|
||||
}
|
||||
|
||||
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() {
|
||||
const canvas = canvasEl.value;
|
||||
if (!canvas || !gl) return;
|
||||
const ratio = Math.min(window.devicePixelRatio || 1, 2);
|
||||
const width = Math.floor(canvas.clientWidth * ratio);
|
||||
const height = Math.floor(canvas.clientHeight * ratio);
|
||||
if (canvas.width !== width || canvas.height !== height) {
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
gl.viewport(0, 0, width, height);
|
||||
function step(mote: Mote, width: number, height: number, time: number) {
|
||||
const angle = field(mote.x, mote.y, time);
|
||||
mote.x += Math.cos(angle) * 2.4;
|
||||
mote.y += Math.sin(angle) * 2.4;
|
||||
mote.life -= 0.004;
|
||||
if (mote.life <= 0 || mote.x < -20 || mote.y < -20 || mote.x > width + 20 || mote.y > height + 20) {
|
||||
mote.x = Math.random() * width;
|
||||
mote.y = Math.random() * height;
|
||||
mote.life = 0.6 + Math.random() * 0.4;
|
||||
mote.hue = 168 + Math.random() * 80;
|
||||
}
|
||||
}
|
||||
|
||||
function startField() {
|
||||
const canvas = canvasEl.value;
|
||||
if (!canvas) return;
|
||||
gl = canvas.getContext("webgl", { antialias: false, alpha: false });
|
||||
if (!gl) 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 context = canvas.getContext("2d");
|
||||
if (!context) return;
|
||||
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
const draw = (now: number) => {
|
||||
if (!gl) return;
|
||||
resize();
|
||||
gl.uniform2f(res, canvas.width, canvas.height);
|
||||
gl.uniform1f(time, reduced ? 8 : now * 0.001);
|
||||
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
||||
if (!reduced) frame = requestAnimationFrame(draw);
|
||||
let width = 0;
|
||||
let height = 0;
|
||||
|
||||
const fit = () => {
|
||||
const ratio = Math.min(window.devicePixelRatio || 1, 2);
|
||||
const nextWidth = Math.floor(canvas.clientWidth * ratio);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -152,9 +128,9 @@ async function copyUrl() {
|
||||
|
||||
onMounted(startField);
|
||||
onUnmounted(() => {
|
||||
running = false;
|
||||
cancelAnimationFrame(frame);
|
||||
window.clearTimeout(copiedTimer);
|
||||
gl = null;
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -179,8 +155,8 @@ onUnmounted(() => {
|
||||
inset: 0;
|
||||
z-index: 20;
|
||||
overflow: auto;
|
||||
color: #f4fff8;
|
||||
background: #05070c;
|
||||
color: #f7fbff;
|
||||
background: #04060c;
|
||||
font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
||||
}
|
||||
|
||||
@@ -197,7 +173,7 @@ onUnmounted(() => {
|
||||
z-index: 1;
|
||||
width: min(640px, calc(100% - 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 {
|
||||
@@ -211,7 +187,7 @@ h1 {
|
||||
p {
|
||||
margin: 0 0 10px;
|
||||
max-width: 38rem;
|
||||
color: rgba(244, 255, 248, 0.86);
|
||||
color: rgba(247, 251, 255, 0.88);
|
||||
font-size: 16px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
@@ -220,7 +196,6 @@ p {
|
||||
margin: 22px 0 18px;
|
||||
color: #fff;
|
||||
font-size: clamp(18px, 2.4vw, 28px);
|
||||
letter-spacing: 0.01em;
|
||||
word-break: break-all;
|
||||
user-select: all;
|
||||
}
|
||||
@@ -228,18 +203,17 @@ p {
|
||||
.copy-btn {
|
||||
height: 42px;
|
||||
padding: 0 18px;
|
||||
border: 1px solid rgba(190, 255, 214, 0.7);
|
||||
border: 1px solid rgba(186, 230, 255, 0.75);
|
||||
border-radius: 999px;
|
||||
background: rgba(8, 16, 14, 0.45);
|
||||
color: #e9fff3;
|
||||
background: rgba(6, 12, 20, 0.4);
|
||||
color: #f3fbff;
|
||||
font: inherit;
|
||||
font-size: 15px;
|
||||
cursor: pointer;
|
||||
backdrop-filter: blur(8px);
|
||||
}
|
||||
|
||||
.copy-btn:hover {
|
||||
background: rgba(120, 255, 190, 0.16);
|
||||
background: rgba(120, 210, 255, 0.16);
|
||||
}
|
||||
|
||||
.result {
|
||||
@@ -248,7 +222,7 @@ p {
|
||||
}
|
||||
|
||||
.ok {
|
||||
color: #d8ffe6;
|
||||
color: #d9fff1;
|
||||
}
|
||||
|
||||
.miss {
|
||||
|
||||
Reference in New Issue
Block a user