three+tone实现多种三维图形变换屏保动画效果代码
代码语言:html
所属分类:动画
代码描述:three+tone实现多种三维图形变换屏保动画效果代码,可以选择不同的shape和颜色配置,还可以设置具体动画参数。
代码标签: three tone 多种 三维 图形 变换 屏保 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; font-family: Arial, sans-serif; background: #000; color: #fff; } .settings-panel { position: fixed; top: 70px; right: -300px; /* Start off-screen */ width: 300px; height: 100%; background: rgba(0, 0, 0, 0.8); transition: right 0.3s ease-in-out; overflow-y: auto; z-index: 1000; padding: 20px; box-sizing: border-box; } .settings-panel.open { left: 0; } .settings-toggle { position: fixed; top: 10px; left: 10px; background: none; border: none; color: white; font-size: 24px; cursor: pointer; z-index: 1001; opacity: 0.7; transition: opacity 0.3s; } .settings-toggle:hover { opacity: 1; } button { background-color: #4CAF50; border: none; color: white; padding: 10px 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 5px; transition: background-color 0.3s; } button:hover { background-color: #45a049; } button:disabled { background-color: #cccccc; cursor: not-allowed; } .fullscreen-button { width: 100%; margin-bottom: 20px; background-color: #4CAF50; border: none; color: white; padding: 10px 20px; text-align: center; text-decoration: none; display: block; font-size: 16px; cursor: pointer; border-radius: 5px; transition: background-color 0.3s; } .fullscreen-button:hover { background-color: #45a049; } .randomize-button { width: 100%; margin-bottom: 20px; background-color: #4CAF50; border: none; color: white; padding: 10px 20px; text-align: center; text-decoration: none; display: block; font-size: 16px; cursor: pointer; border-radius: 5px; transition: background-color 0.3s; } .randomize-button:hover { background-color: #45a049; } .slider { -webkit-appearance: none; width: 100%; height: 15px; border-radius: 5px; background: #d3d3d3; outline: none; opacity: 0.7; transition: opacity .2s; margin: 10px 0; } .slider:hover { opacity: 1; } .slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 25px; height: 25px; border-radius: 50%; background: #4CAF50; cursor: pointer; } .slider::-moz-range-thumb { width: 25px; height: 25px; border-radius: 50%; background: #4CAF50; cursor: pointer; } #tempoValue, #speedValue, #rotationValue, #colorCycleSpeedValue, #colorIntensityValue, #zoomValue, #teleidoscopeSidesValue, #teleidoscopeRotationSpeedValue, #edgeThicknessValue, #starEdgeLengthValue, #starEdgeAngleValue, #distortionAmountValue, #distortionSpeedValue { display: inline-block; width: 50px; text-align: right; } </style> </head> <body translate="no"> <div id="settingsPanel" class="settings-panel"> <div id="settingsContent"> <div> <button id="fullscreenToggle" class="fullscreen-button">Toggle Fullscreen</button> <button id="randomizeButton" class="randomize-button">Randomize All Settings</button> </div> <div> <label for="shapeSelect">Shape:</label> <select id="shapeSelect"> <option value="circle">Circle</option> <option value="square">Square</option> <option value="triangle" selected>Triangle</option> <option value="pentagram">Pentagram</option> <option value="heptagram">Heptagram</option> <option value="octagram">Octagram</option> <option value="enneagram">Enneagram</option> <option value="decagram">Decagram</option> <option value="hendecagram">Hendecagram</option> <option value="dodecagram">Dodecagram</option> </select> </div> <div> <label for="colorGroup">Color Group:</label> <select id="colorGroup"> <option value="group1" selected>Vibrant Red-Blue</option> <option value="group2">Sunset Ocean</option> <option value="group3">Neon Spectrum</option> <option value="group4">Nature Pop</option> <option value="group5">Citrus Twilight</option> <option value="group6">Forest Glow</option> <option value="group7">Candy Cosmos</option> <option value="group8">Royal Prism</option> <option value="custom">Custom</option> </select> </div> <div id="customColorInputs" style="display: none;"> <input type="color" id="customColor1" value="#FF0000"> <input type="color" id="customColor2" value="#00FFFF"> <input type="color" id="customColor3" value="#FFFF00"> <input type="color" id="customColor4" value="#0000FF"> </div> <div> <label for="randomizeColors">Randomize Colors:</label> <input type="checkbox" id="randomizeColors" checked> </div> <div> <label for="enableTeleidoscope">Enable Teleidoscope:</label> <input type="checkbox" id="enableTeleidoscope"> </div> <div> <label for="speed">Speed: <span id="speedValue">1</span></label> <input type="range" min="0" max="5" value="1" step="0.1" class="slider" id="speed"> </div> <div> <label for="rotation">Rotation: <span id="rotationValue">1.5</span></label> <input type="range" min="0" max="5" value="1.5" step="0.1" class="slider" id="rotation"> </div> <div> <label for="colorCycleSpeed">Color Cycle Speed: <span id="colorCycleSpeedValue">0.8</span></label> <input type="range" min="0" max="10" value="0.8" step="0.1" class="slider" id="colorCycleSpeed"> </div> <div> <label for="colorIntensity">Color Intensity: <span id="colorIntensityValue">0.2</span></label> <input type="range" min="0" max="2" value="0.2" step="0.1" class="slider" id="colorIntensity"> </div> <div> <label for="zoom">Zoom: <span id="zoomValue">1</span></label> <input type="range" min="0.1" max="5" value="1" step="0.1" class="slider" id="zoom"> </div> <div> <label for="teleidoscopeSides"># of Sides: <span id="teleidoscopeSidesValue">10</span></label> <input type="range" min="3" max="12" value="10" step="1" class="slider" id="teleidoscopeSides"> </div> <div> <label for="teleidoscopeRotationSpeed">Spin: <span id="teleidoscopeRotationSpeedValue">-1.5</span></label> <input type="range" min="-5" max="5" value="-1.5" step="0.1" class="slider" id="teleidoscopeRotationSpeed"> </div> <div> <label for="edgeThickness">Edge Thickness: <span id="edgeThicknessValue">0.050</span></label> <input type="range" min="0" max="0.5" value="0.050" step="0.001" class="slider" id="edgeThickness"> </div> <div> <label for="starEdgeLength">Star Edge Length: <span id="starEdgeLengthValue">-0.52</span></label> <input type="range" min="0.1" max="5" value="-0.52" step="0.1" class="slider" id="starEdgeLength"> </div> <div> <label for="starEdgeAngle">Star Edge Angle: <span id="starEdgeAngleValue">-0.6</span></label> <input type="range" min="-1" max="1" value="-0.6" step="0.01" class="slider" id="starEdgeAngle"> </div> <div> <label for="distortionAmount">Distortion Amount: <span id="distortionAmountValue">0.1</span></label> <input type="range" min="0" max="1" value="0.1" step="0.01" class="slider" id="distortionAmount"> </div> <div> <label for="distortionSpeed">Distortion Speed: <span id="distortionSpeedValue">2</span></label> <input type="range" min="0" max="5" value="2" step="0.1" class="slider" id="distortionSpeed"> </div> <div> <label for="randomizeTime">Randomize Change Time: <span id="randomizeTimeValue">15</span> seconds</label> <input type="range" min="5" max="300" value="15" class="slider" id="randomizeTime"> </div> </div> </div> <button id="settingsToggle" class="settings-toggle">⚙️</button> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.128.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Tone.min.js"></script> <script id="vertexShader" type="x-shader/x-vertex"> varying vec2 vUv; void main() { vUv = uv; gl_Position = vec4(position, 1.0); } </script> <script id="fragmentShader" type="x-shader/x-fragment"> uniform vec2 iResolution; uniform float iTime; uniform float speed; uniform float rotation; uniform float colorCycleSpeed; uniform float colorIntensity; uniform bool enableTeleidoscope; uniform float zoom; uniform int teleidoscopeSides; uniform float teleidoscopeRotationSpeed; uniform int shapeType; uniform float edgeThickness; uniform float starEdgeLength; uniform float starEdgeAngle; uniform float distortionAmount; uniform float distortionSpeed; uniform vec3 paletteColor1; uniform vec3 paletteColor2; uniform vec3 paletteColor3; uniform vec3 paletteColor4; #define TIME iTime #define RESOLUTION iResolution #define ROT(a) mat2(cos(a), sin(a), -sin(a), cos(a)) const float pi = acos(-1.) , tau = 2.*pi , planeDist = .5 , furthest = 16. , fadeFrom = 8. ; const vec2 pathA = vec2(.31, .41) , pathB = vec2(1.0,sqrt(0.5)) ; const vec4 U = vec4(0, 1, 2, 3) ; vec3 aces_approx(vec3 v) { v = max(v, 0.0); v *= 0.6; float a = 2.51; float b = 0.03; float c = 2.43; float d = 0.59; float e = 0.14; return clamp((v*(a*v+b))/(v*(c*v+d)+e), 0.0, 1.0); } vec3 offset(float z) { return vec3(pathB*sin(pathA*z), z); } vec3 doffset(float z) { return vec3(pathA*pathB*cos(pathA*z), 1.0); } vec3 ddoffset(float z) { return vec3(-pathA*pathA*pathB*sin(pathA*z), 0.0); } vec4 alphaBlend(vec4 back, vec4 front) { float w = front.w + back.w*(1.0-front.w); vec3 xyz = (front.xyz*front.w + back.xyz*back.w*(1.0-front.w))/w; return w > 0.0 ? vec4(xyz, w) : vec4(0.0); } float pmin(float a, float b, float k) { float h = clamp(0.5+0.5*(b-a)/k, 0.0, 1.0); return mix(b, a, h) - k*h*(1.0-h); } float pmax(float a, float b, float k) { return -pmin(-a, -b, k); } float pabs(float a, float k) { return -pmin(a, -a, k); } float shape(vec2 p, float r, float sm) { float d; if (shapeType == 1) { // Square vec2 d2 = abs(p) - r; d = min(max(d2.x, d2.y), 0.0) + length(max(d2, 0.0)); } else if (shapeType == 2) { // Triangle const float k = sqrt(3.0); p.x = abs(p.x) - r; p.y = p.y + r/k; if (p.x + k*p.y > 0.0) p = vec2(p.x-k*p.y,-k*p.x-p.y)/2.0; p.x -= clamp(p.x, -2.0*r, 0.0); d = -length(p)*sign(p.y); } else if (shapeType >= 3) { // Star shapes int n = shapeType + 2; // Number of points float an = 3.141593 / float(n); float en = 3.141593 / float(n); vec2 acs = vec2(cos(an), sin(an)); vec2 ecs = vec2(cos(en), sin(en)); float bn = mod(atan(p.x, p.y), 2.0 * an) - an; p = length(p) * vec2(cos(bn), abs(sin(bn))); p -= r * acs; vec2 sc = vec2(cos(starEdgeAngle), sin(starEdgeAngle)); p += sc * clamp(-dot(p, sc), 0.0, r * acs.y / ecs.y * starEdgeLength); d = length(p) * sign(p.x); } else { // Circle (default) d = length(p) - r; } return smoothstep(edgeThickness, 0.0, abs(d)) - sm; } vec3 hsv2rgb(vec3 c) { vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } vec3 palette(float t) { vec3 a = paletteColor1; vec3 b = paletteColor2; vec3 c = paletteColor3; vec3 d = paletteColor4; return a + b * cos(6.28318 * (c * t + d)); } vec2 distort(vec2 p) { float angle = atan(p.y, p.x); float radius = length(p); float distortion = sin(radius * 10.0 + iTime * distortionSpeed) * distortionAmount; return p + vec2(cos(angle), sin(angle)) * distortion; } vec4 plane(vec3 ro, vec3 rd, vec3 pp, vec3 npp, float pd, vec3 cp, vec3 off, float n) { float aa = 3.*pd*distance(pp.xy, npp.xy); vec4 col = vec4(0.); vec2 p2 = pp.xy; p2 -= offset(pp.z).xy; vec2 doff = ddoffset(pp.z).xz; vec2 ddoff = doffset(pp.z).xz; float dd = dot(doff, ddoff); p2 *= ROT(dd*pi*5.*rotation); p2 = distort(p2); float d0 = shape(p2, 0.45, 0.02); float d1 = d0-0.01; float d2 = length(p2); const float colp = pi*100.; float colaa = aa*200.; col.xyz = palette(0.5*n + 2.0*d2 + iTime * colorCycleSpeed) * mix(0.5/(d2*d2), 1., smoothstep(-0.5+colaa, 0.5+colaa, sin(d2*colp))) / max(3.*d2*d2, 1E-1); col.xyz *= colorIntensity; col.xyz = mix(col.xyz, vec3(2.), smoothstep(aa, -aa, d1)); col.w = smoothstep(aa, -aa, -d0); return col; } vec3 color(vec3 ww, vec3 uu, vec3 vv, vec3 ro, vec2 p) { float lp = length(p); vec2 np = p + 1./RESOLUTION.xy; float rdd = 2.0-0.25; vec3 rd = normalize(p.x*uu + p.y*vv + rdd*ww); vec3 nrd = normalize(np.x*uu + np.y*vv + rdd*ww); float nz = floor(ro.z / planeDist); vec4 acol = vec4(0.0); vec3 aro = ro; float apd = 0.0; for (float i = 1.; i <= furthest; ++i) { if ( acol.w > 0.95) { break; } float pz = planeDist*nz + planeDist*i; float lpd = (pz - aro.z)/rd.z; float npd = (pz - aro.z)/nrd.z; float cpd = (pz - aro.z)/ww.z; { vec3 pp = aro + rd*lpd; vec3 npp= aro + nrd*npd; vec3 cp = aro+ww*cpd; apd += lpd; vec3 off = offset(pp.z); float dz = pp.z-ro.z; float fadeIn = smoothstep(planeDist*furthest, planeDist*fadeFrom, dz); float fadeOut = smoothstep(0., planeDist*.1, dz); float fadeOutRI = smoothstep(0., planeDist*1.0, dz); float ri = mix(1.0, 0.9, fadeOutRI*fadeIn); vec4 pcol = plane(ro, rd, pp, npp, apd, cp, off, nz+i); pcol.w *= fadeOut*fadeIn; acol = alphaBlend(pcol, acol); aro = pp; } } return acol.xyz*acol.w; } vec2 kale(vec2 uv, int sides, float rotationOffset) { float a = atan(uv.y, uv.x) + rotationOffset; float r = length(uv); float pi = 3.14159; float angle = 2.0*pi/float(sides); a = mod(a, angle); a = abs(a - angle/2.0); return vec2(cos(a), sin(a)) * r; } void main() { vec2 r = RESOLUTION.xy, q = gl_FragCoord.xy/r, pp = -1.0+2.0*q, p = pp; p.x *= r.x/r.y; if (enableTeleidoscope) { p *= zoom; float rotationOffset = teleidoscopeRotationSpeed * TIME; p = kale(p, teleidoscopeSides, rotationOffset); } float tm = pl.........完整代码请登录后点击上方下载按钮下载查看
网友评论0