gsap+sketchjs实现一个水墨风格墨水绘画效果代码
代码语言:html
所属分类:动画
代码描述:gsap+sketchjs实现一个水墨风格墨水绘画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
html,body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
#container, #container canvas {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
display: block;
}
</style>
</head>
<body>
<div id="container">
</div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery.2.11.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/sketch.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TweenMax.min.js"></script>
<script>
$(Main);
function Main () {
// ----------------------------------------
// Particle
// ----------------------------------------
function Particle(x, y, radius) {
this.init(x, y, radius);
}
Particle.prototype = {
points: [],
init: function(x, y, radius) {
this.alive = true;
this.radius = radius || 10;
this.wander = 0.15;
this.theta = random(TWO_PI);
this.drag = 0.92;
this.color = '#fff';
this.x = x || 0.0;
this.y = y || 0.0;
this.vx = 0.0;
this.vy = 0.0;
},
move: function() {
//this.points.push( {x: this.x, y: this.y } );
this.x += this.vx;
this.y += this.vy;
this.vx *= this.drag;
this.vy *= this.drag;
this.theta += random(-0.5, 0.5) * this.wander;
this.vx += sin(this.theta) * 0.1;
this.vy += cos(this.theta) * 0.1;
this.radius *= 0.96;
this.alive = this.radius > 0.1;
},
draw: function(ctx) {
ctx.beginPath()
ctx.arc(this.x, this.y, this.radius, 0, TWO_PI);
ctx.fillStyle = this.color;
ctx.strokeStyle = 'transparent'; //this.color;
ctx.fill();
ctx.stroke();
}
};
// -----.........完整代码请登录后点击上方下载按钮下载查看
网友评论0