このページでは「P5.js 日本語リファレンス」 の copy関数を説明します。
copy()
説明文
キャンバスの領域の一部をキャンバスの別の領域にコピーします。または、srcImage パラメータで指定したコピー元画像からキャンバスにコピーします。コピー元領域とコピー先領域が同じサイズでない場合、指定されたコピー先領域に合わせてコピー元ピクセルのサイズが自動的に変更されます。
構文
copy(srcImage, sx, sy, sw, sh, dx, dy, dw, dh)
copy(sx, sy, sw, sh, dx, dy, dw, dh)
パラメタ
srcImage
p5.Image|p5.Element:コピー元画像sx
Number:コピー元画像の左上隅のX座標sy
Number:コピー元画像の左上隅のY座標sw
Number:コピー元画像の幅sh
Number:コピー元画像の高さdx
Number:コピー先画像の左上隅のX座標dy
Number:コピー先画像の左上隅のY座標dw
Number:コピー先画像の幅dh
Number:コピー先画像の高さ
例1
let img;
function preload() {
img = loadImage('assets/mountain.jpg');
}
function setup() {
createCanvas(300, 200);
background(img);
// Imgパラメータで指定したコピー元画像からキャンバスにコピーします。
copy(img, 10, 30, 60, 40, 40, 100, 120, 80);
stroke(255);
noFill() ;
//長方形はコピーされる領域を示します
rect(10, 30, 60, 40);
}
実行結果
例2
let img;
function preload() {
img = loadImage('assets/mountain.jpg');
}
function setup() {
createCanvas(300, 200);
background(img);
// キャンバスの領域の一部をキャンバスの別の領域にコピーします。
copy(10, 30, 60, 40, 40, 100, 120, 80);
stroke(255);
noFill() ;
//長方形はコピーされる領域を示します
rect(10, 30, 60, 40);
}
実行結果
著作権
p5.js was created by Lauren McCarthy and is developed by a community of collaborators, with support from the Processing Foundation and NYU ITP. Identity and graphic design by Jerel Johnson.
ライセンス
Creative Commons(CC BY-NC-SA 4.0) に従います。