【成图】
【代码】
<!DOCTYPE html>
<html lang="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<head>
<title>比特币Draft1</title>
<style type="text/css">
.centerlize{
margin:0 auto;
width:1200px;
}
</style>
</head>
<body οnlοad="init();">
<div class="centerlize">
<canvas id="myCanvas" width="12px" height="12px" style="border:1px dotted black;">
如果看到这段文字说您的浏览器尚不支持HTML5 Canvas,请更换浏览器再试.
</canvas>
</div>
</body>
</html>
<script type="text/javascript">
<!--
/*****************************************************************
* 将全体代码(从<!DOCTYPE到script>)拷贝下来,粘贴到文本编辑器中,
* 另存为.html文件,再用chrome浏览器打开,就能看到实现效果。
******************************************************************/
// canvas的绘图环境
var ctx;
// 高宽
const WIDTH=512;
const HEIGHT=512;
// 舞台对象
var stage;
//-------------------------------
// 初始化
//-------------------------------
function init(){
// 获得canvas对象
var canvas=document.getElementById('myCanvas');
canvas.width=WIDTH;
canvas.height=HEIGHT;
// 初始化canvas的绘图环境
ctx=canvas.getContext('2d');
ctx.translate(WIDTH/2,HEIGHT/2);// 原点平移
// 准备
stage=new Stage();
stage.init();
// 开幕
animate();
}
// 播放动画
function animate(){
stage.update();
stage.paintBg(ctx);
stage.paintFg(ctx);
// 循环
if(true){
//sleep(100);
window.requestAnimationFrame(animate);
}
}
// 舞台类
function Stage(){
// 初始化
this.init=function(){
}
// 更新
this.update=function(){
}
// 画背景
this.paintBg=function(ctx){
ctx.clearRect(-WIDTH/2,-HEIGHT/2,WIDTH,HEIGHT);// 清屏
}
// 画前景
this.paintFg=function(ctx){
// 底色
ctx.save();
ctx.fillStyle = "white";
ctx.fillRect(-WIDTH/2,-HEIGHT/2,WIDTH,HEIGHT);
ctx.restore();
const R=210;// 基准尺寸
//最外圈
ctx.save();
var r=R*1.00;
var gnt1=ctx.createLinearGradient(-r,-r,r,r);
gnt1.addColorStop(0,"rgb(185,140,47)");
gnt1.addColorStop(0.125,"rgb(231,197,107)");
gnt1.addColorStop(0.25,"rgb(252,252,200)");
gnt1.addColorStop(0.5,"rgb(238,208,120)");
gnt1.addColorStop(0.75,"rgb(230,191,100)");
gnt1.addColorStop(1,"rgb(170,116,20)");
drawSolidCircle(ctx,0,0,r,gnt1);
ctx.restore();
//#2圈
ctx.save();
var r=R*0.97;
var gnt1=ctx.createLinearGradient(-r,-r,r,r);
gnt1.addColorStop(0,"rgb(255,245,191)");
gnt1.addColorStop(0.125,"rgb(181,123,26)");
gnt1.addColorStop(0.25,"rgb(250,244,186)");
gnt1.addColorStop(0.375,"rgb(253,255,216)");
gnt1.addColorStop(0.5,"rgb(236,195,116)");
gnt1.addColorStop(0.75,"rgb(176,124,25)");
gnt1.addColorStop(1,"rgb(255,255,112)");
drawSolidCircle(ctx,0,0,r,gnt1);
ctx.restore();
//#3圈
ctx.save();
var r=R*0.95;
drawSolidCircle(ctx,0,0,r,"rgb(20,23,28)");
ctx.restore();
//#4圈
ctx.save();
var r=R*0.88;
var gnt1=ctx.createLinearGradient(-r,-r,r,r);
gnt1.addColorStop(0,"rgb(28,33,39)");
gnt1.addColorStop(0.35,"rgb(49,59,69)");
gnt1.addColorStop(0.5,"rgb(26,31,37)");
gnt1.addColorStop(0.65,"rgb(63,63,73)");
gnt1.addColorStop(1,"rgb(22,25,30)");
drawSolidCircle(ctx,0,0,r,gnt1);
ctx.restore();
//#5圈
ctx.save();
var r=R*0.65;
var gnt1=ctx.createLinearGradient(-r,-r,r,r);
gnt1.addColorStop(0,"rgb(249,250,206)");
gnt1.addColorStop(0.35,"rgb(177,122,19)");
gnt1.addColorStop(0.5,"rgb(250,218,133)");
gnt1.addColorStop(0.65,"rgb(180,117,22)");
gnt1.addColorStop(1,"rgb(226,195,102)");
drawSolidCircle(ctx,0,0,r,gnt1);
ctx.restore();
//#6圈
ctx.save();
var r=R*0.64;
var gnt1=ctx.createLinearGradient(-r,-r,r,r);
gnt1.addColorStop(0,"rgb(205,153,52)");
gnt1.addColorStop(0.25,"rgb(253,253,215)");
gnt1.addColorStop(0.5,"rgb(215,160,43)");
gnt1.addColorStop(0.75,"rgb(200,151,58)");
gnt1.addColorStop(1,"rgb(176,118,21)");
drawSolidCircle(ctx,0,0,r,gnt1);
ctx.restore();
// 两竖杠
ctx.save();
var r=R*0.50;
ctx.strokeStyle="gold";
ctx.fillStyle="rgb(53,63,73)";
drawRoundRect(ctx,-r/5,-r/1.2,r/10,r/4,r/20);// 左上
ctx.fill();
ctx.stroke();
ctx.strokeStyle="gold";
ctx.fillStyle="rgb(53,63,73)";
drawRoundRect(ctx,r/5,-r/1.2,r/10,r/4,r/20);// 右上
ctx.fill();
ctx.stroke();
ctx.strokeStyle="gold";
ctx.fillStyle="rgb(53,63,73)";
drawRoundRect(ctx,-r/5,r/1.2,r/10,r/4,r/20);// 左下
ctx.fill();
ctx.stroke();
ctx.strokeStyle="gold";
ctx.fillStyle="rgb(53,63,73)";
drawRoundRect(ctx,r/5,r/1.2,r/10,r/4,r/20);// 右下
ctx.fill();
ctx.stroke();
ctx.restore();
// B文字
ctx.save();
var r=R*0.50;
var x=r/15,y=r/5;
var word="B";
ctx.textBaseline="middle";
ctx.textAlign="center";
ctx.font = r*2.5+"px consolas";
ctx.fillStyle="rgb(53,63,73)";
ctx.fillText(word,x,y);
ctx.lineWidth=2;
ctx.strokeStyle="gold";
ctx.strokeText(word,x,y);
ctx.restore();
// 覆盖
ctx.save();
// 左上覆盖
ctx.fillStyle="rgb(53,63,73)";
drawRoundRect(ctx,-r/5,-r/1.3,r/11,r/6,r/20);// 左
ctx.fill();
// 左上覆盖
ctx.fillStyle="rgb(53,63,73)";
drawRoundRect(ctx,r/5,-r/1.3,r/11,r/6,r/20);// 右上
ctx.fill();
// 左下覆盖
ctx.fillStyle="rgb(53,63,73)";
drawRoundRect(ctx,-r/5,r/1.3,r/11,r/6,r/20);// 左下
ctx.fill();
// 右下覆盖
ctx.fillStyle="rgb(53,63,73)";
drawRoundRect(ctx,r/5,r/1.3,r/11,r/6,r/20);// 右下
ctx.fill();
ctx.restore();
writeText(ctx,WIDTH/2-30,HEIGHT/2-5,"逆火制图","8px consolas","lightgrey");// 版权
}
}
/*----------------------------------------------------------
函数:用于绘制圆角矩形
ctx:绘图上下文
x:矩形中心横坐标
y:矩形中心纵坐标
width:矩形宽
height:矩形高
radius:圆角半径
----------------------------------------------------------*/
function drawRoundRect(ctx,x,y,width,height,radius){
ctx.beginPath();
ctx.moveTo(x-width/2+radius,y-height/2);
ctx.lineTo(x+width/2-radius,y-height/2);
ctx.arcTo(x+width/2,y-height/2,x+width/2,y-height/2+radius,radius);
ctx.lineTo(x+width/2,y-height/2+radius);
ctx.lineTo(x+width/2,y+height/2-radius);
ctx.arcTo(x+width/2,y+height/2,x+width/2-radius,y+height/2,radius);
ctx.lineTo(x+width/2-radius,y+height/2);
ctx.lineTo(x-width/2+radius,y+height/2);
ctx.arcTo(x-width/2,y+height/2,x-width/2,y+height/2-radius,radius);
ctx.lineTo(x-width/2,y+height/2-radius);
ctx.lineTo(x-width/2,y-height/2+radius);
ctx.arcTo(x-width/2,y-height/2,x-width/2+radius,y-height/2,radius);
ctx.closePath();
}
/*----------------------------------------------------------
函数:用于绘制实心圆
ctx:绘图上下文
x:矩形中心横坐标
y:矩形中心纵坐标
r:圆半径
style:填充圆的方案
----------------------------------------------------------*/
function drawSolidCircle(ctx,x,y,r,style){
ctx.fillStyle=style;
ctx.beginPath();
ctx.arc(x,y,r,0,Math.PI*2,false);
ctx.closePath();
ctx.fill();
}
/*----------------------------------------------------------
函数:创建一个二维坐标点
x:横坐标
y:纵坐标
Pt即Point
----------------------------------------------------------*/
function createPt(x,y){
var retval={};
retval.x=x;
retval.y=y;
return retval;
}
/*----------------------------------------------------------
函数:延时若干毫秒
milliseconds:毫秒数
----------------------------------------------------------*/
function sleep(milliSeconds) {
const date = Date.now();
let currDate = null;
while (currDate - date < milliSeconds) {
currDate = Date.now();
}
}
/*----------------------------------------------------------
函数:书写文字
ctx:绘图上下文
x:横坐标
y:纵坐标
text:文字
font:字体
color:颜色
----------------------------------------------------------*/
function writeText(ctx,x,y,text,font,color){
ctx.save();
ctx.textBaseline="bottom";
ctx.textAlign="center";
ctx.font = font;
ctx.fillStyle=color;
ctx.fillText(text,x,y);
ctx.restore();
}
/*-------------------------------------------------------------
衣敝缊袍,与衣狐貉者立,而不耻者,其由也与?
--------------------------------------------------------------*/
//-->
</script>
END