【pixijs】关于pixijs画圆

pixijs中画布原点在左上角,向右是x的正方向,向下是y的正方向(这点和数学坐标系相反)。

用到arc函数时突然短路,忘记0度是从9点方向还是3点方向了,各种坐标系搞晕了,写个文章记录下。

演练场:https://pixijs.com/8.x/playground

demo如下:

javascript 复制代码
import { Application, Assets, Container, Sprite, Graphics } from 'pixi.js';

(async () => {
  // Create a new application
  const app = new Application();

  // Initialize the application
  await app.init({ background: '#1099bb', resizeTo: window });

  // Append the application canvas to the document body
  document.body.appendChild(app.canvas);

  // Create and add a container to the stage
  const container = new Container();

  app.stage.addChild(container);

  const graphics = new Graphics();
  graphics
    .arc(0, 0, 50, 0, Math.PI / 5)
    .stroke({ width: 2, color: 'pink' });

  // Draw a full circle using an arc
  graphics
    .arc(100, 0, 30, 0, Math.PI * 2)
    .stroke({ color: 'red' });

  // Draw a counterclockwise arc
  graphics
    .arc(200, 0, 40, 0, Math.PI / 5, true)
    .stroke({ width: 2, color: 'green' });
  container.addChild(graphics);
  // Move the container to the center
  container.x = app.screen.width / 2;
  container.y = app.screen.height / 2;

  // Center the bunny sprites in local container coordinates
  container.pivot.x = container.width / 2;
  container.pivot.y = container.height / 2;


})();
相关推荐
陆康永1 天前
JavaScript 数组填充:Array.from 与 Array.fill 用法详解及核心区别
js·array
熊猫钓鱼>_>3 天前
ArkTS 方舟编程语言 · 原创快速入门教程
运维·架构·ts·harmonyos·arkts·鸿蒙·js
sugar__salt5 天前
Document 切割:RAG 知识库数据预处理实战
javascript·langchain·embedding·js·rag·cheerio
rockey6276 天前
基于AScript的JavaScript脚本语言发布啦
javascript·c#·.net·js·script
数聚天成DeepSData7 天前
企业知识库 RAG 数据准备与文档清洗:Dify、RAGFlow、扣子选型指南
开发语言·人工智能·机器学习·自然语言处理·sentinel·cocos2d
天若有情6739 天前
前端性能优化:从“按下预加载”到“AI级智能预判系统”
前端·性能优化·js·active·hover·首屏加载
H Journey10 天前
web开发学习:html、css、js
前端·css·html·js
Java小学生丶14 天前
分享一个 JS 鼠标跟随贪吃蛇背景库
js·美化
保持当下1 个月前
分享一些程序员很棘手但是却又简单的工具
程序员·免费·js·工具
LONGZETECH1 个月前
无人机仿真教学软件选型实战:5 个硬核技术维度,避开实训建设踩坑
3d·无人机·交互·cocos2d