html做星空网页游戏,HTML5绘制星空

HTML5绘制一个很丑的星空

canvas{display: block;border:1px dotted skyblue;}

HTML5绘制星空

var nimo={};

window.οnlοad=function(){

nimo.canvas=document.getElementById('canvas');

nimo.context=nimo.canvas.getContext('2d');

nimo.starBgImg=new Image();

nimo.starBgImg.src='//ku.shouce.ren/files/images/201601/56a097327d965.jpg';

nimo.starBgImg.οnlοad=function(){

//填充星星背景

nimo.statBg=nimo.context.createPattern(nimo.starBgImg,'repeat')

nimo.context.rect(0,0,nimo.canvas.width,nimo.canvas.height);

nimo.context.fillStyle=nimo.statBg;

nimo.context.fill();

//绘制月亮轮廓

nimo.context.beginPath();

nimo.context.arc(200,200,100,0.6*Math.PI,1.3*Math.PI);

nimo.context.bezierCurveTo(140,119,93,224,169,295)

//填充月亮轮廓和设置投影

nimo.context.shadowColor="blue";

nimo.context.shadowBlur=3;

nimo.context.strokeStyle="blue";

nimo.context.stroke();

//填充放射渐变给月亮

nimo.radialGradient=nimo.context.createRadialGradient(150,200,0,150,200,50);

nimo.radialGradient.addColorStop(0,'white')

nimo.radialGradient.addColorStop(1,'#999')

nimo.context.fillStyle=nimo.radialGradient;

nimo.context.fill()

//绘制月亮的研究和嘴巴

nimo.context.shadowColor="white";

nimo.context.beginPath();

nimo.context.moveTo(110,173);

nimo.context.lineTo(114,173);

nimo.context.moveTo(119,173);

nimo.context.lineTo(123,173);

nimo.context.stroke();

nimo.context.beginPath();

nimo.context.arc(116,183,2,0,2*Math.PI);

nimo.context.stroke();

nimo.context.shadowColor='transparent';

nimo.context.font="15px 微软雅黑"

nimo.context.fillText('月亮啊月亮,我知道你很丑,但很温柔!~!',100,100)//设置文字及在图片上的位置

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值