【成果图】

【代码】
<!DOCTYPE html>
<html lang="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<head>
<title>金色Brand Award品牌嘉奖</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>
<img id="myImg" src="120.jpg" style="display:none;"/>
</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){
window.requestAnimationFrame(animate);
}
}
// 舞台类
function Stage(){
// 初始化
this.init=function(){
}
// 更新
this.update=function(){
}
// 画背景
this.paintBg=function(ctx){
ctx.clearRect(-WIDTH/2,-HEIGHT/2,WIDTH,HEIGHT);// 清屏
// 斜45°线性渐变色
var vgrd=ctx.createLinearGradient(-240,-240,240,240);
vgrd.addColorStop(0,"rgb(255,255,170)");
vgrd.addColorStop(1,"rgb(140,140,0)");
// 波纹形外圈
for(var i=0;i<5;i++){
ctx.save();
ctx.rotate(Math.PI/180*2*i);
var arr=createWaveCircleArray(144,240,20);
ctx.beginPath();
for(var j=0;j<arr.length-2;j+=2){
var pt1=arr[j];
var pt2=arr[j+1];// 控制点
var pt3=arr[j+2];
ctx.lineTo(pt1.x,pt1.y);
ctx.quadraticCurveTo(pt2.x,pt2.y,pt3.x,pt3.y);
}
ctx.closePath();
ctx.lineWidth=2;
ctx.strokeStyle=vgrd;
ctx.stroke();
ctx.restore();
}
// 用圆去切取背景图成黄铜底
ctx.save();
ctx.rotate(Math.PI/2*3);
ctx.beginPath();
ctx.arc(0,0,228,0,Math.PI*2,true);
ctx.closePath();
ctx.lineWidth=4;
var gnt=ctx.createLinearGradient(0,-170,0,170);
gnt.addColorStop(0,"rgb(224,174,77)");
gnt.addColorStop(1,"rgb(85,43,5)");
ctx.strokeStyle=gnt;
ctx.stroke();
ctx.clip();
var img=document.getElementById("myImg");
ctx.drawImage(img,40,40,240,240,-WIDTH/2,-HEIGHT/2,WIDTH,HEIGHT);
ctx.restore();
// 金属圈
ctx.beginPath();
ctx.arc(0,0,210,0,Math.PI*2,true);
ctx.closePath();
ctx.lineWidth=2;
ctx.strokeStyle=vgrd;
ctx.stroke();
// 黑底
ctx.beginPath();
ctx.arc(0,0,207,0,Math.PI*2,true);
ctx.closePath();
ctx.fillStyle="rgb(14,22,26)";
ctx.fill();
// 间隔色
var r=207;
for(var i=0;i<6;i++){
var startAngle=i*Math.PI/3-Math.PI/18-Math.PI/2;
var x1=r*Math.cos(startAngle);
var y1=r*Math.sin(startAngle);
var endAngle=startAngle+Math.PI/9;
var x2=r*Math.cos(endAngle);
var y2=r*Math.sin(endAngle);
ctx.beginPath();
ctx.moveTo(0,0);
ctx.lineTo(x1,y1);
ctx.arc(0,0,r,startAngle,endAngle,false);
ctx.closePath();
ctx.fillStyle="rgba(91,111,125,0.3)";
ctx.fill();
}
// 中心五星加文字
//draw5Star(ctx,0,-150,20,"rgb(253,238,181)");
// 上方五星
ctx.beginPath();
ctx.moveTo(-70,-150);
ctx.lineTo(-18,-150);
ctx.closePath();
ctx.lineWidth=1;
ctx.strokeStyle="rgb(253,238,181)";
ctx.stroke();
draw5Star(ctx,0,-150,14,"rgb(253,238,181)");
ctx.beginPath();
ctx.moveTo(70,-150);
ctx.lineTo(18,-150);
ctx.closePath();
ctx.lineWidth=1;
ctx.strokeStyle="rgb(253,238,181)";
ctx.stroke();
// Brand Award
ctx.textBaseline="bottom";
ctx.textAlign="center";
ctx.font = "60px Stencil Std";
ctx.fillStyle="rgb(253,238,181)";
ctx.fillText("BRAND",0,-20);
ctx.font = "50px Stencil Std";
ctx.fillText("AWARD",0,40);
ctx.font = "40px 仿宋";
ctx.fillText("品牌嘉奖",0,90);
// --------右半圈橄榄枝
// 半圆
const radius=170;
const leaveLength=40;
ctx.beginPath();
ctx.arc(0,0,radius,Math.PI*(-3/2)-Math.PI/20,Math.PI*(-1/3)+Math.PI/20,true);
ctx.lineWidth=1;
ctx.strokeStyle="rgb(253,238,181)";
ctx.stroke();
// 外侧叶子
for(var i=1;i<17;i++){
var ratio=(i+30)/60;
var theta=-Math.PI/3*1+i*Math.PI/20;
var start={};
start.x=radius*Math.cos(theta);
start.y=radius*Math.sin(theta);
var end1={};
end1.x=start.x+ratio*leaveLength*Math.cos(-Math.PI/4+theta);
end1.y=start.y+ratio*leaveLength*Math.sin(-Math.PI/4+theta);
var center={};
center.x=(start.x+end1.x)/2;
center.y=(start.y+end1.y)/2;
// 利用复数求c1
var c1={};
c1.x=center.x+center.y-end1.y;
c1.y=end1.x-center.x+center.y;
// 利用复数求c2
var c2={};
c2.x=center.x+center.y-start.y;
c2.y=start.x-center.x+center.y;
ctx.beginPath();
ctx.lineTo(start.x,start.y);
ctx.quadraticCurveTo(c1.x,c1.y,end1.x,end1.y);
ctx.quadraticCurveTo(c2.x,c2.y,start.x,start.y);
ctx.closePath();
ctx.fillStyle="rgb(253,238,181)";
ctx.fill();
}
// 内侧叶子
for(var i=1;i<17;i++){
var ratio=(i+30)/60;
var theta=-Math.PI/3+i*Math.PI/20;
var start={};
start.x=radius*Math.cos(theta);
start.y=radius*Math.sin(theta);
var end1={};
end1.x=start.x+ratio*leaveLength*Math.cos(-Math.PI/4*3+theta);
end1.y=start.y+ratio*leaveLength*Math.sin(-Math.PI/4*3+theta);
var center={};
center.x=(start.x+end1.x)/2;
center.y=(start.y+end1.y)/2;
// 利用复数求c1
var c1={};
c1.x=center.x+center.y-end1.y;
c1.y=end1.x-center.x+center.y;
// 利用复数求c2
var c2={};
c2.x=center.x+center.y-start.y;
c2.y=start.x-center.x+center.y;
ctx.beginPath();
ctx.lineTo(start.x,start.y);
ctx.quadraticCurveTo(c1.x,c1.y,end1.x,end1.y);
ctx.quadraticCurveTo(c2.x,c2.y,start.x,start.y);
ctx.closePath();
ctx.fillStyle="rgb(253,238,181)";
ctx.fill();
}
// --------左半圈橄榄枝
// 半圆
ctx.beginPath();
ctx.arc(0,0,radius,Math.PI*(-4/6)-Math.PI/20,Math.PI*(-3/2)+Math.PI/20,true);
ctx.lineWidth=1;
ctx.strokeStyle="rgb(253,238,181)";
ctx.stroke();
// 外侧叶子
for(var i=1;i<17;i++){
var ratio=(i+30)/60;
var theta=-Math.PI/3*2-i*Math.PI/20;
var start={};
start.x=radius*Math.cos(theta);
start.y=radius*Math.sin(theta);
var end1={};
end1.x=start.x+ratio*leaveLength*Math.cos(Math.PI/4+theta);
end1.y=start.y+ratio*leaveLength*Math.sin(Math.PI/4+theta);
var center={};
center.x=(start.x+end1.x)/2;
center.y=(start.y+end1.y)/2;
// 利用复数求c1
var c1={};
c1.x=center.x+center.y-end1.y;
c1.y=end1.x-center.x+center.y;
// 利用复数求c2
var c2={};
c2.x=center.x+center.y-start.y;
c2.y=start.x-center.x+center.y;
ctx.beginPath();
ctx.lineTo(start.x,start.y);
ctx.quadraticCurveTo(c1.x,c1.y,end1.x,end1.y);
ctx.quadraticCurveTo(c2.x,c2.y,start.x,start.y);
ctx.closePath();
ctx.fillStyle="rgb(253,238,181)";
ctx.fill();
}
// 内侧叶子
for(var i=1;i<17;i++){
var ratio=(i+30)/60;
var theta=Math.PI/3*4-i*Math.PI/20;
var start={};
start.x=radius*Math.cos(theta);
start.y=radius*Math.sin(theta);
var end1={};
end1.x=start.x+ratio*leaveLength*Math.cos(Math.PI/4*3+theta);
end1.y=start.y+ratio*leaveLength*Math.sin(Math.PI/4*3+theta);
var center={};
center.x=(start.x+end1.x)/2;
center.y=(start.y+end1.y)/2;
// 利用复数求c1
var c1={};
c1.x=center.x+center.y-end1.y;
c1.y=end1.x-center.x+center.y;
// 利用复数求c2
var c2={};
c2.x=center.x+center.y-start.y;
c2.y=start.x-center.x+center.y;
ctx.beginPath();
ctx.lineTo(start.x,start.y);
ctx.quadraticCurveTo(c1.x,c1.y,end1.x,end1.y);
ctx.quadraticCurveTo(c2.x,c2.y,start.x,start.y);
ctx.closePath();
ctx.fillStyle="rgb(253,238,181)";
ctx.fill();
}
// 作者
ctx.textBaseline="bottom";
ctx.textAlign="center";
ctx.font = "8px consolas";
ctx.fillStyle="black";
ctx.fillText("逆火原创",WIDTH/2-40,HEIGHT/2-10);
}
// 画前景
this.paintFg=function(ctx){
}
}
//-------------------------------------------------------
// 取得一个齿轮全部控制点的函数
// n:齿轮齿数
// angle:齿斜面倾角
// outerRadius:齿轮外径
// innerRadius:齿轮内径
//-------------------------------------------------------
function getGearArray(n,angle,outerRadius,innerRadius){
// 准备齿轮数组
var gearArr=new Array();
for(var i=0;i<n*2;i++){
var alpha=Math.PI/n*i;
var bata=alpha+angle;
var x1,y1,x2,y2;
if(i%2==1){
x1=innerRadius*Math.cos(alpha);
y1=innerRadius*Math.sin(alpha);
x2=outerRadius*Math.cos(bata);
y2=outerRadius*Math.sin(bata);
}else{
x1=outerRadius*Math.cos(alpha);
y1=outerRadius*Math.sin(alpha);
x2=innerRadius*Math.cos(bata);
y2=innerRadius*Math.sin(bata);
}
gearArr.push({x:x1,y:y1});
gearArr.push({x:x2,y:y2});
}
return gearArr;
}
// 画实心五角星的函数
function draw5Star(ctx,x,y,r,color){
ctx.save()
ctx.translate(x-r,y-r);
ctx.beginPath();
ctx.moveTo(r, 0);
ctx.lineTo(r+Math.cos(Math.PI*3/10)*r, r+Math.sin(Math.PI*3/10)*r);
ctx.lineTo(r-Math.cos(Math.PI*1/10)*r, r-Math.sin(Math.PI*1/10)*r);
ctx.lineTo(r+Math.cos(Math.PI*1/10)*r, r-Math.sin(Math.PI*1/10)*r);
ctx.lineTo(r-Math.cos(Math.PI*3/10)*r, r+Math.sin(Math.PI*3/10)*r);
ctx.lineTo(r, 0);
ctx.closePath();
ctx.fillStyle=color;
ctx.fill();
ctx.restore();
}
//--------------------------------------------------
// 函数:创建波浪式环形需要的数组
// n:浪头峰谷个数
// radius:环形半径
// waveHeight:浪高
// 返回:包含浪高中低点坐标的数组
//--------------------------------------------------
function createWaveCircleArray(n,radius,waveHeight){
var arr=[];
const LEN=n+2;// 数组长度比浪头峰谷数多两个以在绘图时形成闭环
for(var i=0;i<LEN;i++){
var theta=i*Math.PI*2/n;
var r=radius+Math.sin(Math.PI/2*i)*waveHeight;// 造成涨落
var pt={};
pt.x=r*Math.cos(theta);
pt.y=r*Math.sin(theta);
arr.push(pt);
}
return arr;
}
/*---------------------------------------------
活着不是靠泪水博得同情,
而是靠汗水赢得掌声。
理性的羊肠小道,胜过鲁莽的高速公路。
----------------------------------------------*/
//-->
</script>
【底图】
以上代码使用到的底图120.jpg



















