pixi.js 5.0

Stars, bursts, gears, wedges, polygons, arcs, and dashes all drawn using Pixi.js, the HTML5 creation engine with the fastest, most flexible 2D WebGL renderer.

使用Pixi.js(具有最快,最灵活的2D WebGL渲染器HTML5创建引擎)绘制的星形,爆炸,齿轮,楔形,多边形,弧形和破折号。

It was many years ago when adding a burst to a graphic I stumbled upon the Funky Monkey drawing script by Ric Ewing. Comments embedded in the function immediately resonated with me:

多年前,当在图形中添加连拍时,我偶然发现了Ric Ewing的Funky Monkey绘图脚本。 函数中嵌入的注释立即引起了我的共鸣:

Burst is a method for drawing star bursts. If you’ve ever worked with an advertising department, you know what they are ;-)

爆发是一种绘制星爆发的方法。 如果您曾经在广告部门工作过,您就会知道他们是什么;-)

Clients tend to want them, Developers tend to hate them…

客户倾向于想要它们,开发人员倾向于讨厌它们……

Thought I’d bring these back to life leveraging modern web.

以为我会利用现代网络将它们重新带回生活。

Here are seven of those drawing shapes ported to Pixi.js.

这是移植到Pixi.js的七个图形。

划线 (Drawing Dashes)

Draws a dashed line from point x1, y1 to point x2, y2.

从点x1,y1到点x2,y2绘制一条虚线。

Usage:

用法:

  • target — Graphics instance on which dashed line will be drawn

    target —将在其上绘制虚线的图形实例

  • x1 — Starting position along x-axis

    x1 —沿x轴的起始位置

  • y1 — Starting position along y-axis

    y1沿y轴的起始位置

  • x2 — Final position along x-axis

    x2 —沿x轴的最终位置

  • y2 — Final position along y-axis

    y2沿y轴的最终位置

  • dashLength — Length of each dash, in pixels

    dashLength —每个破折号的长度,以像素为单位

  • spaceLength — Space between dashes, in pixels

    spaceLength —破折号之间的间隔,以像素为单位

function drawDash(target,                  x1,                  y1,                  x2,                  y2,                  dashLength = 5,                  spaceLength = 5) {  let x = x2 - x1;  let y = y2 - y1;  let hyp = Math.sqrt((x) * (x) + (y) * (y));  let units = hyp / (dashLength + spaceLength);  let dashSpaceRatio = dashLength / (dashLength + spaceLength);  let dashX = (x / units) * dashSpaceRatio;  let spaceX = (x / units) - dashX;  let dashY = (y / units) * dashSpaceRatio;  let spaceY = (y / units) - dashY;  target.moveTo(x1, y1);  while (hyp > 0) {    x1 += dashX;    y1 += dashY;    hyp -= dashLength;    if (hyp < 0) {      x1 = x2;      y1 = y2;    }    target.lineTo(x1, y1);    x1 += spaceX;    y1 += spaceY;    target.moveTo(x1, y1);    hyp -= spaceLength;  }  target.moveTo(x2, y2);}

绘制弧 (Drawing Arcs)

Draws an arc from starting position x, y.

从起始位置x,y绘制圆弧。

Usage:

用法:

  • target — Graphics instance on which dashed line will be drawn

    target —将在其上绘制虚线的图形实例

  • x — X coordinate of the starting point

    x —起点的X坐标

  • y — Y coordinate of the starting point

    y —起点的Y坐标

  • radius — Radius of the arc

    radius —弧的半径

  • arc — Sweep of the arc (negative values draw clockwise)

    arcarc扫描(负值顺时针绘制)

  • startAngle — Starting offset angle in degrees

    startAngle —以角度为单位的起始偏移角度

  • yRadius — Y radius of the arc, if different than radius will draw an oval

    yRadius —圆弧的Y半径,如果与半径不同,将绘制一个椭圆

function drawArc(target,                  x,                  y,                  radius,                  arc,                  startAngle = 0,                  yRadius = 0) {

  if (yRadius === 0)    yRadius = radius;  let segs = Math.ceil(Math.abs(arc) / 45);  let segAngle = arc / segs;  let theta = -(segAngle / 180) * Math.PI;  let angle = -(startAngle / 180) * Math.PI;  let ax = x - Math.cos(angle) * radius;  let ay = y - Math.sin(angle) * yRadius;  let angleMid, bx, by, cx, cy;

  if (segs > 0) {    target.moveTo(x, y);    for (let i = 0; i < segs; ++i) {      angle += theta;      angleMid = angle - (theta / 2);      bx = ax + Math.cos(angle) * radius;      by = ay + Math.sin(angle) * yRadius;      cx = ax + Math.cos(angleMid) * (radius / Math.cos(theta / 2));      cy = ay + Math.sin(angleMid) * (yRadius / Math.cos(theta / 2));      target.quadraticCurveTo(cx, cy, bx, by);    }  }}

绘图楔 (Drawing Wedges)

Draws pie shaped wedges, such as in pie charts.

绘制饼状的楔形图,例如在饼图中。

Usage:

用法:

  • target — Graphics instance on which dashed line will be drawn

    target —将在其上绘制虚线的图形实例

  • x — X coordinate of the center point

    x —中心点的X坐标

  • y — Y coordinate of the center point

    y中心点的Y坐标

  • radius — Radius of the wedge

    radius —楔形的半径

  • arc — Sweep of the arc (negative values draw clockwise)

    arcarc扫描(负值顺时针绘制)

  • startAngle — Starting angle in degrees

    startAngle —起始角度(度)

  • yRadius — Y radius of the wedge

    yRadius —楔的Y半径

function drawWedge(target,                   x,                   y,                   radius,                   arc,                   startAngle = 0,                   yRadius = 0) {  let segs = Math.ceil(Math.abs(arc) / 45);  let segAngle = arc / segs;  let theta = -(segAngle / 180) * Math.PI;  let angle = -(startAngle / 180) * Math.PI;  let ax = x + Math.cos(startAngle / 180 * Math.PI) * radius;  let ay = y + Math.sin(-startAngle / 180 * Math.PI) * yRadius;  let angleMid, bx, by, cx, cy;  if (yRadius === 0)    yRadius = radius;  target.moveTo(x, y);  target.lineTo(ax, ay);  for (let i = 0; i < segs; ++i) {    angle += theta;    angleMid = angle - (theta / 2);    bx = x + Math.cos(angle) * radius;    by = y + Math.sin(angle) * yRadius;    cx = x + Math.cos(angleMid) * (radius / Math.cos(theta / 2));    cy = y + Math.sin(angleMid) * (yRadius / Math.cos(theta / 2));    target.quadraticCurveTo(cx, cy, bx, by);  }  target.lineTo(x, y);}

绘制多边形 (Drawing Polygons)

Draws polygon shapes of specified number of sides.

绘制指定边数的多边形形状。

Usage:

用法:

  • target — Graphics instance on which dashed line will be drawn

    target —将在其上绘制虚线的图形实例

  • x — X coordinate of the center point

    x —中心点的X坐标

  • y — Y coordinate of the center point

    y中心点的Y坐标

  • sides — Number of sides (must be greater than 2)

    sides数—边数(必须大于2)

  • radius — Radius from the center point to points on the polygon

    radius —从中心点到多边形上各点的半径

  • angle — Starting angle offset in degrees

    angle —以角度为单位的起始角度偏移量

function drawPolygon(target,                     x,                     y,                     sides,                     radius,                     angle = 0) {  let step = (Math.PI * 2) / sides;  let start = (angle / 180) * Math.PI;  let n, dx, dy;  target.moveTo(    x + (Math.cos(start) * radius),    y - (Math.sin(start) * radius)  );  for (n = 1; n <= sides; ++n) {    dx = x + Math.cos(start + (step * n)) * radius;    dy = y - Math.sin(start + (step * n)) * radius;    target.lineTo(dx, dy);  }}

绘图星 (Drawing Stars)

Draws a star shaped pattern with specified number of points

绘制具有指定点数的星形图案

Usage:

用法:

  • target — Graphics instance on which dashed line will be drawn

    target —将在其上绘制虚线的图形实例

  • x — X coordinate of the center point

    x —中心点的X坐标

  • y — Y coordinate of the center point

    y中心点的Y坐标

  • points — Number of points on the star

    points —星点数

  • innerRadius — Radius of the inside angles of the star

    innerRadius —恒星内角的半径

  • outerRadius — Radius of the outside angles of the star

    outerRadius —恒星outerRadius半径

  • angle — Starting angle offset in degrees

    angle —以角度为单位的起始角度偏移量

function drawStar(target,                  x,                  y,                  points,                  innerRadius,                  outerRadius,                  angle = 0) {  let step = (Math.PI * 2) / points;  let halfStep = step / 2;  let start = (angle / 180) * Math.PI;  let n, dx, dy;  target.moveTo(    x + (Math.cos(start) * outerRadius),    y - (Math.sin(start) * outerRadius)  );

  for (n = 1; n <= points; ++n) {    dx = x + Math.cos(start + (step * n) - halfStep) * innerRadius;    dy = y - Math.sin(start + (step * n) - halfStep) * innerRadius;    target.lineTo(dx, dy);    dx = x + Math.cos(start + (step * n)) * outerRadius;    dy = y - Math.sin(start + (step * n)) * outerRadius;    target.lineTo(dx, dy);  }}

牵引齿轮 (Drawing Gears)

Draws a gear shape with the specified number of sides.

绘制具有指定边数的齿轮形状。

Usage:

用法:

  • target — Graphics instance on which dashed line will be drawn

    target —将在其上绘制虚线的图形实例

  • x — X coordinate of the center point

    x —中心点的X坐标

  • y — Y coordinate of the center point

    y中心点的Y坐标

  • sides — Number of teeth on the gear (must be greater than 2)

    sides —齿轮上的齿数(必须大于2)

  • innerRadius — Radius of the indent of the teeth

    innerRadius —牙齿凹痕的半径

  • outerRadius — Radius of the teeth

    outerRadius —牙齿的半径

  • angle — Starting angle offset in degrees

    angle —以角度为单位的起始角度偏移量

  • holeSides — Polygonal hole number of sides (must be greater than 2)

    holeSides —边的多边形Kong数(必须大于2)

  • holeRadius — Radius of the hole

    holeRadius —Kong的半径

function drawGear(target,                  x,                  y,                  sides,                  innerRadius = 80,                  outerRadius = 4,                  angle = 0,                  holeSides = 2,                  holeRadius = 0) {  let step = (Math.PI * 2) / sides;  let qtrStep = step / 4;  let start = (angle / 180) * Math.PI;  let n, dx, dy;  target.moveTo(    x + (Math.cos(start) * outerRadius),    y - (Math.sin(start) * outerRadius)  );

  for (n = 1; n <= sides; ++n) {    dx = x + Math.cos(start + (step * n) - (qtrStep * 3)) * innerRadius;    dy = y - Math.sin(start + (step * n) - (qtrStep * 3)) * innerRadius;    target.lineTo(dx, dy);    dx = x + Math.cos(start + (step * n) - (qtrStep * 2)) * innerRadius;    dy = y - Math.sin(start + (step * n) - (qtrStep * 2)) * innerRadius;    target.lineTo(dx, dy);    dx = x + Math.cos(start + (step * n) - qtrStep) * outerRadius;    dy = y - Math.sin(start + (step * n) - qtrStep) * outerRadius;    target.lineTo(dx, dy);    dx = x + Math.cos(start + (step * n)) * outerRadius;    dy = y - Math.sin(start + (step * n)) * outerRadius;    target.lineTo(dx, dy);  }  step = (Math.PI * 2) / holeSides;  target.moveTo(    x + (Math.cos(start) * holeRadius),    y - (Math.sin(start) * holeRadius)  );  for (n = 1; n <= holeSides; ++n) {    dx = x + Math.cos(start + (step * n)) * holeRadius;    dy = y - Math.sin(start + (step * n)) * holeRadius;    target.lineTo(dx, dy);  }}

拉爆 (Drawing Bursts)

Draw a star burst with the specified number of sides.

用指定的边数绘制一个星状爆发。

Usage:

用法:

  • target — Graphics instance on which dashed line will be drawn

    target —将在其上绘制虚线的图形实例

  • x — X coordinate of the center point

    x —中心点的X坐标

  • y — Y coordinate of the center point

    y中心点的Y坐标

  • sides — Number of teeth on the gear (must be greater than 2)

    sides —齿轮上的齿数(必须大于2)

  • innerRadius — Radius of the indent of the curves

    innerRadius —曲线压痕的半径

  • outerRadius — Radius of the outermost points

    outerRadius —最外点的半径

  • angle — Starting angle offset in degrees

    angle —以角度为单位的起始角度偏移量

function drawBurst(target,                   x,                   y,                   sides,                   innerRadius,                   outerRadius,                   angle = 0) {  let step = (Math.PI * 2) / sides;  let halfStep = step / 2;  let qtrStep = step / 4;  let start = (angle / 180) * Math.PI;  let n, dx, dy, cx, cy;  target.moveTo(    x + (Math.cos(start) * outerRadius),    y - (Math.sin(start) * outerRadius)  );   for (n = 1; n <= sides; ++n) {    cx = x + Math.cos(start + (step * n) - (qtrStep * 3)) * (innerRadius / Math.cos(qtrStep));    cy = y - Math.sin(start + (step * n) - (qtrStep * 3)) * (innerRadius / Math.cos(qtrStep));    dx = x + Math.cos(start + (step * n) - halfStep) * innerRadius;    dy = y - Math.sin(start + (step * n) - halfStep) * innerRadius;    target.quadraticCurveTo(cx, cy, dx, dy);    cx = x + Math.cos(start + (step * n) - qtrStep) * (innerRadius / Math.cos(qtrStep));    cy = y - Math.sin(start + (step * n) - qtrStep) * (innerRadius / Math.cos(qtrStep));    dx = x + Math.cos(start + (step * n)) * outerRadius;    dy = y - Math.sin(start + (step * n)) * outerRadius;    target.quadraticCurveTo(cx, cy, dx, dy);  }}

翻译自: https://levelup.gitconnected.com/advanced-drawing-with-pixi-js-cd3fddc1d69e

pixi.js 5.0

http://www.taodudu.cc/news/show-4034629.html

相关文章:

  • pixi.js淘宝小程序快速上手指南
  • PIXI_碰撞检测
  • Pixi.js文档笔记-起步
  • pixi 小游戏_学习如何用pixi.js开发微信小游戏
  • 使用PIXI制作简单canvas逐帧动画的心得
  • pixi 流星_流星语270—273
  • 实战pixi+gsap,仿刹车动画
  • pixi 平铺精灵 demo (一)
  • pixi 小游戏_关于PIXI引擎制作页面小游戏的几个总结
  • Pixi
  • pixi 小游戏_使用 Pixi.js 开发微信小游戏
  • pixi 小游戏_pixi2d小游戏跳一跳源码/pixi教程,基于pixi-spine的2d游戏
  • PIXI入门-PIXI文档翻译(1)
  • 2D渲染pixi项目实战总结
  • Pixi官方文档译文(1)
  • OCP原则
  • 设计模式七大原则——里氏替换原则
  • 归结原则
  • DRY原则
  • java程序设计六大原则
  • Attempt to read from field ‘android.os.VibrationEffect com.android.server.VibratorService$Vibration.
  • [MEM]Backdoor Access Memory
  • How to Backdoor Federated Learning
  • Backdoor Attack with Imperceptible Input and Latent Modification
  • 后门攻击阅读笔记,Input-aware dynamic backdoor attack
  • 后门防御阅读笔记,Black-box Detection of Backdoor Attacks with Limited Information and Data
  • Backdoor.Zegost木马病毒分析(一)
  • ctf_backdoor
  • 论文笔记| 后门攻击|Composite Backdoor Attack for Deep Neural Network byMixing Existing Benign Features
  • Invisible Backdoor Attack with Sample-Specific Triggers 论文笔记

pixi.js 5.0_使用Pixi.js进行高级绘图相关推荐

  1. 【Node.js】2.开发Node.js选择哪个IDE 开发工具呢

    安装完Node.js之后,就要为它选择一个有利的IDE用于开发. 相比较了多个IDE之后,定位在webstrom和sublime上. 有一个简单的比较: webstorm功能很丰富,前端开发工具的集大 ...

  2. 【深入浅出Node.js系列十一】Node.js开发框架Express4.x

    为什么80%的码农都做不了架构师?>>>    #0 系列目录# 深入浅出Node.js系列 [深入浅出Node.js系列一]什么是Node.js [深入浅出Node.js系列二]N ...

  3. 微信小程序首页index.js获取不到app.js中动态设置的globalData的原因以及解决方法

    微信小程序首页index.js获取不到app.js中动态设置的globalData的原因以及解决方法 参考文章: (1)微信小程序首页index.js获取不到app.js中动态设置的globalDat ...

  4. React.js 小书 Lesson5 - React.js 基本环境安装

    React.js 小书 Lesson5 - React.js 基本环境安装 本文作者:胡子大哈 本文原文:http://huziketang.com/books/react/lesson5 转载请注明 ...

  5. node.js入门系列(一)--Node.js简介

    什么是NodeJS JS是脚本语言,脚本语言都需要一个解析器才能运行.对于写在HTML页面里的JS,浏览器充当了解析器的角色.而对于需要独立运行的JS,NodeJS就是一个解析器. 每一种解析器都是一 ...

  6. js向head中添加js代码

    js向head中添加js代码 1.$("<script>").attr("type","text/javascript") .h ...

  7. php与js的关系,Php与Js的交互

    设计软件有两种方法:一是简单到极致而明显没有缺陷:另一种是复杂到极致以至于没有明显的缺陷,前者要难得多. -----C.A.R Hoare 本篇主要知识点: JS是什么 Js基础 Js语句 Js与浏览 ...

  8. node.js mysql 不退出_node.js,node-mysql_使用了node-mysql的代码无法自动停止,node.js,node-mysql - phpStudy...

    使用了node-mysql的代码无法自动停止 // db.js var mysql = require('mysql'); module.exports = function () { var poo ...

  9. js动态生产html元素,js 动态创建 html元素

    js 动态创建 html元素 js学习之动态创建html元素 body{margin:0;padding:0;} .sky{background:#000;width:1000;height:500p ...

  10. html中js添加或删除activex,JS:操作样式表2 :用JS实现添加和删除一个类名的功能(addClass()和removeClass())...

    var box = document.getElementById("box"); box.id = "pox"; 将id = "box", ...

最新文章

  1. python内置数据结构_Python内置数据结构
  2. 周休2.5天是一种奢望?互联网人自愿加班成常态?
  3. BZOJ3476 : [Usaco2014 Mar]The Lazy Cow
  4. SAP Loyalty management模块演示场景的测试数据
  5. javaheapspace解决方案_高手总结的9种 OOM 常见原因及解决方案
  6. Django models模型
  7. 代码分析-DataGrid实现自增列、单选、多选
  8. 30个提高Web程序执行效率的好经验
  9. 带你深入了解何为TeamViewer视频通话
  10. 清华大学操作系统OS学习(三)——启动、中断、异常和系统调用
  11. zr-djypvp计算机电缆,ZR-DJYPVP计算机电缆ZR-DJYPVP-2X2X1.0
  12. 浙江大学计算机学院科研团队,科研团队
  13. 原函数与反函数的关系
  14. 64位win7下Android SDK Manager闪退的解决方法
  15. 当我们在谈论HTTP队头阻塞时,我们在谈论什么?
  16. 20/06/27 charles安装报【User installations are disabled via policy on the machine】解决方法
  17. 一个免费的在线录屏网站
  18. ros串口通讯(读取串口数据)
  19. 东田纳西州立大学计算机排名,东田纳西州立大学如何
  20. 利用腾讯云函数服务进行每日wps签到打卡(部分失效)

热门文章

  1. 嵌入式Qt-做一个秒表
  2. sublime主题配色
  3. html超链接子页面,页面html超链接怎么做
  4. printf(“%d \n“,printf(“%d “,printf(“%d “,i)));输出结果?
  5. 绘制qq群的基础用例图_首次绘制出“氟化氢”地图:间接实现追踪宇宙中最常见的分子氢!...
  6. java取0到999整数_Java中输入一个0到999的整数 怎么弄? 谢谢了、
  7. 阿里云国际香港服务器,入手到底行不行?
  8. 寻找丢失的LZY(dfs)
  9. 【论文笔记】Switching Convolutional Neural Network for Crowd Counting
  10. Knowledge Tracing: A Survey阅读笔记