当前位置: 首页 > news >正文

canvas基础2 -- 形状

 七巧板

七巧板本质上就是 分别由几个直线 拼成一个个图形,再将这些图形结合起来

var tangram = [{ p: [{ x: 0, y: 0 }, { x: 800, y: 0 }, { x: 400, y: 400 }], color: "#caff67" },{ p: [{ x: 0, y: 0 }, { x: 400, y: 400 }, { x: 0, y: 800 }], color: "#67beef" },{ p: [{ x: 800, y: 0 }, { x: 800, y: 400 }, { x: 600, y: 600 }, { x: 600, y: 200 }], color: "#ef3d61" },{ p: [{ x: 600, y: 200 }, { x: 600, y: 600 }, { x: 400, y: 400 }], color: "#f9f5la" },{ p: [{ x: 400, y: 400 }, { x: 600, y: 600 }, { x: 400, y: 800 }, { x: 200, y: 600 }], color: "#a594c0" },{ p: [{ x: 200, y: 600 }, { x: 400, y: 800 }, { x: 0, y: 800 }], color: "#fa8ecc" },{ p: [{ x: 800, y: 400 }, { x: 800, y: 800 }, { x: 400, y: 800 }], color: "#f6ca29" }]const canvas = document.getElementById('canvas')canvas.width = 800canvas.height = 800const context = canvas.getContext('2d')for (let i = 0; i < tangram.length; i++) {draw(tangram[i], context)}function draw(piece, cxt) {cxt.beginPath()cxt.moveTo(piece.p[0].x, piece.p[0].y)for (var i = 1; i < piece.p.length; i++) {cxt.lineTo(piece.p[i].x, piece.p[i].y)}cxt.closePath()cxt.fillStyle = piece.colorcxt.fill()cxt.strokeStyle = "black"cxt.lineWidth = 3cxt.stroke()}

图示:

箭头

    context.beginPath()context.moveTo(100, 350) context.lineTo(500, 350) context.lineTo(500, 200) context.lineTo(700, 400)context.lineTo(500, 600)context.lineTo(500, 450)context.lineTo(100, 450)context.closePath()context.lineWidth = 5  context.strokeStyle = '#058'context.stroke() 

图示:

1

http://www.lryc.cn/news/189831.html

相关文章:

  • TCP/IP(五)TCP的连接管理(二)三次握手细节
  • Vue Elememt 链接后端
  • XPS光电子谱峰与俄歇电子谱峰-科学指南针
  • STM32F4X I2C LM75
  • “华为杯”研究生数学建模竞赛2019年-【华为杯】F题:智能飞行器航迹规划模型(下)(附优秀论文及Pyhton代码实现)
  • 信息系统项目管理师第四版学习笔记——配置与变更管理
  • 代理IP端口是什么意思呢?
  • 如何使用ChatPPT生成PPT文档
  • 亚马逊云科技最新分享:人、流程、工具全链路数据安全合规
  • Xception:使用Tensorflow从头开始实现
  • Practical Memory Leak Detection using Guarded Value-Flow Analysis 论文阅读
  • 淘宝天猫商品历史价格API接口
  • 从0开始学go第七天
  • 【牛客面试必刷TOP101】Day7.BM31 对称的二叉树和BM32 合并二叉树
  • U盘怎么设置为只读?U盘怎么只读加密?
  • 为什么MyBatis是Java数据库持久层的明智选择
  • 二叉搜索树--查询节点-力扣 700 题
  • YOLOv3 | 核心主干网络,特征图解码,多类损失函数详解
  • Java架构师API设计
  • .net也能写内存挂
  • python学习笔记2-数字转化为String
  • MAC版Gradle构建Spring5.X源码阅读环境
  • Linux 常用通配符
  • Python皮卡丘
  • 【数据结构与算法】三种简单排序算法,包括冒泡排序、选择排序、插入排序算法
  • 视频太大怎么压缩变小?超过1G的视频这样压缩
  • Edge 无法登录/同步问题【一招搞定】
  • ESP32-S3上手开发
  • UE4和C++ 开发-编程基础记录(UE4+代码基础知识)
  • 【Unity】【VR】如何让Distance Grab抓取物品时限制物品的Rotation