JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

var PI2 = Math.PI * 2,

// canvas vars

canvasWidth = 500,

canvasHeight = 500,

canvas = document.querySelector('.js-canvas'),

ctx = canvas.getContext('2d'),

// vars for the circles

circles = [],

circleDiameter = 40,

circleRadius = circleDiameter * 0.5,

circleSpacing = 5,

rotateSpeed = 0.06,

showCircles = false,

showDebugColors = false,

// calculate rows & cols

numCols = Math.round(canvasWidth / (circleRadius + circleSpacing)),

numRows = Math.round(canvasHeight / (circleRadius + circleSpacing)),

// vars for test colors

count = numRows * 2,

colors = [];

// set canvas size

canvas.setAttribute('width', canvasWidth);

canvas.setAttribute('height', canvasHeight);

// set debug colors

while (count--) {

colors.push('#' + ((1 << 24) * Math.random() | 0).toString(16));

}

// agile event binding...

document.querySelector('.js-show-cirlces').addEventListener('change', function(e) {

showCircles = e.target.checked;

});

document.querySelector('.js-show-colors').addEventListener('change', function(e) {

showDebugColors = e.target.checked;

});

function Circle(x, y, radius, angle, color) {

this.x = x;

this.y = y;

this.radius = radius;

this.angle = angle;

this.color = color;

}

Circle.prototype = {

update: function() {

// speed of the rotation

this.angle += rotateSpeed;

},

draw: function(ctx) {

// draw circle

if (showCircles) {

ctx.beginPath();

ctx.strokeStyle = showDebugColors ? this.color : '#acacac';

ctx.lineWidth = 1;

ctx.arc(this.x, this.y, this.radius, 0, PI2);

ctx.stroke();

ctx.closePath();

}

// draw dot

ctx.beginPath();

ctx.fillStyle = '#ffffff';

ctx.arc(this.x + Math.cos(this.angle) * this.radius, this.y + Math.sin(this.angle) * this.radius, 3, 0, PI2);

ctx.fill();

ctx.closePath();

}

};

createCircles();

run();

function createCircles() {

var x = 0,

y = 0,

angle = 0,

diagonal = 0,

totalCircles = numCols * numRows,

circle,

i, q;

// loop over rows

for (q = 0; q < numRows; q++) {

// add columns on each row

for (i = 0; i < numCols; i++) {

// get starting angle for the dot

angle = getAngle(diagonal);

circle = new Circle(x, y, circleRadius, angle, colors[diagonal]);

circle.draw(ctx);

circles.push(circle);

// update diagonal

diagonal = q + i;

x += circleRadius + circleSpacing;

}

x = 0;

y += circleRadius + circleSpacing;

}

}

function run() {

window.requestAnimationFrame(run);

var i = circles.length,

circle;

// clear

ctx.fillStyle = 'rgba(0, 0, 0, 1)';

ctx.fillRect(0, 0, canvasWidth, canvasHeight);

// loop over all circles and update and draw them

while (i--) {

circle = circles[i];

circle.update();

circle.draw(ctx);

}

}

function getAngle(diagonal) {

return PI2 * (diagonal / numRows);

}

html5时间点阵代码,HTML5 Canvas 波动的点阵相关推荐

  1. html5页面弹幕代码,html5新年许愿文字弹幕代码

    特效描述:html5 新年许愿 文字弹幕代码.html5文字弹幕 代码结构 1. 引入CSS 2. 引入JS 3. HTML代码 HTML5手机视频弹幕文字评论代码 #audio_btn{ posit ...

  2. html5纪念日期代码,HTML5适合的情人节礼物有纪念日期功能

    前言 利用HTML5,css,js实现爱心树 以及 纪念日期的功能 网页有播放音乐功能 以及打字倾诉感情的画面,非常适合情人节送给女朋友 具体的HTML代码 具体只要修改代码里面的男某某和女某某 文字 ...

  3. html5语音闹钟代码,HTML5数字时钟之闹钟

    想要在数字时钟时钟上扩展闹钟效果,需要做的有1.要有一个可以编辑设置闹钟响铃时间的界面:2.每秒钟侦听是否到了响铃时间,如果到了响铃时间则弹出提醒并播放响铃音频. HTML 我们使用上篇文章使用jQu ...

  4. html5进度条代码,html5简单进度条效(progressbar)

    [实例简介] [实例截图] [核心代码] 一个html5实现的简单进度条效果 var i = 0; var res = 0; var context = null; var total_width = ...

  5. html5外链代码,html5关于外链嵌入页面通信问题

    这篇文章主要介绍了html5关于外链嵌入页面通信问题(postMessage解决跨域通信),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学 ...

  6. html5语音闹钟代码,HTML5+CSS3闹钟动画特效源码

    效果图 各位朋友大家好,今天给大家带来的是 <HTML5+CSS3闹钟动画特效源码> 可以添加在网站里面作为一个炫酷的小装饰 代码过长需要文档版源码来我的前端群581549454,已上传到 ...

  7. html5面板制作代码,HTML5绘制设备面板

    客户提到设备面板的需求,qunee并没有Equipment这样的图元,但借助父子关系和跟随关系设置,可以实现类似功能,并完成下面的例子 示例代码 代码非常简单,这里直接列出 var graph; fu ...

  8. HTML5隐藏图片代码,HTML5终极备忘大全(图片版+文字版)

    一.前言兼图片备忘 下图是我从testking网站上的Ultimate HTML5 Cheatsheat这篇文章中备忘图片(已大小优化,因为图片较高,故滚动显示). 但是,上面毕竟是图片格式(原图上兆 ...

  9. html5 3d全景代码,HTML5教程 三维全景详解

    本篇教程探讨了HTML5教程 三维全景详解,希望阅读本篇文章以后大家有所收获,帮助大家HTML5+CSS3从入门到精通 . < 准备: 1.一张或多张全景图片素材 2.pano2VR软件,链接: ...

  10. HTML5移动的代码,HTML5实现一个能够移动的小坦克示例代码

    复制代码代码如下: 您的浏览器不支持canvas标签 var canvas1=document.getelementbyid('tankmap'); var ctx=canvas1.getcontex ...

最新文章

  1. iis 发布MVC HTTP错误 403.14
  2. 关于方法论的对话之二敏捷与方法论
  3. SQL事务用法begin tran,commit tran和rollback tran的用法
  4. Ubuntu安装配置Python.pyDev
  5. Install Odoo 11 on CentOS 7
  6. 斑马打印机怎么打印二维码_万能打印机厂家是怎么改良打印机的?
  7. 资深架构专家讲解微服务治理的架构演进
  8. 算法题存档20190127
  9. 【OpenCV应用】python处理行李图像匹配项目——图像(简单)清晰化
  10. [msi]获取msi安装包的ProductCode
  11. php dp0,DOS批处理中%cd%与%~dp0的区别详解
  12. 三年一个人使用虚幻引擎(UDK)开发的一个游戏心路
  13. 电力线载波通信(PLC)简介
  14. 二氯甲烷废气处理吸附工艺
  15. 关于上海四金计算和工资对照表(转载)
  16. 中国人民银行计算机招聘笔试题和答案(笔试真题)
  17. 手机如何测光照度_照度测定方法
  18. 离散数学 群,环和域
  19. 两个时间序列之间的DTW(Dynamic Time Warping)距离度量
  20. Java抽象类与抽象方法

热门文章

  1. 【CSS系列】获取实时数据做进度
  2. C++版 - 剑指offer 面试题23:从上往下打印二叉树(二叉树的层次遍历BFS) 题解
  3. 项目范围管理论文提纲
  4. CSS实现限制字数功能
  5. mysqludf_json将关系数据以JSON编码
  6. 从零开始学习 ASP.NET MVC 1.0 (四) View/Model 全解 【转】
  7. 瀏覽器擴展──釋放你的個性
  8. react+antd 权限管理 Tree树形控件
  9. python爬取图片失败什么原因_请问下面这个python3.5下的爬虫程序有什么错误,为什么运行正常 但是不爬取图片?...
  10. Java Web架构实战篇:聊一聊前后端分离架构