欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 国际 > 【Canvas与图标】蓝色渐变SQL图标

【Canvas与图标】蓝色渐变SQL图标

2025/2/5 17:36:41 来源:https://blog.csdn.net/River_Sun/article/details/144168752  浏览:    关键词:【Canvas与图标】蓝色渐变SQL图标

【成图】

120*120的png图标

各种大小图:

【代码】

<!DOCTYPE html>
<html lang="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<head><title>蓝色渐变SQL图标 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;// 暂停标志
var paused=false;//-------------------------------
// 初始化
//-------------------------------
function init(){// 获得canvas对象var canvas=document.getElementById('myCanvas');  // 设置点击鼠标暂停canvas.οnclick=function(e){paused=! paused;}// 设置高宽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.theta=0;// 初始化this.init=function(){}// 更新this.update=function(){ if(!paused){this.theta+=0.02;}}// 画背景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;// 基准尺寸// 第1圈ctx.save();ctx.shadowOffsetX=2; ctx.shadowOffsetY=2; ctx.shadowColor="grey";ctx.shadowBlur=4;var r=R*1.00;var gnt=ctx.createLinearGradient(r,-r,-r,r);gnt.addColorStop(0,"rgb(0,21,42)");gnt.addColorStop(0.25,"rgb(41,104,139)");gnt.addColorStop(0.50,"rgb(76,167,212)");gnt.addColorStop(0.75,"rgb(41,104,139)");gnt.addColorStop(1,"rgb(0,21,42)");drawSolidCircle(ctx,0,0,r,gnt);ctx.restore();// 彩带1ctx.save();var r=R*1.00;ctx.arc(0,0,r,0,Math.PI*2,false);ctx.clip();ctx.rotate(-Math.PI/4);var colors=["rgb(0,97,148)","rgb(255,255,255)","rgb(191,0,31)"];var w=r/5/Math.sqrt(3);var h=2*r;for(var i=0;i<3;i++){ctx.fillStyle=colors[i];drawRect(ctx,(i-1)*w,0,w,h);ctx.fill();}ctx.restore();// 第2圈var r=R*0.80;var gnt=ctx.createLinearGradient(-r,0,r,0);gnt.addColorStop(0,"rgb(4,31,58)");gnt.addColorStop(0.25,"rgb(33,93,129)");gnt.addColorStop(0.50,"rgb(76,167,212)");gnt.addColorStop(0.75,"rgb(33,93,129)");gnt.addColorStop(1,"rgb(4,31,58)");drawSolidCircle(ctx,0,0,r,gnt);ctx.restore();// 内圈var r=R*0.77;var gnt=ctx.createRadialGradient(0,0,0,0,0,r);gnt.addColorStop(0,"rgb(255,255,255)");gnt.addColorStop(0.3,"rgb(254,254,254)");gnt.addColorStop(0.5,"rgb(246,246,246)");gnt.addColorStop(0.75,"rgb(204,213,220)");gnt.addColorStop(0.9,"rgb(163,176,192)");gnt.addColorStop(1,"rgb(115,133,147)");drawSolidCircle(ctx,0,0,r,gnt);ctx.restore();// 文字ctx.save();var r=R*0.77;ctx.textBaseline="middle";ctx.textAlign="center";ctx.font = r*1.0+"px Cambria";ctx.lineWidth=R/105*1.1;ctx.strokeStyle="white";ctx.strokeText("SQL",0,0);ctx.fillStyle="rgb(29,93,121)";ctx.fillText("SQL",0,0);ctx.restore();// 玻璃光ctx.save();var r=R*0.77;var a=createPt(-r,0);var b=createPt(+r,0);var c=createPt(-r/4,+r/2);var d=createPt(+r/4,-r/2);var gnt=ctx.createLinearGradient(0,d.y,0,r);gnt.addColorStop(0,"rgba(180,180,180,0.1)");gnt.addColorStop(0.5,"rgba(210,210,210,0.2)");gnt.addColorStop(1,"rgba(240,240,240,0.4)");ctx.fillStyle=gnt;ctx.lineWidth=1;ctx.beginPath();ctx.moveTo(a.x,a.y);ctx.bezierCurveTo(c.x,c.y,d.x,d.y,b.x,b.y);ctx.arc(0,0,r,0,Math.PI,false);ctx.fill();ctx.restore();    writeText(ctx,WIDTH/2-30,HEIGHT/2-5,"逆火制图","8px consolas","lightgrey");// 版权}
}/*----------------------------------------------------------
函数:用于绘制矩形
ctx:绘图上下文
x:矩形中心横坐标
y:矩形中心纵坐标
width:矩形宽
height:矩形高
----------------------------------------------------------*/
function drawRect(ctx,x,y,width,height){ctx.beginPath();ctx.moveTo(x-width/2,y-height/2);ctx.lineTo(x+width/2,y-height/2);ctx.lineTo(x+width/2,y+height/2);ctx.lineTo(x-width/2,y+height/2);ctx.closePath();
}/*----------------------------------------------------------
函数:用于绘制实心圆,用途是标记点以辅助作图
ctx:绘图上下文
x:矩形中心横坐标
y:矩形中心纵坐标
r:圆半径
color:填充圆的颜色
----------------------------------------------------------*/
function drawSolidCircle(ctx,x,y,r,color){ctx.fillStyle=color;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();
}/*-------------------------------------------------------------
勇敢无畏才是前进提升的前提。
当你害怕被评判,害怕犯错,认为犯错就是失败,那么你往往会逃避,
而不开始好像不会失败,但其实不开始才是真正的选择了失败,
当你选择逃避不做的那一刻,1%-99%的成功率成了0%。
--------------------------------------------------------------*/
//-->
</script>

END

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com