【Canvas与标牌】立入禁止标牌

news/2024/10/15 23:35:51/

【成图】

【代码】

<!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;ctx.shadowOffsetX=2; // 阴影ctx.shadowOffsetY=2; ctx.shadowColor="lightgrey";ctx.shadowBlur=2;var gnt1=ctx.createLinearGradient(0,-r,0,r);gnt1.addColorStop(0,"rgb(252,238,162)");gnt1.addColorStop(0.5,"rgb(255,225,83)");gnt1.addColorStop(1,"rgb(200,163,74)");ctx.fillStyle=gnt1;var w=2*r;var h=w/3*2;var round=r/20;drawRoundRect(ctx,0,0,w,h,round);ctx.fill();ctx.restore();// 黑圈ctx.save();var r=R*0.95;ctx.fillStyle="black";w-=r*0.05;h-=r*0.05;drawRoundRect(ctx,0,0,w,h,round);ctx.fill();ctx.restore();// 条纹区域ctx.save();var r=R*0.93;w-=r*0.07;h-=r*0.07;drawRoundRect(ctx,0,0,w,h,round);ctx.clip();const N=15;var offset=(w+h)/N;for(var i=0;i<N;i++){var a=createPt(-w/2-h+i*offset,h/2);r=offset;var angle=0;var b=createPt(a.x+r*Math.cos(angle),a.y+r*Math.sin(angle));r=h*Math.sqrt(2);angle=-Math.PI/4;var c=createPt(b.x+r*Math.cos(angle),b.y+r*Math.sin(angle));r=offset;angle=Math.PI;var d=createPt(c.x+r*Math.cos(angle),c.y+r*Math.sin(angle));ctx.fillStyle=(i%2==0)?"black":gnt1;ctx.beginPath();ctx.moveTo(a.x,a.y);ctx.lineTo(b.x,b.y);ctx.lineTo(c.x,c.y);ctx.lineTo(d.x,d.y);ctx.closePath();ctx.fill();}ctx.restore();// 中心文字ctx.save();var r=R*0.93;var x=0,y=r/4;var word="立入禁止";ctx.textBaseline="bottom";ctx.textAlign="center";ctx.font = r*0.4+"px 黑体";ctx.fillStyle="red";ctx.fillText(word,x,y);ctx.lineWidth=1;ctx.strokeStyle="white";ctx.strokeText(word,x,y);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


http://www.ppmy.cn/news/1538255.html

相关文章

百度搜索引擎是如何解决用户点击率与网站排名关联度的呢?

百度搜索引擎是如何解决用户点击率与网站排名的关联度 大家好&#xff0c;我是林汉文&#xff08;SEO专家&#xff09;&#xff0c;今天我们来讨论一个非常有意义的话题&#xff1a;百度搜索引擎是如何解决用户点击率与网站排名的关联度&#xff0c;在当今搜索引擎优化&#x…

P8635 [蓝桥杯 2016 省 AB] 四平方和

对于一个给定的正整数&#xff0c;可能存在多种平方和的表示法。 要求你对 44个数排序使得 0≤a≤b≤c≤d。 输入 #1复制 5 输出 #1 0 0 1 2 输入 #2 12 输出 #2 0 2 2 2 输入 #3 773535 输出 #3 1 1 267 838 代码 #include<bits/stdc.h> using namespace …

【C++】模拟实现hash_table(哈希表)

&#x1f984;个人主页:修修修也 &#x1f38f;所属专栏:实战项目集 ⚙️操作环境:Visual Studio 2022 目录 一.了解项目功能 二.逐步实现项目功能模块及其逻辑详解 &#x1f4cc;实现HashNode类模板 &#x1f38f;构造HashNode类成员变量 &#x1f38f;实现HashNode类构造函数…

【Python Django + Vue】酒店在线预订系统:用技术说话!

&#x1f393; 作者&#xff1a;计算机毕设小月哥 | 软件开发专家 &#x1f5a5;️ 简介&#xff1a;8年计算机软件程序开发经验。精通Java、Python、微信小程序、安卓、大数据、PHP、.NET|C#、Golang等技术栈。 &#x1f6e0;️ 专业服务 &#x1f6e0;️ 需求定制化开发源码提…

springboot项目通过maven的profile功能实现通过不同文件夹的方式来组织不同环境配置文件

写在前面 本文看下springboot项目如何通过文件夹的方式来组织不同环境配置文件。 1&#xff1a;正文 一般的我们写springboot项目时配置文件是这个样子的&#xff1a; appliction.yaml --> 通过spring.profiles.activexxx来激活某个指定后缀的配置文件 application-evn1…

Windows环境NodeJS下载配置安装运行

Windows环境NodeJS下载配置安装运行 &#xff08;1&#xff09;下载 Node.js — Run JavaScript Everywhere 安装文件。 一路傻瓜式安装。 如果安装正常&#xff0c;输入命令可显示版本号&#xff1a; &#xff08;2&#xff09;可以查询nodejs默认的后续依赖安装包位置及缓存…

React02 JSX的基本使用

JSX的基本使用 JSX 变量引用JSX 函数调用JSX 方法调用JSX 遍历数组JSX 条件渲染JSX 事件绑定 JSX 变量引用 const userName "BLU"; function App() {return (<div className"App"><p>Hello, {userName}!</p></div>); } export d…

优化 webpack 的打包速度的优化

前端面试题包括ECMScript,TypeScript,Nodejs,React,Webgl,Threejs等还在整理中&#xff0c;在线地址前端面试题&#xff0c;源码地址大家多多支持才有动力给大家分享更多好的面试题。 优化 Webpack 的打包速度可以显著提升开发效率&#xff0c;尤其是在大型项目中。以下是一些…