【Canvas与标牌】2024.10.8胜利大逃亡盾形标牌

news2024/10/12 0:00:26

【成图】

【代码】

<!DOCTYPE html>
<html lang="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<head>
     <title>537.日期金盾Draft2上色</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;
        ctx.fillStyle="grey";
        drawShield(ctx,0,0,r);
        ctx.fill();
        ctx.restore();

        // 2圈
        ctx.save();
        var r=R*0.99;
        var gnt1=ctx.createLinearGradient(0,-r,0,r);
        gnt1.addColorStop(0,"rgb(191,206,213)");
        gnt1.addColorStop(0.25,"rgb(177,194,201)");
        gnt1.addColorStop(0.5,"rgb(219,230,236)");
        gnt1.addColorStop(0.75,"rgb(214,227,235)");
        gnt1.addColorStop(1,"rgb(194,209,216)");
        ctx.fillStyle=gnt1;
        drawShield(ctx,0,0,r);
        ctx.fill();
        ctx.restore();

        // 3圈
        ctx.save();
        var r=R*0.95;
        ctx.fillStyle="black";
        drawShield(ctx,0,0,r);
        ctx.fill();
        ctx.restore();

        // 4圈
        ctx.save();
        var r=R*0.94;
        var gnt1=ctx.createLinearGradient(0,-r,0,r);
        gnt1.addColorStop(0,"rgb(253,243,140)");
        gnt1.addColorStop(0.5,"rgb(252,207,43)");
        gnt1.addColorStop(1,"rgb(255,158,1)");
        ctx.fillStyle=gnt1;
        drawShield(ctx,0,0,r);
        ctx.fill();
        ctx.restore();

        // 5圈
        ctx.save();
        var r=R*0.90;
        var gnt1=ctx.createLinearGradient(0,-r,0,r);
        gnt1.addColorStop(0,"rgb(253,243,140)");
        gnt1.addColorStop(0.5,"rgb(251,223,97)");
        gnt1.addColorStop(1,"rgb(253,185,14)");
        ctx.fillStyle=gnt1;
        drawShield(ctx,0,0,r);
        ctx.fill();
        ctx.restore();

        // 2024
        ctx.save();
        var r=R*0.93;
        ctx.textBaseline="middle";
        ctx.textAlign="center";
        ctx.font = r*0.40+"px Bahnschrift SemiBold SemiConden";
        ctx.fillStyle="black";
        ctx.fillText("2024",0,-r*0.56);
        ctx.restore();

        // 10.8
        ctx.save();
        var r=R*0.93;
        ctx.textBaseline="middle";
        ctx.textAlign="center";
        ctx.font = r*0.36+"px Bahnschrift SemiBold SemiConden";
        ctx.fillStyle="black";
        ctx.fillText("10.8",0,-r*0.16);
        ctx.restore();

        // 红带
        ctx.save();
        var r=R*0.99;
        var w=r/3*2;
        var gnt1=ctx.createLinearGradient(-w,0,w,0);
        gnt1.addColorStop(0,"rgba(111,1,2,0.9)");
        gnt1.addColorStop(0.1,"rgba(162,3,7,0.9)");
        gnt1.addColorStop(0.25,"rgba(182,2,4,0.9)");
        gnt1.addColorStop(0.5,"rgba(208,2,4,0.9)");
        gnt1.addColorStop(0.75,"rgba(182,2,4,0.9)");
        gnt1.addColorStop(0.9,"rgba(162,3,7,0.9)");
        gnt1.addColorStop(1,"rgba(111,1,2,0.9)");
        ctx.fillStyle=gnt1;
        drawRect(ctx,0,r/6,2*w,r/3);
        ctx.fill();
        ctx.restore();

        // PREMIUM文字
        ctx.save();
        var r=R*0.98;        
        ctx.textBaseline="middle";
        ctx.textAlign="center";
        ctx.font = r*0.25+"px Bahnschrift SemiBold SemiConden";
        ctx.fillStyle="white";
        ctx.fillText("ESCAPE",0,r*0.20);
        ctx.restore();

        // QUALITY文字
        ctx.save();
        var r=R*0.93;
        ctx.textBaseline="middle";
        ctx.textAlign="center";
        ctx.font = r*0.19+"px Bahnschrift SemiBold SemiConden";
        ctx.fillStyle="black";
        ctx.fillText("successfully",0,r*0.53);
        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:盾牌中心纵坐标
radius:盾牌半径
----------------------------------------------------------*/
function drawShield(ctx,x,y,radius){
    ctx.save();
    const R=radius;//基准尺寸
    const ROUND=R/10;// 圆角
    const H=2*R;// 高
    const W=H*2/3;// 宽

    // a族
    var a=createPt(x,y-H/2);
    
    var r=ROUND;
    var angle=Math.PI/12;
    var a1=createPt(a.x+r*Math.cos(angle),a.y+r*Math.sin(angle));

    r=ROUND;
    angle=Math.PI-Math.PI/12;
    var a2=createPt(a.x+r*Math.cos(angle),a.y+r*Math.sin(angle));

    // b族
    r=W/2/Math.cos(Math.PI/12);
    angle=Math.PI-Math.PI/12;
    var b=createPt(a.x+r*Math.cos(angle),a.y+r*Math.sin(angle));

    r=ROUND;
    angle=-Math.PI/12;
    var b1=createPt(b.x+r*Math.cos(angle),b.y+r*Math.sin(angle));

    r=ROUND;
    angle=Math.PI/2;
    var b2=createPt(b.x+r*Math.cos(angle),b.y+r*Math.sin(angle));

    // f
    r=W/2/Math.cos(Math.PI/12);
    angle=Math.PI/12;
    var f=createPt(a.x+r*Math.cos(angle),a.y+r*Math.sin(angle));

    r=ROUND;
    angle=Math.PI/2;
    var f1=createPt(f.x+r*Math.cos(angle),f.y+r*Math.sin(angle));

    r=ROUND;
    angle=Math.PI+Math.PI/12;
    var f2=createPt(f.x+r*Math.cos(angle),f.y+r*Math.sin(angle));

    // d族
    var d=createPt(x,y+H/2);

    r=ROUND;
    angle=Math.PI+Math.PI/6;
    var d1=createPt(d.x+r*Math.cos(angle),d.y+r*Math.sin(angle));

    r=ROUND;
    angle=-Math.PI/6;
    var d2=createPt(d.x+r*Math.cos(angle),d.y+r*Math.sin(angle));

    // c族
    r=W/2/Math.cos(Math.PI/6);
    angle=Math.PI+Math.PI/6;
    var c=createPt(d.x+r*Math.cos(angle),d.y+r*Math.sin(angle));

    r=ROUND;
    angle=-Math.PI/2;
    var c1=createPt(c.x+r*Math.cos(angle),c.y+r*Math.sin(angle));

    r=ROUND;
    angle=Math.PI/6;
    var c2=createPt(c.x+r*Math.cos(angle),c.y+r*Math.sin(angle));

    // e族
    r=W/2/Math.cos(Math.PI/6);
    angle=-Math.PI/6;
    var e=createPt(d.x+r*Math.cos(angle),d.y+r*Math.sin(angle));

    r=ROUND;
    angle=Math.PI-Math.PI/6;
    var e1=createPt(e.x+r*Math.cos(angle),e.y+r*Math.sin(angle));

    r=ROUND;
    angle=-Math.PI/2;
    var e2=createPt(e.x+r*Math.cos(angle),e.y+r*Math.sin(angle));

    ctx.beginPath();
    ctx.moveTo(a1.x,a1.y);
    ctx.quadraticCurveTo(a.x,a.y,a2.x,a2.y);
    ctx.lineTo(a2.x,a2.y);
    ctx.lineTo(b1.x,b1.y);
    ctx.quadraticCurveTo(b.x,b.y,b2.x,b2.y);
    ctx.lineTo(c1.x,c1.y);
    ctx.quadraticCurveTo(c.x,c.y,c2.x,c2.y);
    ctx.lineTo(d1.x,d1.y);
    ctx.quadraticCurveTo(d.x,d.y,d2.x,d2.y);
    ctx.lineTo(e1.x,e1.y);
    ctx.quadraticCurveTo(e.x,e.y,e2.x,e2.y);
    ctx.lineTo(f1.x,f1.y);
    ctx.quadraticCurveTo(f.x,f.y,f2.x,f2.y);
    ctx.closePath();        

    ctx.restore();
}

/*----------------------------------------------------------
函数:用于绘制实心圆
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.coloradmin.cn/o/2206279.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

用Raspberry Pi Imager重装树莓派系统

今天删东西的时候&#xff0c;无意中把系统文件给remove了&#xff0c;结果树莓派无法正常启动&#xff0c;只能重新安装。 用DiskGenius工具将SD卡彻底清空&#xff0c;并将boot分区和文件分区合并为一&#xff0c;之后再对这个新分区进行了格式化。接下来就是烧录镜像了。以…

Java知识巩固(二)

OKracle JDK vs OpenJD 可能在看这个问题之前很多人和我一样并没有接触和使用过 OpenJDK 。那么 Oracle JDK 和 OpenJDK 之间是否存在重大差异&#xff1f;下面我通过收集到的一些资料&#xff0c;为你解答这个被很多人忽视的问题。 首先&#xff0c;2006 年 SUN 公司将 Java…

HTB:Bike[WriteUP]

目录 连接至HTB服务器并启动靶机 1.What TCP ports does nmap identify as open? Answer with a list of ports seperated by commas with no spaces, from low to high. 2.What software is running the service listening on the http/web port identified in the first …

MVC案例整合Spring和Hibernate

说到整合Spring和Hibernate首先要搞清楚&#xff0c;整合什么&#xff1f; 1、使用Spring的IOC容器来生产Hibernate的SessionFactory对象实例 2、让Hibernate使用Spring的声明式事务 整合步骤 1、先加入Hibernate 2、在加入Spring&#xff0c;整合 新建项目&#xff0c;建…

38个巨魔神级APP,建议果粉收藏

本文介绍了2024年最常用的38个精选巨魔工具&#xff0c;整理不易&#xff0c;建议收藏。 工欲善其事&#xff0c;必先利其器。从我刚接触巨魔开始&#xff0c;我就发现很多人即使有了巨魔&#xff0c;也是两眼一摸黑。 除了多开APP、通话录音&#xff0c;不知道巨魔还有什么用…

图论day57|建造最大岛屿(卡码网)【截至目前,图论的最高难度】

图论day57|建造最大岛屿&#xff08;卡码网&#xff09;【截至目前所做的题中&#xff0c;图论的最高难度】 思维导图分析 104.建造最大岛屿&#xff08;卡码网&#xff09;【截至目前所做的题中&#xff0c;图论的最高难度】 思维导图分析 104.建造最大岛屿&#xff08;卡码网…

文件IO及目录操作

一、文件IO 1.1 close函数&#xff08;关闭文件&#xff09; #include <unistd.h>---所需头文件 int close(int fd); 功能&#xff1a;关闭文件 参数&#xff1a;fd&#xff1a;文件描述符 返回值&#xff1a;成功返回0&#xff0c;失败返回-1&#xff0c;置位错误码 …

C#代码 串口通信晋中A2板,控制直流电机

1&#xff0c;在电脑中给晋中板中下载编译好的程序。 0x39 &#xff1a;开启电机的标识 代码&#xff1a; /********************************************************************************** **** 实验名称&#xff1a;串口通信实验 接线说明&#xff1a; 实验现象&…

NRF24L01原子HAl库学习

IRQ产生中断有低电平&#xff0c;在TxFIFI发送完收到ACk后产生&#xff0c; 在RxFIFO收到数据后也产生 达到最大重发次数也产生 工作时序&#xff0c;SCK空闲状态为0&#xff0c;CPOL0,第一个时钟沿采集数据CPHA0,SPI工作模式0 另外SPI高位先出&#xff0c;低字节先出 30个寄…

2024年秋季学期期中考试成绩查询系统-老师制作工具

随着2024年的日历逐渐翻至末尾&#xff0c;我们迎来了本年度的最后一次期中考试。对于我们这些教育工作者而言&#xff0c;这段时间无疑是充满挑战与收获的。今天&#xff0c;我要向大家推荐一个创新的工具——“易查分”&#xff0c;它将彻底革新我们传统的成绩发布流程。通过…

【瑞萨RA8D1 CPK开发板】lcd显示

1.8寸lcd使用gpio模拟spi驱动 由于板子引出的接口限制&#xff0c;故使用gpio模拟spi驱动中景园的1.8寸lcd 1.77寸液晶屏 1.8寸TFT LCD SPI TFT彩屏st7735驱动128x160高清屏-淘宝网 (taobao.com) 使用RASC 的gpio配置 根据厂家提供的驱动文件移植 #define LCD_SCLK_Clr() g…

【MySQL】CRUD增删改查操作

文章目录 CRUD简介一、Creat 新增1.单行数据全列插入2.单行数据全指定列插入3.多行数据指定列插入 二、Retrieve 检索1.全列查询 --练习阶段最简单的查询&#xff1a;&#xff08;在生产环境最好不要用&#xff01;&#xff01;&#xff09;2.指定列查询3.结果去重查询4.where条…

Tomcat部署java项目,反馈漏洞CVE-2005-4900: TLS SHA-1 安全漏洞(中危) *

根据项目反馈漏洞处理&#xff0c;修复部署SSL证书时反馈TLS1.2版本漏洞&#xff1a; 漏洞描述如下&#xff1a; 漏洞类型&#xff1a;密码学问题 漏洞描述&#xff1a; TLS &#xff08;全称 Transport Layer Security&#xff0c;安全传输层 协议&#xff09;是一套用于在两…

Qt 数据库,人脸识别

数据库 头文件 #ifndef WIDGET_H #define WIDGET_H#include <QMainWindow> #include<QSqlDatabase> QT_BEGIN_NAMESPACE namespace Ui { class widget; } QT_END_NAMESPACEclass widget : public QMainWindow {Q_OBJECTpublic:widget(QWidget *parent nullptr);…

HCIP-HarmonyOS Application Developer 习题(九)

(多选) 1、HarmonyOS多窗口交互能力提供了以下哪几种交互方式&#xff1f; A. 全局消息通知 B.平行视界 C.悬浮窗 D.分屏 答案&#xff1a;BCD 分析&#xff1a;系统提供了悬浮窗、分屏、平行视界三种多窗口交互&#xff0c;为用户在大屏幕设备上的多任务并行、便捷的临时任务…

项目 多人对话

项目 目标 多人对话仿真平台 技术点 socketIO异常多线程集合面向对象字符串GUI&#xff08;client&#xff09;… 项目开发方式 迭代开发-敏捷开发 建立模型 C/S 客户端/服务器模型(console) 服务器 package com.ffyc.tcp.one;import java.io.IOException; import java.i…

【大模型】RMS Normalization原理及实现

1.RMS Normalization的原理 说RMS Normalization之前&#xff0c;先讲Layer Normalization 和 Batch Normalization。 BN和LN是两种常见的归一化方法。它们的目的是帮助模型训练更稳定、收敛更快。BN是在Batch维度上进行归一化&#xff0c;即对同一batch中每个特征维度的值进行…

操作系统的了解及安装

一、linux系统认识 linux是指操作系统的内核&#xff0c;ubuntu是指基于这种内核的操作系统&#xff0c;Ubuntu属于Linux的一个发行版本&#xff0c;有简易的用户界面&#xff0c;完善的包管理系统&#xff0c;Ubuntu还对大多数硬件有着良好的兼容性&#xff0c;包含最新的图形…

一文区分SSTI 和 CSTI

前言 有时&#xff0c;SSTI&#xff08;服务器端模板注入&#xff09;和 CSTI&#xff08;客户端模板注入&#xff09;可能会由于它们相似的负载语法而混淆。这种混乱可能会导致渗透测试人员浪费时间尝试实现反向 shell&#xff0c;即使payload仅限于客户端。 定义 &#x1d…

10.11 QT数据库实现学生信息的增、删、改、查

.pro文件 QT core gui sql .h文件 #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QSqlDatabase> //数据库管理类 #include <QSqlQuery> //数据库查寻类 #include <QSqlRecord> //记录类 #include <QMessage…