注册 登录 充值会员 退出
毕业设计 PHP源码
充值

HTML5 Canvas马赛克背景缩放动画特效

作者/代码整理:  (转载请附加本文地址,带有“懒人原生”字样的谢绝转载) 发布日期:2018-12-01
HTML5 Canvas马赛克背景缩放动画特效
HTML5 Canvas马赛克背景缩放动画特效,有规律的缩放大小马赛克背景,我看久了头会晕,不知道大家会不会。


js代码

<script id="fragmentShader" type="x-shader/fragment">
precision mediump float;

uniform float time;
uniform float width;
uniform float height;
uniform float red;
uniform float green;
uniform float blue;
uniform float zoom;
uniform float rotation;
  
const float PI = 3.141592654;
  
void main () {
  
  vec2 p0 = vec2(gl_FragCoord) * zoom;
  float a = rotation * PI / 180.0;
  vec2 p = vec2(p0.x * cos(a) - p0.y * sin(a),
                p0.x * sin(a) + p0.y * cos(a));
  vec3 c = vec3(red, green, blue);
  
  vec3 color = (c * 
                sin(sin(time * 0.1) * 4.0 * PI * sin(p.x * .025)) * 
                sin(sin(time * 0.1) * 4.0 * PI * sin(p.y * .025) ));
  gl_FragColor = vec4(vec3(color), 1.0);
}
</script>
<script id="vertexShader" type="x-shader/vertex">
precision mediump float;
attribute vec2 position;

void main () {
  gl_Position = vec4(position, 0, 1);
} 
</script>
<script src='js/regl.js'></script>
<script src='js/react.production.min.js'></script>
<script src='js/react-dom.production.min.js'></script>
<script  src="js/index.js"></script>