用regl.js实现催眠动画特效
代码语言:html
所属分类:动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> Rainbow Colored Hexagon Stars</title> <style> .ui { position: absolute; z-index: 1; } label { display: block; font-size: .8; } </style> </head> <body translate="no"> <script id="fragmentShader" type="x-shader/fragment"> precision highp float; uniform float time; uniform float width; uniform float height; const float PI = 3.141592654; const float DEG = PI / 180.0; vec2 coords() { float vmin = min(width, height); return vec2((gl_FragCoord.x - width * .5) / vmin, (gl_FragCoord.y - height * .5) / vmin); } vec2 rotate(vec2 p, float a) { return vec2(p.x * cos(a) - p.y * sin(a), p.x * sin(a) + p.y * cos(a)); } vec2 repeat(in vec2 p, in vec2 c) { return mod(p, c) - 0.5 * c; } // Distance functions by Inigo Quilez // https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm float circle(in vec2 p, in vec2 pos, float radius) { return length(p - pos) - radius; } float box(in vec2 p, in vec2 pos, in vec2 b) { vec2 d = abs(p - pos) - b; return length(max(d, vec2(0))) + min(max(d.x, d.y), 0.0); } float triangle(in vec2 p, in float h) { const float k = sqrt(3.0); p.x = abs(p.x) - h; p.y = p.y + h / 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, 0.0 ); return -length(p)*sign(p.y); } float hexagon(in vec2 p, in vec2 pos, in float r) { const vec3 k = vec3(-0.866025404,0.5,0.577350269); p = abs(p - pos); p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); return length(p) * sign(p.y); } float hexagram(in vec2 p, in vec2 pos, in float r) { const vec4 k=vec4(-0.5,0.8660254038,0.5773502692,1.7320508076); p = abs(p - pos); p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; p -= 2.0*min(dot(k.yx,p),0.0)*k.yx; p -= vec2(clamp(p.x,r*k.z,r*k.w),r); return length(p)*sign(p.y); } float distanceField(vec2 p) { float hexa = hexagon(p, vec2(0, 0), 1.5); float star = hexagram(p, vec2(0, 0), .5); float x = (1.0 + sin(time * 0.5)) * .5; return mix(hexa, star, x); } // by @mattdesl float hue2rgb(float f1, float f2, float hue) { if (hue < 0.0) hue += 1.0; else if (hue > 1.0) hue -= 1.0; float res; if ((6..........完整代码请登录后点击上方下载按钮下载查看
网友评论0