Canvas实例
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
body { background: #141414; overflow: hidden; }
</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
window.onload = function (argument) {
var lyric = "i couldn't take it couldn't stand another minute couldn't bear another day without you in it all of the joy that I had known for my life was stripped away from me the minute that you died to have you in my life was all i ever wanted but now without you I'm a soul forever haunted can't help but feel that i had taken you for granted no way in hell that i can ever comprehend this i wasn't dreaming when they told me you were gone i was wide awake and feeling that they had to be wrong how could you leave me when you swore that you would stay now i'm trapped inside a nightmare every single fucking day it's like a movie but there's not a happy ending every scene fades black and there's no pretending this little fairy tale doesn't seem to end well theres no knight in shining armor who will wake me from the spell i know you didn't plan this you tried to do what's right but in the middle of this madness i'm the one you left to win this fight red like roses fills my head with dreams and finds me always closer to the emptiness and sadness that has come to take the place of you i know you're broken down by anger and by sadness you feel I left you in a world that's full of madness wish i could talk to you if only for a minute make you understand the reasons why i did it i wanna tell you that you're all that ever mattered want you to know that for eternity i'm shattered i tried so hard just to protect you but i failed to and in a prison of abandonment i've jailed you i never planned that i would leave you there alone i was sure that i would see you when i made it back home and all the times I swore that it would be okay now i'm nothing but a liar and you're thrown into the fray this bedtime story ends with misery ever after the pages are torn and there's no final chapter i didn't have a choice I did what I had to do i made a sacrifice but forced a bigger sacrifice on you i know you've lived a nightmare i caused you so much pain but baby please don't do what i did i don't want you to waste your life in vain red like roses fills my head with dreams and finds me always closer to the emptiness and sadness that has come to take the place of you you're not the only one who needed me i thought you understood you were the one i needed and you left me as I always feared you would would I change it if i could? it doesn't matter how the petals scatter now every nightmare just discloses it's your blood that's red like roses and no matter what I do nothing ever takes the place of you red like roses fills my head with dreams and finds me always closer to the emptiness and sadness that has come to take the place of you";
var words = {};
var words_attr = [];
string_handle(lyric); var canvas = document.getElementById('c');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight; if (canvas.getContext) {
var c = canvas.getContext('2d'),
w = canvas.width,
h = canvas.height; c.strokeStyle = 'red';
c.fillStyle = 'white';
c.lineWidth = 5; // constructor
Word = function (key) {
this.text = key;
this.x = Math.random() * w;
this.y = Math.random() * h;
this.font = words[key] * 10 + 'px arial'
this.speed = (words[key]);
}
for (key in words) {
words_attr.push(new Word(key));
}
console.log(words_attr.length); function animation() {
for (var i = 0; i < words_attr.length; i++) {
c.font = words_attr[i].font;
c.fillText(words_attr[i].text, words_attr[i].x, words_attr[i].y);
words_attr[i].width = c.measureText(words_attr[i].text).width;
c.stroke();
}
move();
} function move() {
for (var i = 0; i < words_attr.length; i++) {
if (words_attr[i].x > w) {
words_attr[i].x = -words_attr[i].width;
words_attr[i].y = Math.random() * h;
} else {
words_attr[i].x += words_attr[i].speed;
}
}
} setInterval(function () {
c.clearRect(0, 0, w, h);
animation();
}, 24); } function string_handle(str) {
var split_str = str.split(" ");
var word_array = [];
var word_count = [];
for (var i = 0; i < split_str.length; i++) {
check = true;
for (var j = 0; j <= word_array.length; j++) {
if (split_str[i] == word_array[j]) {
word_count[j]++;
check = false;
break;
}
}
if (check) {
word_array.push(split_str[i]);
word_count.push(1);
}
}
for (var i = 0; i < word_array.length; i++) {
words[word_array[i]] = word_count[i];
}
return words;
}
}
</script>
</body>
</html>
来源:http://codepen.io/FlyC/pen/yaNVEQ
Canvas实例的更多相关文章
- 超多经典 canvas 实例,动态离子背景、移动炫彩小球、贪吃蛇、坦克大战、是男人就下100层、心形文字等等等
超多经典 canvas 实例 普及:<canvas> 元素用于在网页上绘制图形.这是一个图形容器,您可以控制其每一像素,必须使用脚本来绘制图形. 注意:IE 8 以及更早的版本不支持 &l ...
- canvas实例 ---- 制作简易迷宫(一)
这个系列分为两部分,第一部分为迷宫的生成及操作,第二部分为自动寻路算法. 我们先看效果: See the Pen QGKBjm by fanyipin (@fanyipin) on CodePen. ...
- canvas实例:旋转缩放的方块
首先在页面中创建一个canvas标签: <body> <canvas id="c1" width="500" height="500 ...
- canvas实例_时钟
效果图:是一个会动的时钟 一.时钟的组成 1.表盘(蓝色) 2.刻度(黑色) 3.时针(黑色) 4.分针(黑色) 5.秒针(红色)需美化 二.主要应用的技术 Canvas画线 Canv ...
- canvas实例(基础)
JS实现五子棋大战:GitHub源码 知识点总结: 第一步.基础: //获取canvas var chess = document.getElementById('chess'); //获取上下文,创 ...
- canvas实例_在线画图工具
fadsfklasdjfklasjdklfjasdlk;fjasd;lfjaskl;dfjal
- Canvas 最佳实践(性能篇)
Canvas 想必前端同学们都不陌生,它是 HTML5 新增的「画布」元素,允许我们使用 JavaScript 来绘制图形.目前,所有的主流浏览器都支持 Canvas. Canvas 最常见的用途是渲 ...
- canvas API ,通俗的canvas基础知识(六)
这篇是canvas API系列的首尾之作,这篇以后,所有的canvas的属性和方法就将完了,哦,不对,应该是大部分常用的,还有部分不常用的属性和方法,因为种种原因,就不介绍了,后期的重点就是多写一点c ...
- Android核心分析之二十八Android GDI之Surface&Canvas
Surface&Canvas Canvas为在画布的意思.Android上层的作图几乎都通过Canvas实例来完成,其实Canvas更多是一种接口的包装.drawPaints ,drawPoi ...
随机推荐
- x01.Weiqi.8: 一点改进
原来的代码全部删除,进行了深层次重构,得其意而忘其言.得意之处有二: 1.关于显示 以 StoneSize 属性为依托,在 set 中加了一句:Width = Height = m_StoneSize ...
- ubuntu下怎么给普通用户赋予sudo权限
ununtu系统安装过程中,系统会提示建立一个默认用户,比如用户名为:zhuhui.这个默认用户具有一定的管理功能,即可以通过sudo命令执行root权限的操作.由于Ubuntu系统默认不允许通过ro ...
- Linux初学:(二)Shell环境与命令基础
博客园(FOREVER_ENJOY):http://www.cnblogs.com/zyx1314/ 本文版权归作者所有:欢迎转载!请注明文章作者和原文连接 Shell是什么? 1. Shell作为应 ...
- windows下OpenSSL加密证书安装步骤与使用方法
OpenSSL加密证书一般用于签名认证,含私钥和公钥.在Linux系统中,OpenSSL一般是已经安装好了,可以直接使用.而在Windows系统中,是需要安装使用的. 最近在使用支付平台时,用到了Op ...
- linux下shell脚本执行jar文件
最近在搞一个shell脚本启动jar文件个关闭jar文件的东东.搞得我都蛋疼了.今天晚上终于弄好了 话说,小弟的linux只是刚入门,经过各方查资料终于搞定了.话不多说,下面开始上小弟写的shell脚 ...
- Oracle数据库穿越防火墙访问
原因 Oracle listener 只起一个中介作用,当客户连接它时,它根据配置寻找到相应的数据库实例进程,然后spawned一个新的数据库连接,这个连接端口由listener传递给客户机,此后客户 ...
- 关于mysql数据库插入数据,不能插入中文和出现中文乱码问题
首先,推荐一篇博客:http://www.cnblogs.com/sunzn/archive/2013/03/14/2960248.html 当时,我安装完mysql数据库后,新建一个数据库后插入数据 ...
- NOIP2012同余方程[exgcd]
题目描述 求关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解. 输入输出格式 输入格式: 输入只有一行,包含两个正整数 a, b,用一个空格隔开 输出格式: 输出只有一行,包含一个正整 ...
- Win10 VC++6 无法启动此程序,因为计算机中丢失mfc42d.dll 需要提升
亲测可用 1.无法启动此程序,因为计算机中丢失mfc42d.dll 我也遇到了这个问题,并且顺利解决了!按一下流程搞定的: “工程-设置-常规-microsoft基础类,(选择使用MFC作为静态链接库 ...
- ThinkPHP常用查询
1.常规 $map2['state'] = 1; $User->where ( $map2 )->find(); 2. OR 查询 $where['name'] = array('neq' ...