canvas彩色油漆滴落线条动画效果代码
代码语言:html
所属分类:动画
代码描述:canvas彩色油漆滴落线条动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { background-color: #FFFFFF; margin:0px;} </style> </head> <body> <canvas id='c'></canvas> <!-- partial --> <script > var width = window.innerWidth, height = window.innerHeight, c = document.getElementById('c'), ctx = c.getContext('2d'); c.width = width; c.height = height; var paint = []; var totalPaints = width/50; var size = 20; function init(){ for (var i = 0; i < totalPaints; i++){ addPaint(); } setInterval( update, 40 ); } function drawPaint(x,y,size, colour) { ctx.beginPath(); ctx.arc(x, y, size ,0 , Math.PI*2, true); ctx.closePath(); ctx.fillStyle=colour; ctx.fill(); } function update(){ for (var i = 0; i < paint.length; i++){ paint[i].y = paint[i].y + paint[i].v; if (paint[i].y > height + 60){ paint.splice(i,1); addPaint(); } drawPaint(pain.........完整代码请登录后点击上方下载按钮下载查看
网友评论0