非常不错的canvas效果,线随心动
非常不错的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效果,线随心动的更多相关文章
- 一个不错的loading效果--IT蓝豹
一个不错的loading效果 介绍:一个不错的loading加载效果,弹性收缩,效果不错,学习android动画的朋友可以下载来研究研究本例子其实由SeekBar实现,由MetaballView,Me ...
- 非常不错的KPTimePicker效果源码
非常不错的KPTimePicker效果源码,实现特殊设计的时间选择器.用户选择时间是通过滑动一个圆环,并且屏幕的颜色会随着时间点的推移变暗或者变亮,喜欢的朋友可以下载研究一下吧. 源码大家可以到源码天 ...
- 兼容IE浏览器的canvas画线和圆圈
1.新建test.html文件,代码如下: <!DOCTYPE html><html><head> <meta charset="utf-8& ...
- 那些不错的 [ Html5 + CSS3 + Canvas ] 效果!
apng制作工具:http://isparta.github.io/how.html apng制作文章:http://isux.tencent.com/introduction-of-apng.htm ...
- canvas 画线
一.canvas是基于状态的绘图环境 1.canvas是基于状态的绘制 context.moveTo(100,100); context.lineTo(700,700); context.lineWi ...
- 知乎背景图 canvas 效果
思路分析: 1.创造一块画布, 2.在画布内随机产生一些小球,小球位置,半径,颜射,大小,速度等都可以随机产生, 3.定义画小球函数与小球移动函数, 4.将每一个小球圆心都与其它小球链接, 5判断每一 ...
- 自定义控件详解(三):Canvas效果变换
Canvas 画布 从前面我们已经知道了 Canvas 类可以绘出 各种形状. 这里学习一下Canvas 类的变换效果(平移,旋转等) 首先需要了解一下Canvas 画布, 我们用Canvas.Dra ...
- canvas绘制线和矩形
###canvas绘制矩形 HTML中的元素canvas只支持一种原生的图形绘制:矩形.所有其他的图形的绘制都至少需要生成一条路径 1.绘制矩形 canvas提供了三种方法绘制矩形: ----> ...
- canvas连线特效
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- cocos2d-x 显示触摸操作(显示水波点击效果,用于视频演示)
昨天刚刚參加玩游戏设计大赛, 积累了一些东西. 接下去将会逐个分享出来. 首先是显示触摸操作. 由于要演示我们的作品.使用试玩过程中, 假设没办法显示我们的触摸操作(像录制视频一样, 点击了屏幕某点, ...
- iOS 卖票中多线程分析;
注意:(主要一个加锁机制)
- 菜鸟之webservice(一) 服务端搭建
首先说一下,为什么取名叫菜鸟之webservice,由于本人技术真的不咋滴,写博客仅仅是为了对所学知识的总结.webservice对于我来说一直都是高大上的感觉,一个java web和javase都没 ...
- Anatomy of an IIS7 configuration path
The concept of configuration paths is fundamental to managing and operating an IIS server, so I want ...
- javascript对象如何使用
javascript对象如何使用 一.总结 一句话总结:JavaScript 中的所有事物都是对象:字符串.数值.数组.函数... 因为函数是对象,所以自定义对象的创建中有种方法就是函数 1.js中的 ...
- 洛谷P3355 骑士共存问题
题目描述 在一个 n*n个方格的国际象棋棋盘上,马(骑士)可以攻击的棋盘方格如图所示.棋盘上某些方格设置了障碍,骑士不得进入 对于给定的 n*n 个方格的国际象棋棋盘和障碍标志,计算棋盘上最多可以放置 ...
- react-native-swiper苹果正常显示,Android不显示
在使用react-native-swiper时,最好不要放到(FlatList , SectionList,ListView,ScrollView 等)组件中,否则Android 可能不会正常显示图片 ...
- 几种类型的db,以及最新的db排名,看一下
5月数据库排名: http://geek.csdn.net/news/detail/196118 另外这篇文章里面提到了一些内嵌式数据库: http://blog.csdn.net/leagoal/a ...
- 关于bootstrap IE8的兼容性问题
非常久没有写技术类的文章了.这几天在用bootstrap来做我们站点的UI框架,感觉还是不错的.只是遇到一点不大不小的问题,那就是有朋友在IE8下訪问我们的站点.界面变成了跟手机浏览一样的界面. 后来 ...
- elasticsearch index 之merge
merge是lucene的底层机制,merge过程会将index中的segment进行合并,生成更大的segment,提高搜索效率.segment是lucene索引的一种存储结构,每个segment都 ...