canvas实现彩色波纹海浪滚滚动画效果代码
代码语言:html
所属分类:动画
代码描述:canvas实现彩色波纹海浪滚滚动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> html, body { padding: 0px; margin: 0px; overflow: hidden; } canvas { width: 100%; height: 100%; } </style> </head> <body > <canvas></canvas> <script id="fragment-shader" type="x-shader/x-fragment"> #ifdef GL_ES precision highp float; #endif uniform vec2 u_resolution; uniform vec2 u_mouse; uniform float u_time; float repeat = u_resolution.x / 5.0; float wibblyness = 10.0; void main() { float test = mod(gl_FragCoord.x + (sin((gl_FragCoord.y / 20.0)) * wibblyness) + (u_time * 100.0) + (gl_FragCoord.y / 2.0), repeat) / repeat; float test2 = mod(gl_FragCoord.y - (sin((gl_FragCoord.x / 20.0)) * wibblyness) + (u_time * 100.0) - (gl_FragCoord.x / 2.0), repeat) / repeat; gl_FragColor = vec4(test,test2,1.0,1.0); } </script> <script id="vertex-shader" type="x-shader/x-vertex"> attribute vec2 a_position; void main() { gl_Position = vec4( a_position, 0, 1 ); } </script> <script > var canvas = document.querySelector('canvas'); var gl = canvas.getContext('webgl'); var width, height; var mouseX = 0; var mouseY = 0; var startTime = new Date().getTime(); // Get start time for animating // ----- Uniform ----- // function Uniform(name, suffix) { this.name = name; this.suffix = suffix; this.location = gl.getUniformLocation(program, name); } Uniform.prototype.set = function (...values) { var method = 'uniform' + this.suffix; var args = [this.location].concat(values); gl[method].apply(gl, args); }; // ----- Rect ----- // function Rect(gl) { var buffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buffer); gl.bufferData(gl.ARRAY_BUFFER, Rect.verts, gl.STATIC_DRAW); } Rect.verts = new Float32Array([ -1, -1, 1, -1, -1, 1, 1, 1]); Rect.prototype.render = function (gl) { gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); }; // ----- init.........完整代码请登录后点击上方下载按钮下载查看
网友评论0