Canvas Demo
<!DOCTYPE html>
<html>
<head>
<title>ゆき</title>
</head>
<style type="text/css" media="screen">
* {
padding: 0px;
border: 0px;
margin: 0px;
}
#c {
background-color: black;
}
</style>
<body>
<canvas id="c"></canvas>
</body>
<script type="text/javascript">
var c = document.getElementById("c"),
ctx = c.getContext("2d");
var width = c.width = innerWidth;
var height = c.height = innerHeight;
var store = [];
var lin = 0;
for (var i = 0; i < height; i++) {
store.push({
x: Math.floor(Math.random() * width),
y: lin
});
lin++;
}
function draw() {
ctx.clearRect(0, 0, c.width, c.height);
for (var i = 0; i < height; i++) {
ctx.beginPath();
ctx.fillRect(store[i].x, store[i].y, 1, 1);
ctx.fillStyle = "#ffffff";
ctx.stroke();
store[i].y += 1;
if (store[i].y > c.height)
store[i].y = 0;
if (Math.floor(Math.random() > 0.5)) {
store[i].x += Math.random() * 0.5;
} else {
store[i].x -= Math.random() * 0.5;
}
}
window.requestAnimationFrame(draw);
}
draw();
</script>
</html>
<!DOCTYPE html>
<html>
<head>
<title>このひかり</title>
</head>
<body>
<canvas id="c"></canvas>
</body>
<script type="text/javascript">
var c = document.getElementById("c"),
ctx = c.getContext("2d");
c.width = innerWidth;
c.height = innerHeight;
var name =['J','o','k','i','n','g']
var lines = [],
maxSpeed = 5,
spacing = 5,
xSpacing = 0,
n = innerWidth / spacing,
colors = ["#3B8686", "#79BD9A", "#A8DBA8", "#0B486B"];
for (i = 0; i < n; i++){
xSpacing += spacing;
lines.push({
x: xSpacing,
y: Math.round(Math.random()*c.height),
width: 7,
height: Math.round(Math.random()*(innerHeight/10)),
speed: Math.random()*maxSpeed + 1,
color: colors[Math.floor(Math.random() * colors.length)]
});
}
function draw(){
var i;
ctx.clearRect(0,0,c.width,c.height);
for (i = 0; i < n; i++){
ctx.fillStyle = lines[i].color;
ctx.font="20px Georgia";
lines[i].y += lines[i].speed;
test(i);
ctx.textAlign="center";
if (lines[i].y > c.height)
lines[i].y = 0 - lines[i].height;
}
requestAnimationFrame(draw);
}
var test = (i)=>{
ctx.fillText(name[Math.floor(Math.random() * name.length)],lines[i].x, lines[i].y);
}
draw();
</script>
</html>
Canvas Demo的更多相关文章
- canvas写的一个小时钟demo
<!DOCTYPE html> <html> <head> <title>HTML5 Canvas Demo of clock</title> ...
- 在canvas中使用html元素
让div悬浮于canvas之上 使用z-index控制层及顺序 慕课网canvas demo <div id="canvas-wrapper"> <canva ...
- canvas案例——画时钟
基本思路,先画一个200半径的圆 ctx.arc(250,250,200,0,2*Math.PI); 然后再画时分刻度,可以先利用translate变化坐标到圆的中心点,然后再通过rotate旋转 / ...
- HTML5 之Canvas绘制太阳系
<!DOCTYPE html> <html> <head> <title>HTML5_Canvas_SolarSystem</title> ...
- html5——canvas画直线
<html> <head> <title>canvas demo</title> </head> <body> <canv ...
- HTML5 Canvas绘文本动画(使用CSS自定义字体)
一.HTML代码: <!DOCTYPE html> <html> <head> <title>Matrix Text - HTML5 Canvas De ...
- 使用 HTML5 canvas 绘制精美的图形
HTML5 是一个新兴标准,它正在以越来越快的速度替代久经考验的 HTML4.HTML5 是一个 W3C “工作草案” — 意味着它仍然处于开发阶段 — 它包含丰富的元素和属性,它们都支持现行的 HT ...
- HTML5 canvas 绘制精美的图形
HTML5 是一个新兴标准,它正在以越来越快的速度替代久经考验的 HTML4.HTML5 是一个 W3C “工作草案” — 意味着它仍然处于开发阶段 — 它包含丰富的元素和属性,它们都支持现行的 HT ...
- 【python基础】 Tkinter小构件之canvas 画布
[python之tkinter画布] 要画布就要使用tkinter的小构件,canvas(结构化的图形,用于绘制图形,创建图形编辑器以及实现自定制的小构件类) 我们先使用create_rectangl ...
随机推荐
- hdu4791-Alice's Print Service
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 题目解释:给你一组数据s1,p1,s2,p2...sn,pn,一个数字q,问你当要打印q张资料时 ...
- web服务-2、四种方法实现并发服务器-多线程,多进程,协程,(单进程-单线程-非堵塞)
知识点:1.使用多线程,多进程,协程完成web并发服务器 2.单进程-单线程-非堵塞也可以实现并发服务器 1.多进程和协程的代码在下面注释掉的部分,我把三种写在一起了 import socket im ...
- 网页布局之grid
学习网格布局时,你可能会在网络上看到很多文章,内容不同,属性不同,真是让人摸不着头脑,到底哪个才是正确的?看了本篇文章,我想你会豁然开朗.比如,一会儿用grid-rows,一会儿用grid-defin ...
- ant design select placeholder不生效原因
当select的value绑定一个state默认值时,如果默认值是''或null时,placeholder不生效 解决方案:默认值设为undefined
- 高性能平滑动画_requestAnimationFrame
高性能平滑动画_requestAnimationFrame 在下一次重绘之前,执行一个函数
- Jmeter .jmx 改为.jtl
1.cd $jmeter\bin 2. jmeter -n -t $jmeter\extras\**.jmx -l $jmeter\extras\**.jtl 3.cd $jmeter\extras ...
- git-format-patch
使用方法: git diff ${old-commit} ${new-commit} > commit-operation.patch OR git format- b1af44f > c ...
- 一般处理程序(ashx)的使用
ASP.NET 中发送请求的页面代码如下: <head runat="server"> <title></title> <script s ...
- atom编辑器安装插件报错。。
Checking for native build tools failed gyp info it worked if it ends with ok gyp info using node-gyp ...
- char
1 char是多少位的 2 java用的是什么方式表示字符 3 Unicode是用多少位表示的 1的答案是16位的,2的答案是Unicode,3的答案是16位 值得注意的是,2的答案并不是utf-8 ...