画布的使用

body:

 <canvas width="1200"height="900" ; style="border: 1px solid black" id="can">
        111
    </canvas>

js:

 var canvas = document.querySelector("#can");
    var context = canvas.getContext("2d");

	//画一个坐标轴
    function draw(a,b,c,d) {
        if (!canvas.getContext){
            return
        }
        var minhei = a;
        var maxhei = b;
        var minwid = c;
        var maxwid = d;
        var lon = (a-b) / 30;
        context.lineWidth = "5";
        context.strokeStyle = "pink";
        context.fillStyle = "yellow";
        context.moveTo(minwid,minhei);
        context.lineTo(minwid,maxhei);

        context.moveTo(minwid,minhei);
        context.lineTo(maxwid,minhei);

        context.moveTo(minwid-lon,maxhei+lon);
        context.lineTo(minwid,maxhei);
        //
        context.moveTo(minwid+lon,maxhei+lon);
        context.lineTo(minwid,maxhei);

        context.moveTo(maxwid-lon,minhei+lon);
        context.lineTo(maxwid,minhei);

        context.moveTo(maxwid-lon,minhei-lon);
        context.lineTo(maxwid,minhei);
        // /*stroke()描边 不会自动闭合
        // * fill()填充  自动闭合
        // * closePath()   自动闭合
        // * */
        context.stroke();
    }
        draw(500,100,100,500);

	 //
	 function drwaRect() {
        context.fillStyle = "blue";
        //context.strokeRect(100,200,300,400);
        //图案填充
        context.fillRect(10,10,30,100);
        //清除一部分的填充
        context.clearRect(5,5,20,50)
    }
    drwaRect();

	function Color(){
        var r = Math.floor(Math.random()*255);
        var g = Math.floor(Math.random()*255);
        var b = Math.floor(Math.random()*255);
        var col = 'rgba('+ r +','+ g +','+ b +',0.8)';
        return col;
    }
    //生成7x7个随机颜色的方块
	 function drawColor() {
        for (var i = 0 ; i < 7 ; i++){
            for (var j = 0 ; j < 7 ; j++){
                var x = i * 60;
                var y = j * 60;
                var len = 50;
                context.fillStyle = Color();
                context.fillRect(x,y,len,len);
                console.log(Color())
            } }}
   // drawColor();

     //插入文字
     function drawFont() {
        context.font = "30px pink kaiti";
        context.strokeText("hello kugou",800,800);
        context.strokeStyle = "red";
        context.moveTo(0,800);
        context.lineTo(1000,800);
        context.stroke();
        context.textBaseline = "middle"
    }
   // drawFont();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值