canvas-star3_html/css_WEB-ITnose

    添加天空渐变        The current browser does not support Canvas, can replace the browser a try!            window.onload = function(){            var canvas = document.getElementById('canvas');            canvas.width = 1200;            canvas.height = 800;            if(canvas.getContext('2d')){                var context = canvas.getContext('2d');                // context.fillStyle = "#000";                var skyStyle = context.createLinearGradient(0,0,0,canvas.height);                skyStyle.addColorStop(0.0,'black');                skyStyle.addColorStop(1.0,'#035');                context.fillStyle = skyStyle;                                context.fillRect(0,0,canvas.width,canvas.height)                for(var i=0;i<200;i++){                    var r = Math.random() * 5 + 5;                    var x = Math.random() * canvas.width;                    var y = Math.random() * canvas.height * 0.65;                    var a = Math.random() * 360;                    drawStar(context , x , y , r , a )                }            }else{                alert('当前游览器不支持Canvas,请更换游览器后再试!');            }        }        function drawStar(cxt,x,y,R,rot){            cxt.save();                cxt.translate(x,y);                cxt.rotate(rot/180*Math.PI);                cxt.scale(0.05*R,0.05*R)                starPath(cxt);                cxt.fillStyle = "#fb3";                cxt.strokeStyle = "#fd5";                cxt.lineWidth = 3;                cxt.lineJoin = "round";                cxt.fill();                cxt.stroke();            cxt.restore()        }            function starPath(cxt){                    cxt.beginPath();            for(var i=0;i<5;i++){                cxt.lineTo(Math.cos( (18+i*72) / 180 * Math.PI )*20,                                -Math.sin( (18+i*72) / 180 * Math.PI )*20);                cxt.lineTo(Math.cos( (54+i*72) / 180 * Math.PI )*0.5*20,                                -Math.sin( (54+i*72) / 180 * Math.PI )*0.5*20);            }            cxt.closePath();        }        /*图形变换        位移 translate(x,y)        旋转 rotate(deg)        缩放 scale(sx,sy)    */

登录后复制

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/3107765.html

(0)
上一篇 2025年3月29日 09:48:33
下一篇 2025年3月29日 09:48:37

AD推荐 黄金广告位招租... 更多推荐

发表回复

登录后才能评论