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 ...
随机推荐
- 一些有用的huginn Agent
具体API地址 https://huginnio.herokuapp.com/agents 貌似这些Agent都可以按照频率和定时的时间点来触发, 1.Attribute Difference Age ...
- 2018.我的NOIP补全计划
code: efzoi.tk @ shleodai noip2011 D1 选择客栈 这道题是一道大水题,冷静分析一会就会发现我们需要维护最后一个不合法点和前缀和. 维护最后一个不合法点只要边扫描边维 ...
- python飞机大战代码
import pygame from pygame.locals import * from pygame.sprite import Sprite import random import time ...
- __x__(31)0908第五天__导航条的练习 <ul> 版本
效果图: html代码: <!doctype html> <html> <head> <meta charset="utf-8" /&g ...
- mobile_像素
document.documentElement.clientWidth 不包含滚动条 window.innerWidth ...
- linux locate命令
1.命令简介 locate(locate) 命令用来查找文件或目录. locate命令要比find -name快得多,原因在于它不搜索具体目录,而是搜索一个数据库/var/lib/ml ...
- iview menu组件手动收起与展开
本文主要介绍menu组件在有子菜单时如何手动的展开与收起. 展开: 在需要展开的地方先设置openname变量如this.openname = ["设置"]; 再在$nextTic ...
- Java常用类库 读书笔记 二
1.Date类 常用操作方法: public Date () 构造方法,实例化Date类对象 public Data(long Date) ...
- HttpClient参观记:.net core 2.2 对HttpClient到底做了什么?
.net core 于 10月17日发布了 ASP.NET Core 2.2.0 -preview3,在这个版本中,我看到了一个很让我惊喜的新特性:HTTP Client Performance Im ...
- PAT甲级1034 Head of a Gang【bfs】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805456881434624 题意: 给定n条记录(注意不是n个人的 ...