我需要在 P5js 的 Y 軸上翻轉影像
我知道對于翻轉 X 軸,以下代碼有效
push();
scale(-1, 1)
image(pg,-width/2,0, width/2, height);
pop();
但我找不到在 Y 軸上執行此操作的方法。
uj5u.com熱心網友回復:
將 y 軸縮放 -1:
scale(1, -1);
并使用 y 坐標繪制影像-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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/481479.html
標籤:javascript 加工 p5.js
上一篇:通過id更改頁腳大小
