非常不错的canvas效果,下面是html代码。

 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
<title> 似圆非圆,似线非线 </title>
<style>
.stage{position:absolute;left:0;top:0;width:100%;height:100%;background:#000;}
</style>
</head>
<body>
<canvas class="stage"></canvas>
<script>
(function(win,el){
var cvs=document.querySelector(el),
ctx=cvs.getContext("2d"),
width,
height,
mouse={},
scale=1,
min_scale=1,
max_scale=2.5,
isMouseDown=false,
radius=50,
circlesNum=10,
circles=[]; Function.prototype.method=function(k,v){
return this.prototype[k]=v,this;
}; function Circle(x,y,center,radius){
this.x=x;
this.y=y;
this.curX=x;
this.curY=y;
this.center=center;
this.speed=0.01+Math.random()*0.04;
this.angle=0;
this.color="hsl("+Math.random()*360+",100%,50%)";
this.lineWidth=1;
this.targetWidth=5;
this.radius=radius;
} Circle.method("draw",function(ctx,zoom){
var x=this.x,y=this.y;
this.angle+=this.speed; this.curX+=(this.center.x-this.curX)*this.speed;
this.curY+=(this.center.y-this.curY)*this.speed; this.x=this.curX+Math.cos(this.angle)*this.radius*zoom;
this.y=this.curY+Math.sin(this.angle)*this.radius*zoom;
this.lineWidth+=(this.targetWidth-this.lineWidth)*0.05; if(Math.abs(this.targetWidth-this.lineWidth)<0.5)
{
this.targetWidth=1+Math.random()*6;
} ctx.strokeStyle=this.color;
ctx.lineWidth=this.lineWidth; ctx.beginPath();
ctx.moveTo(x,y)
ctx.lineTo(this.x,this.y); ctx.stroke(); }); function init(){
var bound=cvs.getBoundingClientRect(),i=circlesNum,segment=i*10;
cvs.width=width=bound.width;
cvs.height=height=bound.height; ctx.fillStyle="rgba(0,0,0,.05)";
ctx.lineCap="round"; mouse.x=width/2;
mouse.y=height/2; while(i--)
circles[i]=new Circle(0,0,mouse,radius+Math.random()*segment); cvs.addEventListener("mousemove",function(e){
mouse.x=e.clientX;
mouse.y=e.clientY;
},false); cvs.addEventListener("mousedown",function(){
isMouseDown=true;
},false); cvs.addEventListener("mouseup",function(){
isMouseDown=false;
},false);
cvs.addEventListener("mouseout",function(){
isMouseDown=false;
},false); render();
} function render(){
var i=circlesNum;
scale+=isMouseDown?(max_scale-scale)*0.05:(min_scale-scale)*0.05;
ctx.fillRect(0,0,width,height); while(i--)
circles[i].draw(ctx,scale); requestAnimationFrame(render); } init(); })(this,".stage");
</script>
</body>
</html>

非常不错的canvas效果,线随心动的更多相关文章

  1. 一个不错的loading效果--IT蓝豹

    一个不错的loading效果 介绍:一个不错的loading加载效果,弹性收缩,效果不错,学习android动画的朋友可以下载来研究研究本例子其实由SeekBar实现,由MetaballView,Me ...

  2. 非常不错的KPTimePicker效果源码

    非常不错的KPTimePicker效果源码,实现特殊设计的时间选择器.用户选择时间是通过滑动一个圆环,并且屏幕的颜色会随着时间点的推移变暗或者变亮,喜欢的朋友可以下载研究一下吧. 源码大家可以到源码天 ...

  3. 兼容IE浏览器的canvas画线和圆圈

    1.新建test.html文件,代码如下: <!DOCTYPE html><html><head>    <meta charset="utf-8& ...

  4. 那些不错的 [ Html5 + CSS3 + Canvas ] 效果!

    apng制作工具:http://isparta.github.io/how.html apng制作文章:http://isux.tencent.com/introduction-of-apng.htm ...

  5. canvas 画线

    一.canvas是基于状态的绘图环境 1.canvas是基于状态的绘制 context.moveTo(100,100); context.lineTo(700,700); context.lineWi ...

  6. 知乎背景图 canvas 效果

    思路分析: 1.创造一块画布, 2.在画布内随机产生一些小球,小球位置,半径,颜射,大小,速度等都可以随机产生, 3.定义画小球函数与小球移动函数, 4.将每一个小球圆心都与其它小球链接, 5判断每一 ...

  7. 自定义控件详解(三):Canvas效果变换

    Canvas 画布 从前面我们已经知道了 Canvas 类可以绘出 各种形状. 这里学习一下Canvas 类的变换效果(平移,旋转等) 首先需要了解一下Canvas 画布, 我们用Canvas.Dra ...

  8. canvas绘制线和矩形

    ###canvas绘制矩形 HTML中的元素canvas只支持一种原生的图形绘制:矩形.所有其他的图形的绘制都至少需要生成一条路径 1.绘制矩形 canvas提供了三种方法绘制矩形: ----> ...

  9. canvas连线特效

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. 伸缩--也可用于tabs

    var $ranklist_li = $("div.ranklist_model ul li"); $ranklist_li.hover(function () { $(this) ...

  2. CodeForces 550E Brackets in Implications(构造)

    [题目链接]:click here~~ [题目大意]给定一个逻辑运算符号a->b:当前仅当a为1b为0值为0,其余为1,构造括号.改变运算优先级使得最后结果为0 [解题思路]: todo~~ / ...

  3. 理解ThreadLocal类

    1 ThreadLocal是什么 早在JDK 1.2的版本号中就提供java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路. 使用这个工具类能够 ...

  4. linux中的硬连接和软连接

    linux中的硬连接和软连接 linux中的硬连接和软连接 背景 连接 硬连接 软连接 example reference 背景 linux中的文件主要分3块, - 真正的数据 - 索引节点号(ino ...

  5. netsh http的使用

    1.首先通过cmd进入 C:\Windows\System32\inetsrv>netshnetsh>http netsh http> 退出的时候,使用exit命令 2.显示监听的i ...

  6. pythong中的全局变量的调用和嵌套函数中变量的使用

    全局变量调用:想要在自定义的函数中使用全局变量,就得要在函数用关键字global声明,然后就可以对全局变量进行修改.嵌套函数中的变量的调用:要在嵌套的变量中,使用nonlocal的声明'''num = ...

  7. Swift学习笔记(3)--基本运算符

    基本运行符: +(加法.正数) - (减法.负数) *  (乘法) / (除法) % (求余)  : 在Swift中,求余可以是浮点数求余. &&(逻辑与) || (逻辑或) ^ (逻 ...

  8. IDEA 开发工具在POM.XML文件中增加依赖

    在POM.XML 中使用快捷键 ALT+INSERT 选择第一个,输入关键字即可 选择版本,确认,ok

  9. 【Codeforces Round #459 (Div. 2) B】 Radio Station

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map模拟一下映射就好了. [代码] #include <bits/stdc++.h> using namespace ...

  10. openssl之EVP系列之5---EVP_Encrypt系列函数具体解释(二)

    openssl之EVP系列之5---EVP_Encrypt系列函数详细解释(二)    ---依据openssl doc/crypto/EVP_EncryptInit.pod和doc/ssleay.t ...