canvas实现图片万花筒变换动画效果代码
代码语言:html
所属分类:动画
代码描述:canvas实现图片万花筒变换动画效果代码,可调参数
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
</head>
<body translate="no">
<script >
var doc = document,
win = window,
body = doc.body;
var ww = win.innerWidth,
wh = win.innerHeight;
var c = doc.createElement('canvas'),
ctx = c.getContext('2d');
var half_PI = Math.PI / 2,
two_PI = Math.PI * 2,
ease = 0.01;
var k = {
offsetRotation: 0,
offsetScale: 0.8,
offsetX: 0,
offsetY: 0,
radius: 1100,
slices: 24,
zoom: 1.5 };
body.appendChild(c);
c.width = k.radius * 2;
c.height = k.radius * 2;
var img = new Image();
img.crossOrigin = "Anonymous"; // This allows the image to be used with canvas (necessary for some external images)
img.onload = function () {
var fill = ctx.createPattern(img, 'repeat');
var scale, step, cx;
scale = k.zoom * (k.radius / Math.min(img.width, img.height));
step = two_PI / k.slices;
cx = img.width / 2;
function draw() {
ctx.clearRect(0, 0, c.width, c.height); // Clear canvas before drawing each frame
ctx.fillStyle = fill;
for (var i = 0; i <= k.slices; i++) {
ctx.save();
ctx.translate(k.radius, k.radius);
ctx.rotate(i * step);
ctx.beginPath();
ctx.moveTo(-0.5, -0.5);
ct.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0