p5js上的翻转图像y轴

发布于 2025-02-01 15:56:30 字数 168 浏览 3 评论 0原文

我需要在P5J中的Y轴上翻转图像,

我知道对于X轴上的翻转,以下代码有效

push();
scale(-1, 1)
image(pg,-width/2,0, width/2, height);
pop();

,但我找不到在Y轴上进行操作的方法。

I need to flip a image over the Y axis in P5js

I'm aware that for the flip over the X axis the following code works

push();
scale(-1, 1)
image(pg,-width/2,0, width/2, height);
pop();

But I can't found the way to do it over the Y axis.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

思念满溢 2025-02-08 15:56:30

将Y轴缩放为-1:

scale(1, -1);

并用-height的y坐标绘制图像:

image(..., ..., -height, ..., height);

let img;
function preload() {
  img = loadImage('https://raw.githubusercontent.com/Rabbid76/graphics-snippets/master/resource/texture/supermario.jpg');
}

function setup() {
  createCanvas(256, 256);
}

function draw() {
  push();
  scale(1, -1);
  image(img, 0, -height, width, height);
  pop();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.min.js"></script>

Scale the y axis by -1:

scale(1, -1);

And draw the image with a y-coordinate of -height:

image(..., ..., -height, ..., height);

let img;
function preload() {
  img = loadImage('https://raw.githubusercontent.com/Rabbid76/graphics-snippets/master/resource/texture/supermario.jpg');
}

function setup() {
  createCanvas(256, 256);
}

function draw() {
  push();
  scale(1, -1);
  image(img, 0, -height, width, height);
  pop();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.min.js"></script>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文