html5--js函数在canvas中的应用

总结:

1、script中的函数写了要调用

2、rgb()这样的模式的色彩比较适合做变量

3、body的onload事件

html5--js函数在canvas中的应用_人工智能

 4、带参函数

html5--js函数在canvas中的应用_人工智能_02

 

 

效果:

html5--js函数在canvas中的应用_html5课程_03

 

 

代码:

 html5--js函数在canvas中的应用_人工智能_04



1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>无标题文档</title>
6 </head>
7 <body onLoad="draw()">
8 <canvas id="myCanvas" width="600px" height="300px" style="border: 1px solid #c3c3c3;">
9 <script>
10 function draw(){
11 var c=document.getElementById("myCanvas");
12 var cxt=c.getContext("2d");
13 for(var i=0;i<12;i++){
14 for(var j=0;j<24;j++){
15 cxt.fillStyle='rgb(240,'+Math.floor(255-11.5*i)+','+Math.floor(255-11.5*j)+')';
16 cxt.beginPath();
17 cxt.arc(12.5+j*25,12.5+i*25,10,0,Math.PI*2,true);
18 cxt.closePath();
19 cxt.fill();
20 }
21 }
22 }
23 // draw();
24 </script>
25 </canvas>
26 </body>
27 </html>


 


我的旨在学过的东西不再忘记(主要使用艾宾浩斯遗忘曲线算法及其它智能学习复习算法)的偏公益性质的完全免费的编程视频学习网站: ​​fanrenyi.com​​;有各种前端、后端、算法、大数据、人工智能等课程。

​版权申明:欢迎转载,但请注明出处​

一些博文中有一些参考内容因时间久远找不到来源了没有注明,如果侵权请联系我删除。