canvas 绘制八卦图
2024-10-21 09:46:55
绘制要点:
1.getContext('2d'); -->绘图环境,2维空间
2.fillRect(x,y,w,h); -->矩形:实心(黑色背景)
3.strokeRect(x,y,w,h); -->矩形:空心(白色背景)
4.clearRect(x,y,w,h); -->矩形:在已存在的矩形中挖空一个矩形
5.ctx.fillStyle='红色'; -->给图添加颜色
代码如下:
<canvas id="cavas" width="" height="" style="border: 1px solid;"></canvas>
<!--高宽不能写在style里-->
var cas=document.querySelector('#cavas'); var ctx=cas.getContext('2d');
var n;
function rgb(){
var r=Math.floor(Math.random()*);
var g=Math.floor(Math.random()*);
var b=Math.floor(Math.random()*);
return 'rgb('+r+','+g+','+b+')';
}
setInterval(function(){ //定时器
for (var i=;i<;i++) {
for (var j=;j<;j+=) { //循环行
i%==?n=j:n=j+; //如果是偶数行,n=j,如果是奇数行,n=j+1
ctx.fillStyle=rgb(); //添加颜色
ctx.fillRect(*n,*i,,);
}
}
},);
//也可以用下面的方法
setInterval(function(){ //定时器
for (var i=0;i<8;i++) {
for (var j=0;j<8;j++) { //循环行
if (i%2==0&&j%2==0) { //偶数行
ctx.fillRect(100*i,100*j,100,100);
} else if(i%2!=0){ //奇数行
ctx.fillRect(100*i,100*(2*j+1),100,100);
}
ctx.fillStyle=rgb();
}
}
},200);
效果(代码有个定时器会不停的闪动):
最新文章
- 监控Activity的启动等状态--- 源码级
- Uva 1629 切蛋糕
- VS2010 中 Entity Framework 多数据库并存方法
- HP PCS 云监控大数据解决方案
- IOS第18天(4,核心动画,时钟效果,定时器,图片旋转角度,CALayer 锚点,获取当前,小时,秒,分)
- ORA-00265: instance recovery required, cannot set ARCHIVELOG
- 使用ApplicationLoader中出现报错:The IPA is invalid. It does not inlude a Payload directory
- URLEncode和URLDecoder作用
- verilog抓外部低频输入信号的上升沿和下降沿
- 纯手写AJAX
- configparser模块--配置文件
- 3、jeecg 笔记之 模糊查询
- 2、使用Angular-CLI初始化Angular项目(踩过的深坑!!!)
- Annotation 标注
- C#基础巩固(3)-Linq To XML 读取XML
- @Autowired与@Resource 详细诠释和区别(附带例子)
- 数据科学的完整学习路径—Python版(转载)
- UVa 10298 - Power Strings
- Spring Boot 中使用 jpa
- ftp之心脏病